summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornjames <njames@us.ibm.com>2015-02-11 12:17:18 -0600
committernjames <njames@us.ibm.com>2015-02-11 12:17:18 -0600
commit489def7d486bd65e8e781f0839ec122486994097 (patch)
tree0b728aade18c5c966bd4f202b9544cba905e5d6b /src
parent132a3843bafba9f6fafff420e9078b20af8263a6 (diff)
downloadserverwiz-489def7d486bd65e8e781f0839ec122486994097.tar.gz
serverwiz-489def7d486bd65e8e781f0839ec122486994097.zip
first release
Diffstat (limited to 'src')
-rw-r--r--src/com/ibm/ServerWizard2/ArrayDialogCellEditor.java36
-rw-r--r--src/com/ibm/ServerWizard2/ArrayEditingSupport.java45
-rw-r--r--src/com/ibm/ServerWizard2/ArrayEditorDialog.java99
-rw-r--r--src/com/ibm/ServerWizard2/ArrayLabelProvider.java20
-rw-r--r--src/com/ibm/ServerWizard2/Attribute.java163
-rw-r--r--src/com/ibm/ServerWizard2/AttributeEditingSupport.java64
-rw-r--r--src/com/ibm/ServerWizard2/AttributeValue.java49
-rw-r--r--src/com/ibm/ServerWizard2/AttributeValueComplex.java93
-rw-r--r--src/com/ibm/ServerWizard2/AttributeValueNative.java83
-rw-r--r--src/com/ibm/ServerWizard2/AttributeValueSimple.java99
-rw-r--r--src/com/ibm/ServerWizard2/Connection.java70
-rw-r--r--src/com/ibm/ServerWizard2/ConnectionEndpoint.java29
-rw-r--r--src/com/ibm/ServerWizard2/Enumerator.java38
-rw-r--r--src/com/ibm/ServerWizard2/Field.java31
-rw-r--r--src/com/ibm/ServerWizard2/LibraryFile.java41
-rw-r--r--src/com/ibm/ServerWizard2/LibraryManager.java299
-rw-r--r--src/com/ibm/ServerWizard2/LogViewerDialog.java63
-rw-r--r--src/com/ibm/ServerWizard2/MainDialog.java1143
-rw-r--r--src/com/ibm/ServerWizard2/MyLogFormatter.java43
-rw-r--r--src/com/ibm/ServerWizard2/SdrRecord.java56
-rw-r--r--src/com/ibm/ServerWizard2/ServerWizard2.java49
-rw-r--r--src/com/ibm/ServerWizard2/SystemModel.java537
-rw-r--r--src/com/ibm/ServerWizard2/Target.java467
-rw-r--r--src/com/ibm/ServerWizard2/TargetWizardController.java331
-rw-r--r--src/com/ibm/ServerWizard2/XmlHandler.java39
-rw-r--r--src/manifest.txt3
-rw-r--r--src/org/eclipse/wb/swt/SWTResourceManager.java447
27 files changed, 4437 insertions, 0 deletions
diff --git a/src/com/ibm/ServerWizard2/ArrayDialogCellEditor.java b/src/com/ibm/ServerWizard2/ArrayDialogCellEditor.java
new file mode 100644
index 0000000..12393e9
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/ArrayDialogCellEditor.java
@@ -0,0 +1,36 @@
+package com.ibm.ServerWizard2;
+
+import org.eclipse.jface.viewers.DialogCellEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+public class ArrayDialogCellEditor extends DialogCellEditor {
+ Field field;
+
+ public ArrayDialogCellEditor(Composite parent,Field field) {
+ super(parent);
+ this.field=new Field(field);
+ }
+
+ @Override
+ protected Object doGetValue() {
+ return field.value;
+ }
+
+ @Override
+ protected void doSetValue(Object value) {
+ field.value=(String)value;
+ }
+
+ @Override
+ protected Object openDialogBox(Control arg0) {
+ ArrayEditorDialog dlg = new ArrayEditorDialog(arg0.getShell(),SWT.NONE);
+ dlg.setData(field.value, field.array, field.type);
+ if (dlg.open()==0) {
+ this.markDirty();
+ return dlg.getData();
+ }
+ return null;
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/ArrayEditingSupport.java b/src/com/ibm/ServerWizard2/ArrayEditingSupport.java
new file mode 100644
index 0000000..afff1b3
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/ArrayEditingSupport.java
@@ -0,0 +1,45 @@
+package com.ibm.ServerWizard2;
+
+import java.util.Vector;
+
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TextCellEditor;
+
+public class ArrayEditingSupport extends EditingSupport {
+
+ private final CellEditor editor;
+ private int column;
+
+ public ArrayEditingSupport(TableViewer viewer,int column) {
+ super(viewer);
+ this.editor = new TextCellEditor(viewer.getTable());
+ this.column=column;
+ }
+
+ @Override
+ protected boolean canEdit(Object arg0) {
+ return true;
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object arg0) {
+ return editor;
+ }
+
+ @Override
+ protected Object getValue(Object arg0) {
+ @SuppressWarnings("unchecked")
+ Vector<String> v = (Vector<String>)arg0;
+ return v.get(column);
+ }
+
+ @Override
+ protected void setValue(Object arg0, Object arg1) {
+ @SuppressWarnings("unchecked")
+ Vector<String> v = (Vector<String>)arg0;
+ v.set(column, (String)arg1);
+ this.getViewer().update(arg0, null);
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/ArrayEditorDialog.java b/src/com/ibm/ServerWizard2/ArrayEditorDialog.java
new file mode 100644
index 0000000..69ddf44
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/ArrayEditorDialog.java
@@ -0,0 +1,99 @@
+package com.ibm.ServerWizard2;
+
+import java.util.Vector;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+
+public class ArrayEditorDialog extends Dialog {
+
+ private Table table;
+ int numColumns=0;
+ private String rawData="";
+ private TableViewer viewer;
+ private Vector<Vector<String>> data;
+
+ /**
+ * Create the dialog.
+ * @param parent
+ * @param style
+ */
+ public ArrayEditorDialog(Shell parent, int style) {
+ super(parent);
+ this.setShellStyle(SWT.APPLICATION_MODAL);
+
+ }
+
+ /**
+ * Create contents of the dialog.
+ */
+ public String getData() {
+ rawData="";
+ for (Vector<String> v : data) {
+ for (int i=1;i<v.size();i++) {
+ rawData=rawData+v.get(i)+",";
+ }
+ }
+ rawData=rawData.substring(0, rawData.length()-1);
+ return rawData;
+ }
+ public void setData(String rawData,String array,String type) {
+
+ String d[] = array.split(",");
+ if (d.length==1) {
+ numColumns=1;
+ } else {
+ numColumns=Integer.parseInt(d[1]);
+ }
+ this.rawData = rawData;
+ String a[] = rawData.split(",");
+
+ data = new Vector<Vector<String>>();
+ for(int row=0;row < a.length/numColumns;row++) {
+ Vector<String> v_col = new Vector<String>();
+ data.add(v_col);
+ v_col.add(String.valueOf(row));
+ for (int col=0;col<numColumns;col++) {
+ v_col.add(a[col+row*numColumns]);
+ }
+ }
+ }
+ protected Control createDialogArea(Composite parent) {
+ Composite container = (Composite) super.createDialogArea(parent);
+
+ viewer = new TableViewer(container, SWT.MULTI | SWT.H_SCROLL
+ | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+ final TableViewerColumn columnRow = new TableViewerColumn(viewer, SWT.NONE);
+ columnRow.getColumn().setWidth(40);
+ columnRow.setLabelProvider(new ArrayLabelProvider(0));
+
+ for (int i=1;i<numColumns+1;i++) {
+ final TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+ column.getColumn().setWidth(100);
+ column.getColumn().setText(String.valueOf(i-1));
+ column.setLabelProvider(new ArrayLabelProvider(i));
+ column.setEditingSupport(new ArrayEditingSupport(viewer,i));
+ }
+ // make lines and header visible
+ table = viewer.getTable();
+ table.setLinesVisible(true);
+ table.setHeaderVisible(true);
+ viewer.setContentProvider(ArrayContentProvider.getInstance());
+ viewer.setInput(data);
+
+ GridData gd_table = new GridData(SWT.CENTER, SWT.TOP, false, true, 1, 1);
+ gd_table.heightHint = 254;
+ gd_table.widthHint = 260;
+ table.setLayoutData(gd_table);
+
+ return container;
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/ArrayLabelProvider.java b/src/com/ibm/ServerWizard2/ArrayLabelProvider.java
new file mode 100644
index 0000000..1f13fb4
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/ArrayLabelProvider.java
@@ -0,0 +1,20 @@
+package com.ibm.ServerWizard2;
+
+import java.util.Vector;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+
+public class ArrayLabelProvider extends ColumnLabelProvider {
+ public int column = 0;
+ public ArrayLabelProvider(int column) {
+ super();
+ this.column=column;
+ }
+ @Override
+ public String getText(Object element) {
+ @SuppressWarnings("unchecked")
+ Vector<String> v = (Vector<String>)element;
+ return v.get(this.column);
+ }
+
+}
diff --git a/src/com/ibm/ServerWizard2/Attribute.java b/src/com/ibm/ServerWizard2/Attribute.java
new file mode 100644
index 0000000..3dca54c
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/Attribute.java
@@ -0,0 +1,163 @@
+package com.ibm.ServerWizard2;
+
+import java.io.Writer;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class Attribute implements java.io.Serializable {
+ private static final long serialVersionUID = 1L;
+ public String name = "";
+ public AttributeValue value;
+
+ public String inherited = "";
+ public String desc = "";
+ public Boolean readable = false;
+ public Boolean writeable = false;
+ public Boolean readonly = false;
+ public Persistency persistency = Persistency.NO_PERSISTENCY;
+ public Boolean hide = false;
+ private Boolean bitmask = false;
+ private Boolean global = false;
+
+ public enum Persistency {
+ NO_PERSISTENCY, VOLATILE_ZEROED, NON_VOLATILE, VOLATILE
+ };
+
+ public Attribute() {
+ }
+
+ public Attribute(Attribute a) {
+ this.name = a.name;
+ this.desc = a.desc;
+ this.persistency = a.persistency;
+ this.readable = a.readable;
+ this.writeable = a.writeable;
+ this.inherited = a.inherited;
+ this.hide = a.hide;
+ this.bitmask = a.bitmask;
+ this.global = a.global;
+
+ if (a.value instanceof AttributeValueComplex) {
+ this.value = new AttributeValueComplex((AttributeValueComplex)a.value);
+ }
+ else if(a.value instanceof AttributeValueSimple) {
+ this.value = new AttributeValueSimple((AttributeValueSimple)a.value);
+ }
+ else if(a.value instanceof AttributeValueNative) {
+ this.value = new AttributeValueNative((AttributeValueNative)a.value);
+ }
+ else {
+
+ }
+
+ }
+
+ public AttributeValue getValue() {
+ return value;
+ }
+ public boolean isReadable() {
+ return readable;
+ }
+ public boolean isWriteable() {
+ return writeable;
+ }
+ public boolean isHidden() {
+ return hide;
+ }
+
+ public Boolean isBitmask() {
+ return bitmask;
+ }
+ public boolean isGlobal() {
+ return this.global;
+ }
+ public String toString() {
+ String rtn="Attribute: "+name+" = ";
+ rtn="Attribute: "+name+" = "+value.toString()+" inherited="+this.inherited;
+ return rtn;
+ }
+
+ public void setPersistence(String p) {
+ if (p.equals("non-volatile")) {
+ persistency = Persistency.NON_VOLATILE;
+ } else if (p.equals("volatile-zeroed")) {
+ persistency = Persistency.VOLATILE_ZEROED;
+ } else if (p.equals("volatile")) {
+ persistency = Persistency.VOLATILE;
+ } else {
+ throw new NullPointerException("Invalid Peristence: "+p);
+ }
+ }
+ public String getPersistence() {
+ if (persistency == Persistency.NON_VOLATILE) {
+ return "non-volatile";
+ } else if(persistency == Persistency.VOLATILE_ZEROED) {
+ return "volatile-zeroed";
+ } else if(persistency == Persistency.NO_PERSISTENCY) {
+ return "";
+ } else if(persistency == Persistency.VOLATILE) {
+ return "volatile";
+ } else { return ""; }
+
+ }
+ public void readModelXML(Element attribute) {
+ //name = attribute.getElementsByTagName("id").item(0).getChildNodes().item(0).getNodeValue();
+ name = SystemModel.getElement(attribute, "id");
+ desc = SystemModel.getElement(attribute,"description");
+
+ String p = SystemModel.getElement(attribute,"persistency");
+ if (!p.isEmpty()) { setPersistence(p); }
+
+ if (SystemModel.isElementDefined(attribute,"bitmask")) {
+ bitmask=true;
+ }
+ if (SystemModel.isElementDefined(attribute,"global")) {
+ global=true;
+ }
+
+ if (SystemModel.isElementDefined(attribute,"readable")) {
+ readable=true;
+ }
+ if (SystemModel.isElementDefined(attribute,"writeable")) {
+ writeable=true;
+ }
+ if (SystemModel.isElementDefined(attribute,"serverwizHide") ||
+ name.equals("MODEL") || name.equals("TYPE") || name.equals("CLASS")) {
+ hide=true;
+ }
+ if (SystemModel.isElementDefined(attribute,"serverwizReadonly")) {
+ readonly=true;
+ }
+ Node simpleType = attribute.getElementsByTagName("simpleType").item(0);
+ if (simpleType!=null) {
+ value = new AttributeValueSimple(this);
+ value.readonly = readonly;
+ value.readXML((Element)simpleType);
+ }
+ Node complexType = attribute.getElementsByTagName("complexType").item(0);
+ if (complexType!=null) {
+ value = new AttributeValueComplex(this);
+ value.readonly = readonly;
+ value.readXML((Element)complexType);
+ }
+ Node nativeType = attribute.getElementsByTagName("nativeType").item(0);
+ if (nativeType!=null) {
+ value = new AttributeValueNative(this);
+ value.readonly = readonly;
+ value.readXML((Element)nativeType);
+ }
+ }
+ public void writeBusInstanceXML(Writer out) throws Exception {
+ out.write("\t\t<bus_attribute>\n");
+ out.write("\t\t\t<id>"+name+"</id>\n");
+ value.writeInstanceXML(out);
+ out.write("\t\t</bus_attribute>\n");
+ }
+ public void writeInstanceXML(Writer out) throws Exception {
+ out.write("\t<attribute>\n");
+ out.write("\t\t<id>"+name+"</id>\n");
+ value.writeInstanceXML(out);
+ out.write("\t</attribute>\n");
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/AttributeEditingSupport.java b/src/com/ibm/ServerWizard2/AttributeEditingSupport.java
new file mode 100644
index 0000000..4a0d167
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/AttributeEditingSupport.java
@@ -0,0 +1,64 @@
+package com.ibm.ServerWizard2;
+
+import java.util.Vector;
+
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ComboBoxViewerCellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.swt.SWT;
+
+public class AttributeEditingSupport extends EditingSupport {
+ private CellEditor editor;
+ private TableViewer viewer;
+
+ public AttributeEditingSupport(TableViewer viewer) {
+ super(viewer);
+ this.viewer=viewer;
+ }
+
+ @Override
+ protected boolean canEdit(Object obj) {
+ Field f = (Field)obj;
+ return !f.readonly;
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object obj) {
+ Field f = (Field) obj;
+ if (f.type.equals("enumeration")) {
+ ComboBoxViewerCellEditor e = new ComboBoxViewerCellEditor(viewer.getTable(),SWT.READ_ONLY);
+ e.setContentProvider(new ArrayContentProvider());
+ e.setInput(f.enumerator.enumList);
+ this.editor=e;
+ } else if (!f.array.isEmpty()) {
+ this.editor = new ArrayDialogCellEditor(viewer.getTable(),f);
+ } else if (f.type.equals("boolean")) {
+ Vector<String> tf = new Vector<String>();
+ ComboBoxViewerCellEditor e = new ComboBoxViewerCellEditor(viewer.getTable(),SWT.READ_ONLY);
+ e.setContentProvider(new ArrayContentProvider());
+ tf.add("true");
+ tf.add("false");
+ e.setInput(tf);
+ this.editor=e;
+ } else {
+ this.editor = new TextCellEditor(viewer.getTable());
+ }
+ return editor;
+ }
+
+ @Override
+ protected Object getValue(Object obj) {
+ Field f = (Field) obj;
+ return f.value;
+ }
+
+ @Override
+ protected void setValue(Object obj, Object value) {
+ Field f = (Field) obj;
+ f.value = (String) value;
+ this.getViewer().update(obj, null);
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/AttributeValue.java b/src/com/ibm/ServerWizard2/AttributeValue.java
new file mode 100644
index 0000000..18eb28d
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/AttributeValue.java
@@ -0,0 +1,49 @@
+package com.ibm.ServerWizard2;
+
+import java.io.Writer;
+import java.util.Vector;
+
+import org.w3c.dom.Element;
+
+public abstract class AttributeValue {
+
+ protected String type="";
+ protected Vector<Field> fields;
+ protected Attribute attribute = null;
+ protected boolean readonly = true;
+
+ public abstract void readXML(Element value);
+ public abstract void readInstanceXML(Element value);
+ public abstract void writeInstanceXML(Writer out) throws Exception;
+ public abstract String getValue();
+ public abstract void setValue(AttributeValue value);
+ public abstract void setValue(String value);
+ public abstract String toString();
+ public abstract Boolean isEmpty();
+ public void setEnumerator(Enumerator enumerator) {
+ for (Field f : fields) {
+ f.enumerator=enumerator;
+ }
+ }
+
+ public AttributeValue(Attribute attribute) {
+ fields = new Vector<Field>();
+ this.attribute=attribute;
+ }
+ public AttributeValue(AttributeValue a) {
+ fields = new Vector<Field>();
+ for (Field f : a.fields) {
+ Field f2 = new Field(f);
+ fields.add(f2);
+ }
+ type = a.type;
+ attribute = a.attribute;
+ readonly = a.readonly;
+ }
+ public String getType() {
+ return type;
+ }
+ public Vector<Field> getFields() {
+ return fields;
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/AttributeValueComplex.java b/src/com/ibm/ServerWizard2/AttributeValueComplex.java
new file mode 100644
index 0000000..c4db2c3
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/AttributeValueComplex.java
@@ -0,0 +1,93 @@
+package com.ibm.ServerWizard2;
+
+import java.io.Writer;
+import java.util.Vector;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class AttributeValueComplex extends AttributeValue {
+
+ public AttributeValueComplex(Attribute a) {
+ super(a);
+ }
+ public AttributeValueComplex(AttributeValueComplex a) {
+ super(a);
+ }
+
+ public void readXML(Element value) {
+ fields = new Vector<Field>();
+ type="complex";
+ NodeList fieldList = value.getElementsByTagName("field");
+ for (int i = 0; i < fieldList.getLength(); ++i) {
+ Field f = new Field();
+ f.attributeName = this.attribute.name;
+ f.name = SystemModel.getElement((Element) fieldList.item(i), "name");
+ f.desc = SystemModel
+ .getElement((Element) fieldList.item(i), "description");
+ f.type = SystemModel.getElement((Element) fieldList.item(i), "type");
+ f.bits = SystemModel.getElement((Element) fieldList.item(i), "bits");
+ f.defaultv = SystemModel.getElement((Element) fieldList.item(i), "default");
+ f.readonly = this.readonly;
+ fields.add(f);
+ }
+ }
+ public void readInstanceXML(Element value) {
+ NodeList fieldList = value.getElementsByTagName("field");
+ for (int i = 0; i < fieldList.getLength(); ++i) {
+ String fid=SystemModel.getElement((Element) fieldList.item(i), "id");
+ String v=SystemModel.getElement((Element) fieldList.item(i), "value");
+ for(int x=0;x<fields.size();x++) {
+ Field f = fields.get(x);
+ if (f.name.equals(fid)) {
+ f.value=v;
+ }
+ }
+ }
+ }
+ @Override
+ public void writeInstanceXML(Writer out) throws Exception {
+ String t="\t\t";
+ String r=t+"<default>\n";
+ for (int i=0;i<fields.size();i++) {
+ Field f = new Field(fields.get(i));
+ r=r+t+"\t\t<field><id>"+f.name+"</id><value>"+f.value+"</value></field>\n";
+ }
+ r=r+t+"</default>\n";
+ out.write(r);
+ }
+
+ @Override
+ public String getValue() {
+ // TODO Auto-generated method stub
+ return "complex";
+ }
+
+ @Override
+ public String toString() {
+ String r="COMPLEX:\n";
+ for (int i=0;i<this.fields.size();i++) {
+ Field f = new Field(this.fields.get(i));
+ r=f.name+"="+f.value;
+ }
+ return r;
+ }
+ @Override
+ public void setValue(String value) {
+ // TODO Auto-generated method stub
+
+ }
+ @Override
+ public Boolean isEmpty() {
+ return false;
+ }
+ @Override
+ public void setValue(AttributeValue value) {
+ fields.clear();
+ AttributeValueComplex c = (AttributeValueComplex)value;
+ for (int i=0;i<c.fields.size();i++) {
+ Field f = new Field(c.fields.get(i));
+ fields.add(f);
+ }
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/AttributeValueNative.java b/src/com/ibm/ServerWizard2/AttributeValueNative.java
new file mode 100644
index 0000000..bb9a4d4
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/AttributeValueNative.java
@@ -0,0 +1,83 @@
+package com.ibm.ServerWizard2;
+
+import java.io.Writer;
+
+import org.w3c.dom.Element;
+
+public class AttributeValueNative extends AttributeValue {
+ private Field field;
+
+ public AttributeValueNative(Attribute a) {
+ super(a);
+ field = new Field();
+ field.attributeName=a.name;
+ field.desc=a.desc;
+ fields.add(field);
+ }
+ public AttributeValueNative(AttributeValueNative a) {
+ super(a);
+ field=fields.get(0);
+ }
+ public void readXML(Element e) {
+ field.value = SystemModel.getElement(e, "default");
+ field.name = SystemModel.getElement(e, "name");
+ field.readonly = this.readonly;
+ }
+
+ public void readInstanceXML(Element e) {
+ field.value = SystemModel.getElement(e, "default");
+ }
+
+ @Override
+ public void writeInstanceXML(Writer out) throws Exception {
+ out.write("\t\t<default>" + field.value + "</default>\n");
+ }
+
+ @Override
+ public String getValue() {
+ return field.value;
+ }
+
+ @Override
+ public String toString() {
+ return "default(" + field.name + ")";
+ }
+
+ @Override
+ public void setValue(String value) {
+ field.value = value;
+ }
+
+ @Override
+ public Boolean isEmpty() {
+ return field.value.isEmpty();
+ }
+
+ @Override
+ public void setValue(AttributeValue value) {
+ AttributeValueNative n = (AttributeValueNative) value;
+ field.value = n.field.value;
+ field.name = n.field.name;
+ }
+/*
+ @Override
+ public Control getEditor(Table table, AttributeTableItem item) {
+ Text text = new Text(table, SWT.NONE);
+ text.setData(item);
+ text.setText(value);
+ text.setSelection(text.getText().length());
+ text.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ Text text = (Text) e.getSource();
+ AttributeTableItem a = (AttributeTableItem) text.getData();
+ AttributeValueSimple v = (AttributeValueSimple) a.getAttribute();
+ v.value = text.getText();
+ a.getItem().setText(2, v.value);
+ }
+ });
+ return text;
+ }
+ */
+}
diff --git a/src/com/ibm/ServerWizard2/AttributeValueSimple.java b/src/com/ibm/ServerWizard2/AttributeValueSimple.java
new file mode 100644
index 0000000..d661ac4
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/AttributeValueSimple.java
@@ -0,0 +1,99 @@
+package com.ibm.ServerWizard2;
+
+import java.io.Writer;
+
+import org.w3c.dom.Element;
+
+public class AttributeValueSimple extends AttributeValue {
+
+ private String array = "";
+ private Field field;
+
+ public AttributeValueSimple(Attribute a) {
+ super(a);
+ field = new Field();
+ field.attributeName = a.name;
+ field.desc=a.desc;
+ fields.add(field);
+ }
+ public AttributeValueSimple(AttributeValueSimple a) {
+ super(a);
+ field=fields.get(0);
+ }
+
+ @Override
+ public void readXML(Element e) {
+ // value = e.getElementsByTagName("default").;
+ Element a = (Element) e.getElementsByTagName("uint8_t").item(0);
+ if (a != null) {
+ type = "uint8_t";
+ field.value = SystemModel.getElement(a, "default");
+ field.type=type;
+ }
+ a = (Element) e.getElementsByTagName("uint16_t").item(0);
+ if (a != null) {
+ type = "uint16_t";
+ field.value = SystemModel.getElement(a, "default");
+ field.type=type;
+ }
+ a = (Element) e.getElementsByTagName("uint32_t").item(0);
+ if (a != null) {
+ type = "uint32_t";
+ field.value = SystemModel.getElement(a, "default");
+ field.type=type;
+ }
+ a = (Element) e.getElementsByTagName("string").item(0);
+ if (a != null) {
+ type = "string";
+ field.value = SystemModel.getElement(a, "default");
+ field.type=type;
+ }
+ a = (Element) e.getElementsByTagName("enumeration").item(0);
+ if (a != null) {
+ type = "enumeration";
+ field.value = SystemModel.getElement(a, "default");
+ field.name = SystemModel.getElement(a, "id");
+ field.type=type;
+ }
+ array = SystemModel.getElement(e, "array");
+ field.array = array;
+ field.readonly = this.readonly;
+ }
+
+ public void readInstanceXML(Element e) {
+ field.value = SystemModel.getElement(e, "default");
+ }
+
+ @Override
+ public void writeInstanceXML(Writer out) throws Exception {
+ out.write("\t\t<default>" + field.value + "</default>\n");
+ }
+
+ @Override
+ public String getValue() {
+ return field.value;
+ }
+
+ @Override
+ public String toString() {
+ // TODO Auto-generated method stub
+ return field.value + " (" + type + ")";
+ }
+
+ @Override
+ public void setValue(String value) {
+ field.value = value;
+ }
+
+ @Override
+ public Boolean isEmpty() {
+ return field.value.isEmpty();
+ }
+
+ @Override
+ public void setValue(AttributeValue value) {
+ AttributeValueSimple n = (AttributeValueSimple) value;
+ field.value = n.field.value;
+ field.name = n.field.name;
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/Connection.java b/src/com/ibm/ServerWizard2/Connection.java
new file mode 100644
index 0000000..5c9cfe8
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/Connection.java
@@ -0,0 +1,70 @@
+package com.ibm.ServerWizard2;
+
+import java.io.Writer;
+import java.util.Map;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+
+public class Connection {
+ public int id = 0;
+ public String busType = "";
+ public ConnectionEndpoint source;
+ public ConnectionEndpoint dest;
+ public Boolean cabled=false;
+ public Target busTarget;
+ public String getName() {
+ String seperator = " => ";
+ if (cabled) {
+ seperator=" =c=> ";
+ }
+ return source.getName()+seperator+dest.getName();
+ }
+ public void writeInstanceXML(Writer out) throws Exception {
+ out.write("\t<bus>\n");
+ out.write("\t\t<bus_id>"+getName()+"</bus_id>\n");
+ out.write("\t\t<bus_type>"+busType+"</bus_type>\n");
+ String c="no";
+ if (cabled) { c="yes"; }
+ out.write("\t\t<cable>"+c+"</cable>\n");
+ out.write("\t\t<source_path>"+source.getPath()+"</source_path>\n");
+ out.write("\t\t<source_target>"+source.getTargetName()+"</source_target>\n");
+ out.write("\t\t<dest_path>"+dest.getPath()+"</dest_path>\n");
+ out.write("\t\t<dest_target>"+dest.getTargetName()+"</dest_target>\n");
+
+ //write attributes
+ for (Map.Entry<String, Attribute> entry : busTarget.getAttributes().entrySet()) {
+ Attribute attr = new Attribute(entry.getValue());
+ attr.writeBusInstanceXML(out);
+ }
+ out.write("\t</bus>\n");
+ }
+ public void readInstanceXML(Element t) throws Exception {
+ source = new ConnectionEndpoint();
+ dest = new ConnectionEndpoint();
+ busType = SystemModel.getElement(t, "bus_type");
+ String cable = SystemModel.getElement(t, "cable");
+ cabled=false;
+ if (cable.equals("yes")) { cabled=true; }
+ source.setPath(SystemModel.getElement(t, "source_path"));
+ source.setTargetName(SystemModel.getElement(t, "source_target"));
+ dest.setPath(SystemModel.getElement(t, "dest_path"));
+ dest.setTargetName(SystemModel.getElement(t, "dest_target"));
+
+ NodeList attrList = t.getElementsByTagName("bus_attribute");
+ for (int j = 0; j < attrList.getLength(); ++j) {
+ Element attr = (Element) attrList.item(j);
+ if (attr==null) {
+ throw new Exception("Problem with bus source="+source.getPath());
+ }
+ String id = SystemModel.getElement(attr, "id");
+ Attribute a = busTarget.getAttributes().get(id);
+ if (a==null) {
+ ServerWizard2.LOGGER.warning("Attribute: "+id+" is invalid for bus "+source.getPath());
+ } else {
+ a.value.readInstanceXML(attr);
+ }
+ }
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/ConnectionEndpoint.java b/src/com/ibm/ServerWizard2/ConnectionEndpoint.java
new file mode 100644
index 0000000..90b7e21
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/ConnectionEndpoint.java
@@ -0,0 +1,29 @@
+package com.ibm.ServerWizard2;
+
+public class ConnectionEndpoint {
+ //private Target target;
+ private String path="";
+ private String targetName="";
+
+ //public Target getTarget() {
+ // return target;
+ //}
+ public String getTargetName() {
+ return targetName;
+ }
+ public void setTargetName(String targetName) {
+ this.targetName = targetName;
+ }
+ //public void setTarget(Target target) {
+ // this.target = target;
+ //}
+ public String getPath() {
+ return path;
+ }
+ public void setPath(String path) {
+ this.path = path;
+ }
+ public String getName() {
+ return path+targetName;
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/Enumerator.java b/src/com/ibm/ServerWizard2/Enumerator.java
new file mode 100644
index 0000000..815459f
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/Enumerator.java
@@ -0,0 +1,38 @@
+package com.ibm.ServerWizard2;
+
+import java.util.HashMap;
+import java.util.Vector;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class Enumerator {
+ public String id="";
+ public String desc="";
+ public HashMap<String,String> enumValues = new HashMap<String,String>();
+ public Vector<String> enumList = new Vector<String>();
+
+
+ public void addEnum(String name,String value) {
+ enumValues.put(name, value);
+ enumList.add(name);
+ }
+ public void readXML(Element e) {
+ id = SystemModel.getElement(e, "id");
+ desc = SystemModel.getElement(e,"description");
+ NodeList enumList = e.getElementsByTagName("enumerator");
+ for (int i = 0; i < enumList.getLength(); ++i) {
+ Element en=(Element)enumList.item(i);
+ String name=SystemModel.getElement(en, "name");
+ String value=SystemModel.getElement(en, "value");
+ addEnum(name,value);
+ }
+ }
+ public Integer getEnumInt(String e) {
+ return Integer.decode(enumValues.get(e));
+ }
+ public String getEnumStr(String e) {
+ return enumValues.get(e);
+ }
+
+}
diff --git a/src/com/ibm/ServerWizard2/Field.java b/src/com/ibm/ServerWizard2/Field.java
new file mode 100644
index 0000000..3d8c56f
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/Field.java
@@ -0,0 +1,31 @@
+package com.ibm.ServerWizard2;
+
+
+public class Field {
+ public String attributeName="";
+ public String name="";
+ public String desc="";
+ public String type="";
+ public String bits="";
+ public String defaultv="";
+ public String value="";
+ public Enumerator enumerator = null;
+ public String array = "";
+ public boolean readonly = false;
+
+ public Field() {
+
+ }
+ public Field(Field f) {
+ attributeName = f.attributeName;
+ name=f.name;
+ desc=f.desc;
+ type=f.type;
+ bits=f.bits;
+ value=f.value;
+ defaultv=f.defaultv;
+ enumerator=f.enumerator;
+ array = f.array;
+ readonly = f.readonly;
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/LibraryFile.java b/src/com/ibm/ServerWizard2/LibraryFile.java
new file mode 100644
index 0000000..95f69b8
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/LibraryFile.java
@@ -0,0 +1,41 @@
+package com.ibm.ServerWizard2;
+
+import java.io.File;
+import java.net.URL;
+
+public class LibraryFile {
+
+ private URL remoteFile;
+ private File localFile;
+ private String filename;
+ private FileTypes type;
+
+ public enum FileTypes {
+ ATTRIBUTE_TYPE_XML, TARGET_TYPE_XML, TARGET_INSTANCES_XML, SCRIPT
+ }
+
+ public void init(String url, String workingDir, FileTypes type) throws Exception {
+ remoteFile = new URL(url);
+ File fi = new File(getRemotePath());
+ filename = fi.getName();
+ this.type = type;
+ String subdir = "xml";
+ if (type==FileTypes.SCRIPT) {
+ subdir="scripts";
+ }
+ localFile=new File(workingDir+subdir+System.getProperty("file.separator")+filename);
+ }
+
+ public String getRemotePath() {
+ return remoteFile.toString();
+ }
+ public String getLocalPath() {
+ return localFile.getPath();
+ }
+ public String getFilename() {
+ return localFile.getName();
+ }
+ public FileTypes getType() {
+ return type;
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/LibraryManager.java b/src/com/ibm/ServerWizard2/LibraryManager.java
new file mode 100644
index 0000000..071910a
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/LibraryManager.java
@@ -0,0 +1,299 @@
+package com.ibm.ServerWizard2;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Calendar;
+import java.util.Vector;
+
+import javax.swing.ProgressMonitorInputStream;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+
+public class LibraryManager {
+ public String xmlDirectory = "";
+ public String scriptDirectory = "";
+ private Vector<LibraryFile> files = new Vector<LibraryFile>();
+
+ public enum UpdateStatus {
+ FILE_NOT_LOCAL, REMOTE_FILE_NEWER, NO_UPDATE_NEEDED, UNABLE_TO_DOWNLOAD, UPDATE_REQUIRED, UPDATE_RECOMMENDED
+ }
+
+ public static String getWorkingDir() {
+ // gets working directory whether running as jar or from eclipse
+ File f = new File("").getAbsoluteFile();
+ String workingDir = f.getAbsolutePath() + System.getProperty("file.separator");
+ return workingDir;
+ }
+
+ public void loadModel(SystemModel model) throws Exception {
+ for (LibraryFile libFile : files) {
+ if (libFile.getType() == LibraryFile.FileTypes.ATTRIBUTE_TYPE_XML) {
+ model.loadAttributes(new XmlHandler(), libFile.getLocalPath());
+ }
+ if (libFile.getType() == LibraryFile.FileTypes.TARGET_TYPE_XML) {
+ model.loadTargetTypes(new XmlHandler(), libFile.getLocalPath());
+ }
+ if (libFile.getType() == LibraryFile.FileTypes.TARGET_INSTANCES_XML) {
+ model.loadTargetInstances(libFile.getLocalPath());
+ }
+ }
+ }
+
+ public void init() {
+ String workingDir = LibraryManager.getWorkingDir();
+ try {
+ String hbUrl = "https://raw.githubusercontent.com/open-power/hostboot/master/src/usr/targeting/common/xmltohb/";
+ String swUrl = "https://raw.githubusercontent.com/nkskjames/serverwiz/master/ServerWizard2/";
+
+ LibraryFile f1 = new LibraryFile();
+ f1.init(swUrl + "xml/attribute_types.xml", workingDir,
+ LibraryFile.FileTypes.ATTRIBUTE_TYPE_XML);
+ files.add(f1);
+
+ LibraryFile f2 = new LibraryFile();
+ f2.init(swUrl + "xml/attribute_types_hb.xml", workingDir,
+ LibraryFile.FileTypes.ATTRIBUTE_TYPE_XML);
+ files.add(f2);
+
+ LibraryFile f3 = new LibraryFile();
+ f3.init(swUrl + "xml/attribute_types_mrw.xml", workingDir,
+ LibraryFile.FileTypes.ATTRIBUTE_TYPE_XML);
+ files.add(f3);
+
+ LibraryFile f4 = new LibraryFile();
+ f4.init(swUrl + "xml/target_types_mrw.xml", workingDir,
+ LibraryFile.FileTypes.TARGET_TYPE_XML);
+ files.add(f4);
+
+ LibraryFile f5 = new LibraryFile();
+ f5.init(swUrl + "xml/target_instances_v3.xml", workingDir,
+ LibraryFile.FileTypes.TARGET_INSTANCES_XML);
+ files.add(f5);
+
+ LibraryFile f7 = new LibraryFile();
+ f7.init(swUrl + "scripts/processMrw.pl", workingDir, LibraryFile.FileTypes.SCRIPT);
+ files.add(f7);
+
+ LibraryFile f8 = new LibraryFile();
+ f8.init(swUrl + "scripts/Targets.pm", workingDir, LibraryFile.FileTypes.SCRIPT);
+ files.add(f8);
+
+ } catch (Exception e) {
+ ServerWizard2.LOGGER.severe(e.getMessage());
+ e.printStackTrace();
+ System.exit(3);
+ }
+ // create xml subdir if doesn't exist
+ File dir = new File(workingDir + "xml");
+ if (!dir.exists()) {
+ try {
+ dir.mkdir();
+ } catch (SecurityException se) {
+ System.err.println("Unable to create directory: " + workingDir + "xml");
+ }
+ }
+ // create scripts subdir if doesn't exist
+ File sdir = new File(workingDir + "scripts");
+ if (!sdir.exists()) {
+ try {
+ sdir.mkdir();
+ } catch (SecurityException se) {
+ System.err.println("Unable to create directory: " + workingDir + "scripts");
+ }
+ }
+
+ }
+
+ public boolean doUpdateCheck() {
+ String workingDir = LibraryManager.getWorkingDir();
+ String updateFilename = workingDir + "serverwiz2.update";
+ File updateFile = new File(updateFilename);
+
+ Long currentTime = Calendar.getInstance().getTimeInMillis();
+ Boolean doUpdate = true;
+
+ if (updateFile.exists()) {
+ // check last update
+ // update check done once per week
+ Long updateTime = (long) 0;
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new FileReader(updateFile));
+ String t = reader.readLine();
+ updateTime = Long.parseLong(t);
+ } catch (Exception e) {
+ ServerWizard2.LOGGER.severe("Error reading " + updateFilename + "\n"
+ + e.getMessage());
+ } finally {
+ try {
+ // Close the writer regardless of what happens...
+ reader.close();
+ } catch (Exception e) {
+ }
+ }
+ ServerWizard2.LOGGER.info("Current Time: " + String.valueOf(currentTime)
+ + "; Update Time: " + String.valueOf(updateTime));
+
+ long msPerDay = 86400*1000;
+ if ((currentTime - updateTime) < msPerDay*3) {
+ ServerWizard2.LOGGER.info("Update Check Not Needed");
+ doUpdate = false;
+ }
+ }
+ if (doUpdate) {
+ ServerWizard2.LOGGER.info("Update Check Needed");
+ BufferedWriter writer = null;
+ try {
+ writer = new BufferedWriter(new FileWriter(updateFile));
+ writer.write(String.valueOf(currentTime));
+ } catch (Exception e) {
+ ServerWizard2.LOGGER.severe("Error writing " + updateFilename + "\n"
+ + e.getMessage());
+ } finally {
+ try {
+ // Close the writer regardless of what happens...
+ writer.close();
+ } catch (Exception e) {
+ }
+ }
+ }
+ return doUpdate;
+ }
+
+ /*
+ * check if files exist yes- files exist, check if github is newer if yes,
+ * then ask user if wishes to update if no or can't download, then continue
+ * no- files don't exist; download if can't download, then exit
+ */
+ public void update() {
+ // init();
+ Boolean fileNotLocal = false;
+ Boolean remoteFileNewer = false;
+ Boolean doDownload = false;
+ for (LibraryFile libFile : files) {
+ UpdateStatus status = getUpdateStatus(libFile);
+ if (status == UpdateStatus.FILE_NOT_LOCAL) {
+ fileNotLocal = true;
+ }
+ if (status == UpdateStatus.REMOTE_FILE_NEWER) {
+ remoteFileNewer = true;
+ }
+ }
+ if (remoteFileNewer) {
+ doDownload = MessageDialog.openConfirm(null, "Confirm update",
+ "Library out of date. Do you wish to download latest library");
+ }
+ // do download
+ if (fileNotLocal || doDownload) {
+ int fileNum = 0;
+ for (LibraryFile libFile : files) {
+ downloadXML(libFile, fileNum);
+ fileNum++;
+ }
+ }
+ }
+
+ public UpdateStatus getUpdateStatus(LibraryFile f) {
+ ServerWizard2.LOGGER.info("Checking status: " + f.getRemotePath());
+
+ // Check local file size
+ File file = new File(f.getLocalPath());
+ double localFileSize = 0;
+ if (file.exists()) {
+ localFileSize = file.length();
+ } else {
+ return UpdateStatus.FILE_NOT_LOCAL;
+ }
+ UpdateStatus r = UpdateStatus.NO_UPDATE_NEEDED;
+ try {
+ URL u;
+ u = new URL(f.getRemotePath());
+ URLConnection connection = u.openConnection();
+ connection.setConnectTimeout(5000);
+ connection.connect();
+ int remoteFileSize = connection.getContentLength();
+
+ if ((double) remoteFileSize == localFileSize) {
+ // no update needed
+ ServerWizard2.LOGGER.info("No update needed for " + f.getLocalPath() + ".");
+ r = UpdateStatus.NO_UPDATE_NEEDED;
+ } else {
+ // update needed
+ ServerWizard2.LOGGER.info("Update needed for " + f.getLocalPath() + ".");
+ r = UpdateStatus.REMOTE_FILE_NEWER;
+ }
+ connection.getInputStream().close();
+ } catch (Exception e) {
+ // unable to download
+ ServerWizard2.LOGGER.info("Unable to connect to " + f.getFilename()
+ + ". Using local version.");
+ r = UpdateStatus.UNABLE_TO_DOWNLOAD;
+ }
+ return r;
+ }
+
+ public void downloadXML(LibraryFile f, int fileNum) {
+ // Check local file size
+ File file = new File(f.getLocalPath());
+ double localFileSize = 0;
+ if (file.exists()) {
+ localFileSize = file.length();
+ }
+ ProgressMonitorInputStream pim = null;
+ try {
+ URL u;
+ u = new URL(f.getRemotePath());
+ URLConnection connection = u.openConnection();
+ connection.setConnectTimeout(5000);
+ connection.setReadTimeout(15000);
+ connection.connect();
+ int remoteFileSize = connection.getContentLength();
+ if ((double) remoteFileSize == localFileSize) {
+ ServerWizard2.LOGGER.info(f.getFilename()
+ + " - Not downloading, files are same size");
+ } else {
+ ServerWizard2.LOGGER.info("Downloading: " + f.getRemotePath() + " ("
+ + remoteFileSize + ")");
+ pim = new ProgressMonitorInputStream(null, "Downloading " + (fileNum + 1) + " of "
+ + files.size() + " library files: " + f.getFilename(),
+ connection.getInputStream());
+ pim.getProgressMonitor().setMaximum(remoteFileSize);
+ pim.getProgressMonitor().setMillisToDecideToPopup(500);
+ Writer out = new BufferedWriter(new FileWriter(f.getLocalPath()));
+ int j;
+ while ((j = pim.read()) != -1) {
+ out.write((char) j);
+ }
+ out.close();
+ }
+ connection.getInputStream().close();
+ } catch (Exception e) {
+ if (pim != null) {
+ try {
+ pim.close();
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ if (localFileSize == 0) {
+ ServerWizard2.LOGGER.severe("Unable to download " + f.getFilename()
+ + " and local version doesn't exist. Exiting...");
+ MessageDialog.openError(null, "Unable to Download",
+ "Unable to download " + f.getFilename()
+ + " and local version doesn't exist. Exiting...");
+ System.exit(3);
+ } else {
+ ServerWizard2.LOGGER.info("Unable to download " + f.getFilename()
+ + ". Using local version.");
+ }
+ }
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/LogViewerDialog.java b/src/com/ibm/ServerWizard2/LogViewerDialog.java
new file mode 100644
index 0000000..6195ee9
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/LogViewerDialog.java
@@ -0,0 +1,63 @@
+package com.ibm.ServerWizard2;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.wb.swt.SWTResourceManager;
+
+public class LogViewerDialog extends Dialog {
+
+ /**
+ * Create the dialog.
+ * @param parentShell
+ */
+ private String data="";
+
+ public LogViewerDialog(Shell parentShell) {
+ super(parentShell);
+ setShellStyle(SWT.BORDER | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.TITLE | SWT.APPLICATION_MODAL);
+ }
+ public void setData(String data) {
+ this.data=data;
+ }
+ /**
+ * Create contents of the dialog.
+ * @param parent
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite container = (Composite) super.createDialogArea(parent);
+ FillLayout fl_container = new FillLayout(SWT.HORIZONTAL);
+ fl_container.marginHeight = 20;
+ fl_container.marginWidth = 20;
+ container.setLayout(fl_container);
+
+ StyledText styledText = new StyledText(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
+ styledText.setFont(SWTResourceManager.getFont("Courier New", 8, SWT.NORMAL));
+ styledText.setText(data);
+ return container;
+ }
+ /**
+ * Create contents of the button bar.
+ * @param parent
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ }
+
+ /**
+ * Return the initial size of the dialog.
+ */
+ @Override
+ protected Point getInitialSize() {
+ return new Point(723, 629);
+ }
+
+}
diff --git a/src/com/ibm/ServerWizard2/MainDialog.java b/src/com/ibm/ServerWizard2/MainDialog.java
new file mode 100644
index 0000000..1f812cf
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/MainDialog.java
@@ -0,0 +1,1143 @@
+package com.ibm.ServerWizard2;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.wb.swt.SWTResourceManager;
+
+public class MainDialog extends Dialog {
+ private TableViewer viewer;
+ private Tree tree;
+ private TreeColumn columnName;
+ private Text txtInstanceName;
+ private Combo combo;
+ private Menu popupMenu;
+ private Composite container;
+ private TreeItem selectedEndpoint;
+ private String currentPath;
+
+ private Target targetForConnections;
+ private ConnectionEndpoint source;
+ private ConnectionEndpoint dest;
+
+ TargetWizardController controller;
+
+ // Buttons
+ private Button btnAddTarget;
+ private Button btnCopyInstance;
+ private Button btnDeleteTarget;
+ private Button btnSave;
+ private Button btnOpen;
+ private Button btnDeleteConnection;
+ private Button btnSaveAs;
+
+ // document state
+ private Boolean dirty = false;
+ public String mrwFilename = "";
+
+ private Button btnRunChecks;
+ private SashForm sashForm;
+ private SashForm sashForm_1;
+
+ private Composite compositeBus;
+ private Label lblInstanceType;
+ private Composite compositeInstance;
+ private Composite composite;
+
+ private Vector<Field> attributes;
+ private Combo cmbBusses;
+ private Label lblChooseBus;
+ private Label lblSelectedCard;
+ private Boolean busMode = false;
+ private TabFolder tabFolder;
+ private TabItem tbtmAddInstances;
+ private TabItem tbtmAddBusses;
+ private Combo cmbCards;
+ private Boolean targetFound = false;
+ private List listBusses;
+ private Label lblBusDirections;
+ private Label lblInstanceDirections;
+ private Composite compositeDir;
+ private Button btnHideBusses;
+
+ /**
+ * Create the dialog.
+ *
+ * @param parentShell
+ */
+ public MainDialog(Shell parentShell) {
+ super(parentShell);
+ setShellStyle(SWT.BORDER | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.APPLICATION_MODAL);
+ }
+
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("ServerWiz2");
+ }
+
+ public void setController(TargetWizardController t) {
+ controller = t;
+ }
+
+ /**
+ * Create contents of the dialog.
+ *
+ * @param parent
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ container = (Composite) super.createDialogArea(parent);
+ container.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ container.setLayout(new GridLayout(1, false));
+
+ composite = new Composite(container, SWT.NONE);
+ RowLayout rl_composite = new RowLayout(SWT.HORIZONTAL);
+ rl_composite.spacing = 20;
+ rl_composite.wrap = false;
+ rl_composite.fill = true;
+ composite.setLayout(rl_composite);
+ GridData gd_composite = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1);
+ gd_composite.widthHint = 918;
+ gd_composite.heightHint = 135;
+ composite.setLayoutData(gd_composite);
+
+ sashForm_1 = new SashForm(container, SWT.BORDER | SWT.VERTICAL);
+ GridData gd_sashForm_1 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
+ gd_sashForm_1.heightHint = 375;
+ gd_sashForm_1.widthHint = 712;
+ sashForm_1.setLayoutData(gd_sashForm_1);
+
+ sashForm = new SashForm(sashForm_1, SWT.NONE);
+
+ // Target Instances View
+ tree = new Tree(sashForm, SWT.BORDER | SWT.VIRTUAL);
+ tree.setToolTipText("To add an instance\r\n- click on parent\r\n- choose an instance type\r\n- click add instance");
+ tree.setHeaderVisible(true);
+ tree.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ columnName = new TreeColumn(tree, 0);
+ columnName.setText("Instances");
+ columnName
+ .setToolTipText("To add a new instance, choose parent instance. A list of child instances will appear in Instance Type combo.\r\n"
+ + "Select and Instance type. You can optionally enter a custom name. Then click 'Add Instance' button.");
+
+ columnName.setResizable(true);
+ // sashForm.setWeights(new int[] { 283, 283 });
+
+ // Create attribute table
+ viewer = new TableViewer(sashForm_1, SWT.VIRTUAL | SWT.H_SCROLL | SWT.V_SCROLL
+ | SWT.FULL_SELECTION | SWT.BORDER);
+
+ this.createAttributeTable();
+ sashForm_1.setWeights(new int[] { 1, 1 });
+
+ // //////////////////////////////////////////////////////////
+ // Tab folders
+ tabFolder = new TabFolder(composite, SWT.NONE);
+
+ tbtmAddInstances = new TabItem(tabFolder, SWT.NONE);
+ tbtmAddInstances.setText("Instances");
+
+ // //////////////////////////////////////
+ // Add instances tab
+ compositeInstance = new Composite(tabFolder, SWT.BORDER);
+ tbtmAddInstances.setControl(compositeInstance);
+ compositeInstance.setLayout(new GridLayout(3, false));
+
+ lblInstanceType = new Label(compositeInstance, SWT.NONE);
+ lblInstanceType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblInstanceType.setText("Instance Type:");
+ lblInstanceType.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+
+ combo = new Combo(compositeInstance, SWT.NONE);
+ GridData gd_combo = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
+ gd_combo.widthHint = 167;
+ combo.setLayoutData(gd_combo);
+ combo.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+
+ btnAddTarget = new Button(compositeInstance, SWT.NONE);
+ btnAddTarget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+ btnAddTarget.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnAddTarget.setText("Add Instance");
+ btnAddTarget.setEnabled(false);
+
+ Label lblName = new Label(compositeInstance, SWT.NONE);
+ lblName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblName.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ lblName.setText("Custom Name:");
+
+ txtInstanceName = new Text(compositeInstance, SWT.BORDER);
+ GridData gd_txtInstanceName = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
+ gd_txtInstanceName.widthHint = 175;
+ txtInstanceName.setLayoutData(gd_txtInstanceName);
+ txtInstanceName.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+
+ btnDeleteTarget = new Button(compositeInstance, SWT.NONE);
+ btnDeleteTarget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+ btnDeleteTarget.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnDeleteTarget.setText("Delete Instance");
+ new Label(compositeInstance, SWT.NONE);
+ new Label(compositeInstance, SWT.NONE);
+
+ btnCopyInstance = new Button(compositeInstance, SWT.NONE);
+ btnCopyInstance.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
+ btnCopyInstance.setText("Copy Node or Connector");
+ btnCopyInstance.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnCopyInstance.setEnabled(false);
+ // new Label(compositeInstance, SWT.NONE);
+
+ // ////////////////////////////////////////////////////
+ // Add Busses Tab
+
+ tbtmAddBusses = new TabItem(tabFolder, SWT.NONE);
+ tbtmAddBusses.setText("Busses");
+
+ compositeBus = new Composite(tabFolder, SWT.BORDER);
+ tbtmAddBusses.setControl(compositeBus);
+ compositeBus.setLayout(new GridLayout(2, false));
+
+ lblChooseBus = new Label(compositeBus, SWT.NONE);
+ lblChooseBus.setAlignment(SWT.RIGHT);
+ GridData gd_lblChooseBus = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
+ gd_lblChooseBus.widthHint = 88;
+ lblChooseBus.setLayoutData(gd_lblChooseBus);
+ lblChooseBus.setText("Select Bus:");
+
+ cmbBusses = new Combo(compositeBus, SWT.READ_ONLY);
+ cmbBusses.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1));
+
+ cmbBusses.add("NONE");
+ cmbBusses.setData(null);
+ cmbBusses.select(0);
+
+ lblSelectedCard = new Label(compositeBus, SWT.NONE);
+ lblSelectedCard.setAlignment(SWT.RIGHT);
+ GridData gd_lblSelectedCard = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
+ gd_lblSelectedCard.widthHint = 93;
+ lblSelectedCard.setLayoutData(gd_lblSelectedCard);
+ lblSelectedCard.setText("Select Card:");
+
+ cmbCards = new Combo(compositeBus, SWT.READ_ONLY);
+ cmbCards.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+
+ btnDeleteConnection = new Button(compositeBus, SWT.NONE);
+ btnDeleteConnection.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
+ btnDeleteConnection.setText("Delete Connection");
+ btnDeleteConnection.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+
+ btnHideBusses = new Button(compositeBus, SWT.CHECK);
+ btnHideBusses.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
+ btnHideBusses.setText("Show only busses of selected type");
+ btnHideBusses.setSelection(true);
+
+ StackLayout stackLayout = new StackLayout();
+ compositeDir = new Composite(composite, SWT.NONE);
+ compositeDir.setLayout(stackLayout);
+ compositeDir.setLayoutData(new RowData(382, SWT.DEFAULT));
+
+ lblInstanceDirections = new Label(compositeDir, SWT.NONE);
+ lblInstanceDirections.setFont(SWTResourceManager.getFont("Arial", 8, SWT.NORMAL));
+ lblInstanceDirections.setText("Steps for adding a new instance\r\n"
+ + "1. Select parent instance in Instance Tree (sys-0 if just starting)\r\n"
+ + "2. Select new instance type in dropdown\r\n"
+ + "3. (Optional) Enter custom name\r\n" + "4. Click \"Add Instance\"");
+ lblInstanceDirections.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
+ stackLayout.topControl = this.lblInstanceDirections;
+
+ lblBusDirections = new Label(compositeDir, SWT.NONE);
+ lblBusDirections.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
+ lblBusDirections
+ .setText("Steps for adding a new connection:\r\n"
+ + "1. Select a bus type from dropdown\r\n"
+ + "2. Select the card on which the bus is on from dropdown\r\n"
+ + "3. Navigate to connection source in Instances Tree view on left\r\n"
+ + "4. Right-click on source and select \"Set Source\"\r\n"
+ + "5. Navigate to connection destination\r\n6. Right-click on destination and select \"Add Connection\"");
+
+ listBusses = new List(sashForm, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+
+ this.addEvents();
+
+ controller.init();
+
+ this.setDirtyState(false);
+ // load file if passed on command line
+ if (!mrwFilename.isEmpty()) {
+ ServerWizard2.LOGGER.info("Loading MRW: " + mrwFilename);
+ controller.readXML(mrwFilename);
+ setFilename(mrwFilename);
+ }
+ for (Target t : controller.getBusTypes()) {
+ cmbBusses.add(t.getType());
+ cmbBusses.setData(t.getType(), t);
+ }
+ this.initInstanceMode();
+ // columnName.setWidth(200);
+ sashForm.setWeights(new int[] { 1, 1 });
+ columnName.pack();
+ return container;
+ }
+
+ /**
+ * Create contents of the button bar.
+ *
+ * @param parent
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ parent.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ Button btnNew = createButton(parent, IDialogConstants.NO_ID, "New", false);
+ btnNew.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnNew.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (dirty) {
+ if (!MessageDialog.openConfirm(null, "Save Resource", mrwFilename
+ + "has been modified. Ignore changes?")) {
+ return;
+ }
+ ServerWizard2.LOGGER.info("Discarding changes");
+ }
+ try {
+ controller.initModel();
+ setFilename("");
+ initAll();
+ setDirtyState(false);
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ }
+ });
+
+ btnOpen = createButton(parent, IDialogConstants.NO_ID, "Open", false);
+ btnOpen.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnOpen.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (dirty) {
+ if (!MessageDialog.openConfirm(null, "Save Resource", mrwFilename
+ + "has been modified. Ignore changes?")) {
+ return;
+ }
+ ServerWizard2.LOGGER.info("Discarding changes");
+ }
+ Button b = (Button) e.getSource();
+ FileDialog fdlg = new FileDialog(b.getShell(), SWT.OPEN);
+ String ext[] = { "*.xml" };
+ fdlg.setFilterExtensions(ext);
+ String filename = fdlg.open();
+ if (filename == null) {
+ return;
+ }
+ controller.readXML(filename);
+ setFilename(filename);
+ initAll();
+ setDirtyState(false);
+ }
+ });
+ btnOpen.setToolTipText("Loads XML from file");
+
+ btnSave = createButton(parent, IDialogConstants.NO_ID, "Save", false);
+ btnSave.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnSave.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String filename = mrwFilename;
+ if (mrwFilename.isEmpty()) {
+ Button b = (Button) e.getSource();
+ FileDialog fdlg = new FileDialog(b.getShell(), SWT.SAVE);
+ String ext[] = { "*.xml" };
+ fdlg.setFilterExtensions(ext);
+ fdlg.setOverwrite(true);
+ filename = fdlg.open();
+ if (filename == null) {
+ return;
+ }
+ }
+ controller.writeXML(filename);
+ setFilename(filename);
+ setDirtyState(false);
+ }
+ });
+ btnSave.setText("Save");
+
+ btnSaveAs = createButton(parent, IDialogConstants.NO_ID, "Save As...", false);
+ btnSaveAs.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Button b = (Button) e.getSource();
+ FileDialog fdlg = new FileDialog(b.getShell(), SWT.SAVE);
+ String ext[] = { "*.xml" };
+ fdlg.setFilterExtensions(ext);
+ fdlg.setOverwrite(true);
+ String filename = fdlg.open();
+ if (filename == null) {
+ return;
+ }
+ controller.writeXML(filename);
+ setFilename(filename);
+ setDirtyState(false);
+ }
+ });
+
+ btnSaveAs.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnSaveAs.setEnabled(true);
+
+ Button btnImportSDR = createButton(parent, IDialogConstants.NO_ID, "Import SDR", false);
+ btnImportSDR.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Button b = (Button) e.getSource();
+ FileDialog fdlg = new FileDialog(b.getShell(), SWT.OPEN);
+ String ext[] = { "*.xml" };
+ fdlg.setFilterExtensions(ext);
+ String filename = fdlg.open();
+ if (filename == null) {
+ return;
+ }
+ controller.importSDR(filename);
+ setDirtyState(true);
+ }
+ });
+
+ btnImportSDR.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnImportSDR.setEnabled(true);
+
+ btnRunChecks = createButton(parent, IDialogConstants.NO_ID, "Run Checks", false);
+ btnRunChecks.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ String tempFile = System.getProperty("java.io.tmpdir")
+ + System.getProperty("file.separator") + "~temp.xml";
+ controller.writeXML(tempFile);
+ controller.runChecks(tempFile);
+ }
+ });
+ btnRunChecks.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+
+ Button btnSpacer = createButton(parent, IDialogConstants.NO_ID, "Spacer", false);
+ btnSpacer.setVisible(false);
+
+ Button btnForceUpdate = createButton(parent, IDialogConstants.NO_ID, "Force Update", false);
+ btnForceUpdate.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnForceUpdate.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String workingDir = LibraryManager.getWorkingDir();
+ String updateFilename = workingDir + "serverwiz2.update";
+ File updateFile = new File(updateFilename);
+ if (updateFile.delete()) {
+ MessageDialog.openInformation(null, "Force Update",
+ "Update will occur upon restart...");
+ ServerWizard2.LOGGER.info("Removing update file to force update upon restart.");
+ } else {
+ MessageDialog.openError(null, "Error",
+ "Unable to delete serverwiz2.update. Try deleting manually.");
+ ServerWizard2.LOGGER.severe("Unable to delete serverwiz2.update.");
+ }
+ }
+ });
+
+ Button btnExit = createButton(parent, IDialogConstants.CLOSE_ID, "Exit", false);
+ btnExit.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnExit.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Button b = (Button) e.getSource();
+ b.getShell().close();
+ }
+ });
+ }
+
+ /**
+ * Return the initial size of the dialog.
+ */
+ @Override
+ protected Point getInitialSize() {
+ return new Point(933, 796);
+ }
+
+ // ////////////////////////////////////////////////////
+ // Utility helpers
+ private Target getSelectedTarget() {
+ if (tree.getSelectionCount() > 0) {
+ return (Target) tree.getSelection()[0].getData();
+ }
+ return null;
+ }
+
+ public void initAll() {
+ tabFolder.setSelection(0);
+ initInstanceMode();
+ }
+
+ public void initBusMode() {
+ busMode = true;
+ this.lblBusDirections.setEnabled(true);
+ this.lblBusDirections.setVisible(true);
+ this.lblInstanceDirections.setVisible(false);
+ this.lblInstanceDirections.setEnabled(false);
+
+ // update card combo
+ cmbCards.removeAll();
+ for (Target target : controller.getConnectionCapableTargets()) {
+ cmbCards.add(target.getName());
+ cmbCards.setData(target.getName(), target);
+ }
+ if (cmbCards.getItemCount() > 0) {
+ cmbCards.select(0);
+ }
+ for (TreeItem item : tree.getItems()) {
+ Target target = (Target) item.getData();
+ // controller.getRootTarget().hideBusses();
+ controller.hideBusses(target);
+ }
+ this.targetForConnections = null;
+
+ this.source = null;
+ this.dest = null;
+ this.selectedEndpoint = null;
+ this.targetFound = false;
+ refreshInstanceTree();
+ refreshConnections();
+ this.updateView();
+ }
+
+ public void initInstanceMode() {
+ busMode = false;
+ this.lblInstanceDirections.setEnabled(true);
+ this.lblInstanceDirections.setVisible(true);
+
+ this.lblBusDirections.setEnabled(false);
+ this.lblBusDirections.setVisible(false);
+
+ this.targetForConnections = null;
+ this.refreshInstanceTree();
+ this.listBusses.removeAll();
+ this.updateView();
+ }
+
+ private void updateChildCombo(Target targetInstance) {
+ btnAddTarget.setEnabled(false);
+ Vector<Target> v = controller.getChildTargets(targetInstance);
+ combo.removeAll();
+ if (v != null) {
+ for (Target target : v) {
+ combo.add(target.getType());
+ combo.setData(target.getType(), target);
+ }
+ if (combo.getItemCount() > 0) {
+ combo.select(0);
+ }
+ btnAddTarget.setEnabled(true);
+ }
+ }
+
+ public void updateView() {
+ Target targetInstance = getSelectedTarget();
+ if (targetInstance == null) {
+ btnAddTarget.setEnabled(false);
+ btnDeleteTarget.setEnabled(false);
+ btnCopyInstance.setEnabled(false);
+ return;
+ }
+ updatePopupMenu(targetInstance);
+ updateChildCombo(targetInstance);
+
+ TreeItem item = tree.getSelection()[0];
+ ConnectionEndpoint ep = this.getEndpoint(item, null);
+ refreshAttributes(targetInstance,ep);
+
+ if (targetInstance.isSystem()) {
+ btnDeleteTarget.setEnabled(false);
+ } else {
+ btnDeleteTarget.setEnabled(true);
+ }
+ if (targetInstance.isNode() || targetInstance.isConnector()) {
+ btnCopyInstance.setEnabled(true);
+ } else {
+ btnCopyInstance.setEnabled(false);
+ }
+ }
+
+ public void refreshInstanceTree() {
+ currentPath="";
+ for (Target target : controller.getRootTargets()) {
+ this.updateInstanceTree(target, null);
+ }
+ btnAddTarget.setEnabled(false);
+ }
+
+ public void updatePopupMenu(Target selectedTarget) {
+ if (selectedTarget == null || tree.getSelectionCount()==0) {
+ return;
+ }
+ if (popupMenu != null) {
+ popupMenu.dispose();
+ }
+
+ popupMenu = new Menu(tree);
+
+ if (busMode) {
+ if (cmbBusses.getSelectionIndex() > 0) {
+ if (targetForConnections != null && selectedTarget.getAttribute("CLASS").equals("UNIT")) {
+ if (selectedTarget.isOutput()) {
+ MenuItem srcItem = new MenuItem(popupMenu, SWT.NONE);
+ srcItem.setText("Set Source");
+ srcItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ source = getEndpoint(true);
+ }
+ });
+ }
+ }
+ if (source != null && selectedTarget.isInput()) {
+ MenuItem connItem = new MenuItem(popupMenu, SWT.NONE);
+ connItem.setText("Add Connection");
+ connItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ dest = getEndpoint(false);
+ addConnection(false);
+ }
+ });
+ MenuItem cableItem = new MenuItem(popupMenu, SWT.NONE);
+ cableItem.setText("Add Cable");
+ cableItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ dest = getEndpoint(false);
+ addConnection(true);
+ }
+ });
+ }
+ } else {
+ targetForConnections = null;
+ source = null;
+ dest = null;
+ }
+ }
+ TreeItem item = tree.getSelection()[0];
+ TreeItem parentItem = item.getParentItem();
+ if (parentItem != null) {
+ Target configParentTarget = (Target) parentItem.getData();
+ if (configParentTarget.attributeExists("IO_CONFIG_SELECT")) {
+ MenuItem deconfigItem = new MenuItem(popupMenu, SWT.NONE);
+ deconfigItem.setText("Deconfig");
+ deconfigItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ setConfig(false);
+ }
+ });
+ MenuItem configItem = new MenuItem(popupMenu, SWT.NONE);
+ configItem.setText("Select Config");
+ configItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ setConfig(true);
+ }
+ });
+ }
+ }
+ tree.setMenu(popupMenu);
+ }
+
+ public void setConfig(boolean config) {
+ TreeItem item = tree.getSelection()[0];
+ Target target = (Target) item.getData();
+ TreeItem parentItem = item.getParentItem();
+
+ if (parentItem == null) {
+ ServerWizard2.LOGGER.warning(target.getName() + " parent is null");
+ return;
+ }
+ TreeItem grandParentItem = parentItem.getParentItem();
+ Target configParentTarget = (Target) parentItem.getData();
+ String configNum = target.getAttribute("IO_CONFIG_NUM");
+ if (configNum.isEmpty()) {
+ ServerWizard2.LOGGER.warning(target.getName() + " IO_CONFIG_NUM attribute is empty");
+ return;
+ }
+ ConnectionEndpoint ep = getEndpoint(parentItem,null);
+ String path = "/"+ep.getName();
+ controller.setGlobalSetting(path, "INSTANCE_ID", configParentTarget.getName());
+ if (config) {
+ controller.setGlobalSetting(path, "IO_CONFIG_SELECT", configNum);
+ } else {
+ controller.setGlobalSetting(path, "IO_CONFIG_SELECT", "0");
+ }
+ for (TreeItem childItem : parentItem.getItems()) {
+ clearTree(childItem);
+ }
+ currentPath="/"+ep.getPath();
+ currentPath=currentPath.substring(0, currentPath.length()-1);
+ this.updateInstanceTree(configParentTarget, grandParentItem, parentItem);
+ }
+
+ public ConnectionEndpoint getEndpoint(TreeItem item, String stopCard) {
+ ConnectionEndpoint endpoint = new ConnectionEndpoint();
+
+ Target target = (Target) item.getData();
+ endpoint.setTargetName(target.getName());
+
+ Boolean found = false;
+ TreeItem parentItem = item.getParentItem();
+ while (!found) {
+ if (parentItem==null) {
+ found=true;
+ } else {
+ Target parentTarget = (Target) parentItem.getData();
+ String parentName = parentTarget.getName();
+ if (parentName.equals(stopCard)) {
+ found = true;
+ } else {
+ endpoint.setPath(parentName + "/" + endpoint.getPath());
+ parentItem = parentItem.getParentItem();
+ }
+ }
+ }
+ return endpoint;
+ }
+
+ public ConnectionEndpoint getEndpoint(boolean setBold) {
+ TreeItem item = tree.getSelection()[0];
+ if (setBold) {
+ setEndpointState(item);
+ }
+ return getEndpoint(item,cmbCards.getText());
+ }
+
+ public void setEndpointState(TreeItem item) {
+ if (item != selectedEndpoint && selectedEndpoint != null) {
+ this.setFontStyle(selectedEndpoint, SWT.BOLD, false);
+ }
+ this.setFontStyle(item, SWT.BOLD | SWT.ITALIC, true);
+ selectedEndpoint = item;
+ }
+
+ private void refreshAttributes(Target targetInstance,ConnectionEndpoint ep) {
+ attributes.clear();
+ for (Map.Entry<String, Attribute> entry : targetInstance.getAttributes().entrySet()) {
+
+ Attribute attribute = entry.getValue();
+ if (!attribute.isHidden()) {
+ if (attribute.isGlobal()) {
+ if (ep !=null) {
+ String path="/"+ep.getName();
+ HashMap<String,Field> settings = controller.getGlobalSettings(path);
+ if (settings == null) {
+ controller.setGlobalSetting(path, attribute.name, "");
+ controller.setGlobalSetting(path, "INSTANCE_ID", ep.getTargetName());
+ }
+ attributes.add(controller.getGlobalSetting(path, attribute.name));
+ }
+ } else {
+ for (Field field : attribute.getValue().getFields())
+ attributes.add(field);
+ }
+ }
+ }
+ viewer.refresh();
+ }
+
+ public void clearTreeAll() {
+ if (tree.getItemCount() > 0) {
+ clearTree(tree.getItem(0));
+ }
+ tree.removeAll();
+ }
+
+ private void clearTree(TreeItem treeitem) {
+ for (int i = 0; i < treeitem.getItemCount(); i++) {
+ clearTree(treeitem.getItem(i));
+ }
+ treeitem.removeAll();
+ treeitem.dispose();
+ }
+
+ public void updateInstanceTree(Target target, TreeItem parentItem) {
+ this.updateInstanceTree(target, parentItem, null);
+ }
+
+ public void updateInstanceTree(Target target, TreeItem parentItem, TreeItem item) {
+ if (target == null) {
+ return;
+ }
+ if (target.isHidden()) {
+ return;
+ }
+ boolean hideBus = false;
+ String name = target.getName();
+ String lastPath = currentPath;
+ currentPath=currentPath+"/"+name;
+
+ if (busMode) {
+ if (!target.isSystem() && !cmbBusses.getText().equals("NONE")) {
+ if (target.isBusHidden(cmbBusses.getText())) {
+ hideBus = true;
+ if (btnHideBusses.getSelection()) {
+ currentPath=lastPath;
+ return;
+ }
+ }
+ }
+ if (parentItem != null) {
+ Field cnfgSelect = controller.getGlobalSetting(lastPath, "IO_CONFIG_SELECT");
+ if (cnfgSelect != null) {
+ if (!cnfgSelect.value.isEmpty() && !cnfgSelect.value.equals("0")) {
+ String cnfg = target.getAttribute("IO_CONFIG_NUM");
+ if (!cnfg.equals(cnfgSelect.value)) {
+ hideBus = true;
+ if (btnHideBusses.getSelection()) {
+ currentPath=lastPath;
+ return;
+ }
+ }
+ }
+ }
+ }
+ if (!hideBus) {
+ String sch = target.getAttribute("SCHEMATIC_INTERFACE");
+ if (!sch.isEmpty()) {
+ name = name + " (" + sch + ")";
+ }
+ if (target.isInput() && target.isOutput()) {
+ name = name + " <=>";
+ } else if (target.isInput()) {
+ name = name + " <=";
+ } else if (target.isOutput()) {
+ name = name + " =>";
+ }
+ }
+ }
+ Vector<Target> children = controller.getVisibleChildren(target);
+ TreeItem treeitem = item;
+ if (item == null) {
+ if (parentItem == null) {
+ clearTreeAll();
+ treeitem = new TreeItem(tree, SWT.VIRTUAL | SWT.BORDER);
+ } else {
+ treeitem = new TreeItem(parentItem, SWT.VIRTUAL | SWT.BORDER);
+ }
+ }
+ treeitem.setText(name);
+ treeitem.setData(target);
+
+ if (target.isPluggable()) {
+ this.setFontStyle(treeitem, SWT.ITALIC, true);
+ }
+ if (children != null) {
+ for (int i = 0; i < children.size(); i++) {
+ Target childTarget = children.get(i);
+ updateInstanceTree(childTarget, treeitem);
+ }
+ }
+ if (target == targetForConnections && busMode) {
+ this.setFontStyle(treeitem, SWT.BOLD, true);
+ if (!targetFound) {
+ tree.select(treeitem);
+ for (TreeItem childItem : treeitem.getItems()) {
+ tree.showItem(childItem);
+ }
+ targetFound = true;
+ }
+ }
+ currentPath=lastPath;
+ }
+
+ public void addConnection(Connection conn) {
+ listBusses.add(conn.getName());
+ listBusses.setData(conn.getName(), conn);
+ }
+
+ public void refreshConnections() {
+ listBusses.removeAll();
+ if (cmbBusses == null) {
+ return;
+ }
+ Target busTarget = (Target) cmbBusses.getData(cmbBusses.getText());
+ if (targetForConnections == null || busTarget == null) {
+ return;
+ }
+
+ for (Connection conn : targetForConnections.getBusses().get(busTarget)) {
+ addConnection(conn);
+ }
+ }
+
+ public void setFontStyle(TreeItem item, int style, boolean selected) {
+ if (item.isDisposed()) {
+ return;
+ }
+ FontData[] fD = item.getFont().getFontData();
+ fD[0].setStyle(selected ? style : 0);
+ Font newFont = new Font(this.getShell().getDisplay(), fD[0]);
+ item.setFont(newFont);
+ }
+
+ @Override
+ public boolean close() {
+ if (dirty) {
+ if (!MessageDialog.openConfirm(null, "Save Resource", mrwFilename
+ + "has been modified. Ignore changes?")) {
+ return false;
+ }
+ ServerWizard2.LOGGER.info("Discarding changes and exiting...");
+ }
+ clearTreeAll();
+ for (Control c : container.getChildren()) {
+ c.dispose();
+ }
+ return super.close();
+ }
+
+ public void addConnection(Boolean cabled) {
+ Target busTarget = (Target) cmbBusses.getData(cmbBusses.getText());
+ Connection conn = targetForConnections.addConnection(busTarget, source, dest, cabled);
+ this.addConnection(conn);
+ setDirtyState(true);
+ }
+
+ public void deleteConnection() {
+ if (targetForConnections == null || listBusses.getSelectionCount() == 0) {
+ return;
+ }
+ Connection conn = (Connection) listBusses.getData(listBusses.getSelection()[0]);
+ controller.deleteConnection(targetForConnections, conn.busTarget, conn);
+ this.refreshConnections();
+ setDirtyState(true);
+ }
+
+ public void setDirtyState(Boolean dirty) {
+ this.dirty = dirty;
+ if (this.btnSave != null) {
+ this.btnSave.setEnabled(dirty);
+ }
+ if (dirty) {
+ this.getShell().setText("ServerWiz2 - " + this.mrwFilename + " *");
+ } else {
+ this.getShell().setText("ServerWiz2 - " + this.mrwFilename);
+ }
+ }
+
+ public void setFilename(String filename) {
+ this.mrwFilename = filename;
+ this.btnSave.setEnabled(true);
+ this.getShell().setText("ServerWiz2 - " + this.mrwFilename);
+ }
+
+ public void addEvents() {
+ tabFolder.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ if (tabFolder.getSelection()[0]==tbtmAddBusses) {
+ initBusMode();
+ } else {
+ initInstanceMode();
+ }
+ }
+ });
+ tree.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateView();
+ }
+ });
+
+ tree.addListener(SWT.Expand, new Listener() {
+ public void handleEvent(Event e) {
+ final TreeItem treeItem = (TreeItem) e.item;
+ getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ treeItem.getParent().getColumns()[0].pack();
+ }
+ });
+ }
+ });
+ btnAddTarget.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Target chk = (Target) combo.getData(combo.getText());
+ if (chk != null) {
+ TreeItem selectedItem = tree.getSelection()[0];
+ Target parentTarget = (Target) selectedItem.getData();
+ String nameOverride = txtInstanceName.getText();
+ controller.addTargetInstance(chk, parentTarget, selectedItem, nameOverride);
+ txtInstanceName.setText("");
+ selectedItem.setExpanded(true);
+ columnName.pack();
+ setDirtyState(true);
+ }
+ }
+ });
+ btnDeleteTarget.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ TreeItem treeitem = tree.getSelection()[0];
+ if (treeitem == null) {
+ return;
+ }
+ controller.deleteTarget((Target) treeitem.getData());
+ clearTree(treeitem);
+ setDirtyState(true);
+ }
+ });
+ btnCopyInstance.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ TreeItem selectedItem = tree.getSelection()[0];
+ if (selectedItem == null) {
+ return;
+ }
+ Target target = (Target) selectedItem.getData();
+ Target parentTarget = (Target) selectedItem.getParentItem().getData();
+ Target newTarget = controller.copyTargetInstance(target, parentTarget, true);
+ updateInstanceTree(newTarget, selectedItem.getParentItem());
+ TreeItem t = selectedItem.getParentItem();
+ tree.select(t.getItem(t.getItemCount() - 1));
+ setDirtyState(true);
+ }
+ });
+ cmbCards.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Target t = (Target) cmbCards.getData(cmbCards.getText());
+ targetForConnections = t;
+ targetFound = false;
+ refreshInstanceTree();
+ refreshConnections();
+ }
+ });
+ cmbBusses.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ targetFound = false;
+ refreshInstanceTree();
+ refreshConnections();
+ }
+ });
+ btnDeleteConnection.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ deleteConnection();
+ }
+ });
+ listBusses.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ if (listBusses.getSelectionCount() > 0) {
+ Connection conn = (Connection) listBusses.getData(listBusses.getSelection()[0]);
+ refreshAttributes(conn.busTarget,null);
+ }
+ }
+ });
+ btnHideBusses.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ targetFound = false;
+ refreshInstanceTree();
+ refreshConnections();
+ }
+ });
+ }
+
+ public void createAttributeTable() {
+ Table table = viewer.getTable();
+
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ table.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ table.addListener(SWT.CHANGED, new Listener() {
+ public void handleEvent(Event event) {
+ setDirtyState(true);
+ }
+ });
+
+ final TableViewerColumn colName = new TableViewerColumn(viewer, SWT.NONE);
+ colName.getColumn().setWidth(256);
+ colName.getColumn().setText("Attribute");
+ colName.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ Field f = (Field) element;
+ return f.attributeName;
+ }
+ });
+
+ final TableViewerColumn colField = new TableViewerColumn(viewer, SWT.NONE);
+ colField.getColumn().setWidth(100);
+ colField.getColumn().setText("Field");
+ colField.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ Field f = (Field) element;
+ if (f.attributeName.equals(f.name)) {
+ return "";
+ }
+ return f.name;
+ }
+ });
+
+ final TableViewerColumn colValue = new TableViewerColumn(viewer, SWT.NONE);
+ colValue.getColumn().setWidth(100);
+ colValue.getColumn().setText("Value");
+ colValue.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ Field f = (Field) element;
+ return f.value;
+ }
+ });
+ colValue.setEditingSupport(new AttributeEditingSupport(viewer));
+
+ final TableViewerColumn colDesc = new TableViewerColumn(viewer, SWT.NONE);
+ colDesc.getColumn().setWidth(350);
+ colDesc.getColumn().setText("Description");
+ colDesc.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ Field f = (Field) element;
+ return f.desc;
+ }
+ });
+
+ viewer.setContentProvider(ArrayContentProvider.getInstance());
+ attributes = new Vector<Field>();
+ viewer.setInput(attributes);
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/MyLogFormatter.java b/src/com/ibm/ServerWizard2/MyLogFormatter.java
new file mode 100644
index 0000000..2bac399
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/MyLogFormatter.java
@@ -0,0 +1,43 @@
+package com.ibm.ServerWizard2;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+public class MyLogFormatter extends Formatter {
+ //
+ // Create a DateFormat to format the logger timestamp.
+ //
+ private static final DateFormat df2 = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss.SSS");
+ private static final DateFormat df = new SimpleDateFormat("hh:mm:ss.SSS");
+
+ public String format(LogRecord record) {
+ StringBuilder builder = new StringBuilder(1000);
+ if (record.getLevel()==Level.CONFIG) {
+ builder.append(df2.format(new Date(record.getMillis()))).append(" - ");
+ builder.append(formatMessage(record));
+ builder.append("\n");
+
+ } else {
+ builder.append(df.format(new Date(record.getMillis()))).append(" - ");
+ //builder.append("[").append(record.getSourceClassName()).append(".");
+ //builder.append(record.getSourceMethodName()).append("] - ");
+ builder.append("[").append(record.getLevel()).append("] - ");
+ builder.append(formatMessage(record));
+ builder.append("\n");
+ }
+ return builder.toString();
+ }
+
+ public String getHead(Handler h) {
+ return super.getHead(h);
+ }
+
+ public String getTail(Handler h) {
+ return super.getTail(h);
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/SdrRecord.java b/src/com/ibm/ServerWizard2/SdrRecord.java
new file mode 100644
index 0000000..3182cc9
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/SdrRecord.java
@@ -0,0 +1,56 @@
+package com.ibm.ServerWizard2;
+
+import org.w3c.dom.Element;
+
+public class SdrRecord {
+ private String name = "";
+ private String sdrName = "";
+ private Integer sensorId = 0x00;
+ private Integer entityId = 0x00;
+ private Integer entityInstance = 0x00;
+ private Integer sensorType = 0x00;
+ private Target target = null;
+ private String entityName = "";
+
+ public String getAttributeValue() {
+ return String.format("0x%02x%02x,0x%02x", sensorType,entityId,sensorId);
+ }
+ public void setTarget(Target target) {
+ this.target=target;
+ }
+ public Target getTarget() {
+ return target;
+ }
+ public String getName() {
+ return name;
+ }
+ public String getSdrName() {
+ return sdrName;
+ }
+ public Integer getSensorId() {
+ return sensorId;
+ }
+ public Integer getEntityId() {
+ return entityId;
+ }
+ public Integer getEntityInstance() {
+ return entityInstance;
+ }
+ public void setEntityName(String entityName) {
+ this.entityName=entityName;
+ }
+ public String getEntityName() {
+ return this.entityName;
+ }
+
+ public void readXML(Element t) {
+ name = SystemModel.getElement(t, "name");
+ sensorId = Integer.decode(SystemModel.getElement(t, "sensor_id"));
+ entityId = Integer.decode(SystemModel.getElement(t, "entity_id"));
+ sensorType = Integer.decode(SystemModel.getElement(t, "sensor_type"));
+ entityInstance = Integer.decode(SystemModel.getElement(t, "entity_instance"));
+ }
+ public String toString() {
+ return String.format("%30s (%3d) Entity Id=%3d; Entity Inst=%3d; Sensor Type=%3d",name,sensorId,entityId,entityInstance,sensorType);
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/ServerWizard2.java b/src/com/ibm/ServerWizard2/ServerWizard2.java
new file mode 100644
index 0000000..1545dfd
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/ServerWizard2.java
@@ -0,0 +1,49 @@
+package com.ibm.ServerWizard2;
+import java.io.IOException;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.FileHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+public class ServerWizard2 {
+
+ /**
+ * @param args
+ */
+
+ public static final String VERSION = "2.0.0";
+ public final static Logger LOGGER = Logger.getLogger(ServerWizard2.class.getName());
+
+ public static void main(String[] args) {
+ LOGGER.setLevel(Level.CONFIG);
+ LOGGER.setUseParentHandlers(false);
+ ConsoleHandler logConsole = new ConsoleHandler();
+ logConsole.setLevel(Level.CONFIG);
+ LOGGER.addHandler(logConsole);
+ MyLogFormatter formatter = new MyLogFormatter();
+ logConsole.setFormatter(formatter);
+
+ try {
+ FileHandler logFile = new FileHandler("serverwiz2.%u.%g.log",20000,2,true);
+ LOGGER.addHandler(logFile);
+ logFile.setFormatter(formatter);
+ logFile.setLevel(Level.CONFIG);
+ } catch (IOException e) {
+ System.err.println("Unable to create logfile");
+ System.exit(3);
+ }
+ LOGGER.config("======================================================================");
+ LOGGER.config("ServerWiz2 Starting. VERSION: "+VERSION);
+ TargetWizardController tc = new TargetWizardController();
+ SystemModel systemModel = new SystemModel();
+ MainDialog view = new MainDialog(null);
+ tc.setView(view);
+ tc.setModel(systemModel);
+ systemModel.addPropertyChangeListener(tc);
+ view.setController(tc);
+ if (args.length>0) {
+ view.mrwFilename=args[0];
+ }
+ view.open();
+ //d.dispose();
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/SystemModel.java b/src/com/ibm/ServerWizard2/SystemModel.java
new file mode 100644
index 0000000..39424bc
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/SystemModel.java
@@ -0,0 +1,537 @@
+package com.ibm.ServerWizard2;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class SystemModel {
+ // public Target rootTarget;
+ public Vector<Target> rootTargets = new Vector<Target>();
+ private DocumentBuilder builder;
+
+ // From target instances
+ private HashMap<String, Target> targetInstances = new HashMap<String, Target>();
+ private Vector<Target> targetUnitList = new Vector<Target>();
+
+ // From target types
+ private TreeMap<String, Target> targetModels = new TreeMap<String, Target>();
+ public HashMap<String, Vector<Target>> childTargetTypes = new HashMap<String, Vector<Target>>();
+
+ // From attribute types
+ public HashMap<String, Enumerator> enumerations = new HashMap<String, Enumerator>();
+ public HashMap<String, Attribute> attributes = new HashMap<String, Attribute>();
+
+ // List of targets in current system
+ private Vector<Target> targetList = new Vector<Target>();
+ private HashMap<String, Target> targetLookup = new HashMap<String, Target>();
+
+ private Vector<Target> busTypes = new Vector<Target>();
+ private PropertyChangeSupport changes = new PropertyChangeSupport(this);
+
+ private HashMap<String, HashMap<String, Field>> globalSettings = new HashMap<String, HashMap<String, Field>>();
+
+ public String logData;
+
+ public void addPropertyChangeListener(PropertyChangeListener l) {
+ changes.addPropertyChangeListener(l);
+ }
+
+ public Vector<Target> getBusTypes() {
+ return busTypes;
+ }
+
+ public Target getTarget(String t) {
+ return targetLookup.get(t);
+ }
+
+ public HashMap<String, Target> getTargetLookup() {
+ return this.targetLookup;
+ }
+
+ public Vector<Target> getTargetList() {
+ return this.targetList;
+ }
+
+ public Collection<Target> getTargetInstances() {
+ return targetInstances.values();
+ }
+ public void importSdr(Target target, HashMap<Integer, HashMap<Integer, Vector<SdrRecord>>> sdrLookup,HashMap<String,Boolean>instCheck,String path) throws Exception {
+ if (target==null) {
+ for (Target t : this.rootTargets) {
+ this.importSdr(t,sdrLookup,instCheck,"/");
+ }
+ } else {
+ String strEntityId = target.getAttribute("ENTITY_ID_LOOKUP");
+ if (!strEntityId.isEmpty()) {
+ int entityInst = target.getPosition();
+ if (entityInst==-1) { entityInst=0; } //units have special position of -1 to maintain assigned name
+ String instPath = path+target.getName();
+ HashMap<String,Field> inst = this.globalSettings.get(instPath);
+
+ if (inst!=null) {
+ Field instStr=inst.get("IPMI_INSTANCE");
+ if (instStr!=null && instStr.value!=null) {
+ if (!instStr.value.isEmpty()) {
+ entityInst = Integer.parseInt(instStr.value);
+ }
+ }
+ }
+ String key = target.getName()+":"+entityInst;
+ Boolean instFound = instCheck.get(key);
+ if (instFound!=null) {
+ throw new Exception("Duplicate instance id for instance type: \n"+instPath+
+ "\n. Make sure each instance has a unique IPMI_INSTANCE attribute.");
+ } else {
+ instCheck.put(key,true);
+ }
+ String ids[] = strEntityId.split(",");
+
+ String ipmiAttr[] = new String[16];
+ for (int i=0;i<16;i++) {
+ ipmiAttr[i]="0xFFFF,0xFF";
+ }
+ int i=0;
+ for (String id : ids) {
+ Integer entityId = Integer.decode(id);
+ if (entityId>0) {
+ HashMap<Integer,Vector<SdrRecord>> sdrMap= sdrLookup.get(entityId);
+ if (sdrMap!=null) {
+ Vector<SdrRecord> sdrs = sdrMap.get(entityInst);
+ if (sdrs!=null) {
+ for (SdrRecord sdr:sdrs ) {
+ String msg = "IMPORT MATCH: "+target.getName()+"; "+sdr.toString();
+ ServerWizard2.LOGGER.info(msg);
+ this.logData=this.logData+msg+"\n";
+ ipmiAttr[i]=sdr.getAttributeValue();
+ }
+ } else {
+ String msg = ">>IMPORT ERROR: "+target.getName()+"; Entity ID: "+entityId+"; Entity Inst: "+entityInst+" not found in SDR";
+ ServerWizard2.LOGGER.warning(msg);
+ this.logData=this.logData+msg+"\n";
+ }
+ } else {
+ String msg = ">>IMPORT ERROR: "+target.getName()+"; Entity ID: "+entityId+ " not found in SDR";
+ ServerWizard2.LOGGER.warning(msg);
+ this.logData=this.logData+msg+"\n";
+ }
+ }
+ i++;
+ }
+ String ipmiStr="";
+ String sep=",";
+ Arrays.sort(ipmiAttr);
+ for (i=0;i<16;i++) {
+ if (i==15) { sep=""; }
+ ipmiStr=ipmiStr+ipmiAttr[i]+sep;
+ }
+ this.setGlobalSetting(instPath, "IPMI_SENSORS",ipmiStr);
+ }
+ path=path+target.getName()+"/";
+ for (String child : target.getChildren()) {
+ Target childTarget = this.getTarget(child);
+ this.importSdr(childTarget, sdrLookup,instCheck,path);
+ }
+ }
+ }
+ public Vector<Target> getConnectionCapableTargets() {
+ Vector<Target> cards = new Vector<Target>();
+ for (Target target : targetList) {
+ if (target.isCard() || target.isSystem() || target.isNode()) {
+ if (!target.isLibraryTarget) {
+ cards.add(target);
+ }
+ }
+ }
+ return cards;
+ }
+
+ public void initBusses(Target target) {
+ target.initBusses(busTypes);
+ }
+
+ public Vector<Target> getChildTargetTypes(String targetType) {
+ if (targetType.equals("")) {
+ Vector<Target> a = new Vector<Target>();
+ for (Target t : this.targetModels.values()) {
+ a.add(t);
+ }
+ return a;
+ }
+ if (childTargetTypes.get(targetType) != null) {
+ Collections.sort(childTargetTypes.get(targetType));
+ }
+ return childTargetTypes.get(targetType);
+ }
+
+ public Integer getEnumValue(String enumerator, String value) {
+ Enumerator e = enumerations.get(enumerator);
+ return e.getEnumInt(value);
+ }
+
+ public String getEnumValueStr(String enumerator, String value) {
+ Enumerator e = enumerations.get(enumerator);
+ return e.getEnumStr(value);
+ }
+
+ public static String getElement(Element a, String e) {
+ Node n = a.getElementsByTagName(e).item(0);
+ if (n != null) {
+ Node cn = n.getChildNodes().item(0);
+ if (cn == null) {
+ return "";
+ }
+ return n.getChildNodes().item(0).getNodeValue();
+ }
+ return "";
+ }
+
+ public static Boolean isElementDefined(Element a, String e) {
+ Node n = a.getElementsByTagName(e).item(0);
+ if (n != null) {
+ Node cn = n.getChildNodes().item(0);
+ if (cn == null) {
+ return true;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public TreeMap<String, Target> getTargetModels() {
+ return targetModels;
+ }
+
+ public Target getTargetModel(String t) {
+ return targetModels.get(t);
+ }
+
+ public void deleteAllInstances() {
+ this.targetList.clear();
+ this.targetLookup.clear();
+ this.rootTargets.clear();
+ this.globalSettings.clear();
+ }
+
+ public void deleteTarget(Target deleteTarget) {
+ targetList.remove(deleteTarget);
+ for (Target t : targetList) {
+ t.removeChildren(deleteTarget.getName());
+ }
+ this.targetLookup.remove(deleteTarget.getName());
+ changes.firePropertyChange("DELETE_TARGET", "", "");
+ }
+
+ // Reads a previously saved MRW
+ public void readXML(String filename) throws Exception {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ // delete all existing instances
+ this.deleteAllInstances();
+ this.addUnitInstances();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setErrorHandler(new XmlHandler());
+ Document document = builder.parse(filename);
+
+ NodeList settingList = document.getElementsByTagName("globalSetting");
+ for (int i = 0; i < settingList.getLength(); ++i) {
+ Element t = (Element) settingList.item(i);
+ this.readGlobalSettings(t);
+ }
+
+ NodeList targetInstanceList = document.getElementsByTagName("targetInstance");
+ for (int i = 0; i < targetInstanceList.getLength(); ++i) {
+ Element t = (Element) targetInstanceList.item(i);
+ String type = SystemModel.getElement(t, "type");
+ if (type.length() > 0) {
+ Target targetModel = this.getTargetModel(type);
+ if (targetModel == null) {
+ ServerWizard2.LOGGER.severe("Invalid target type: " + type);
+ throw new Exception("Invalid target type: " + type);
+ } else {
+ Target target = new Target(targetModel);
+ target.initBusses(busTypes);
+
+ target.readInstanceXML(t, targetModels);
+ if (this.targetLookup.containsKey(target.getName())) {
+ // ServerWizard2.LOGGER.warning("Duplicate Target: "+target.getName());
+ } else {
+ this.targetLookup.put(target.getName(), target);
+ this.targetList.add(target);
+ }
+ if (target.getAttribute("CLASS").equals("SYS")) {
+ this.rootTargets.add(target);
+ }
+ }
+ } else {
+ throw new Exception("Empty Target Type");
+ }
+ }
+ }
+
+ public void writeEnumeration(Writer out) throws Exception {
+ for (String enumeration : enumerations.keySet()) {
+ Enumerator e = enumerations.get(enumeration);
+ out.write("<enumerationType>\n");
+ out.write("\t<id>" + enumeration + "</id>\n");
+ for (Map.Entry<String, String> entry : e.enumValues.entrySet()) {
+ out.write("\t\t<enumerator>\n");
+ out.write("\t\t<name>" + entry.getKey() + "</name>\n");
+ out.write("\t\t<value>" + entry.getValue() + "</value>\n");
+ out.write("\t\t</enumerator>\n");
+ }
+ out.write("</enumerationType>\n");
+ }
+ }
+
+ public void setGlobalSetting(String path, String attribute, String value) {
+ HashMap<String, Field> s = globalSettings.get(path);
+ if (s == null) {
+ s = new HashMap<String, Field>();
+ globalSettings.put(path, s);
+ }
+ Field f = s.get(attribute);
+ if (f == null) {
+ f = new Field();
+ f.attributeName = attribute;
+ s.put(attribute, f);
+ }
+ f.value = value;
+ }
+
+ public Field getGlobalSetting(String path, String attribute) {
+ HashMap<String, Field> s = globalSettings.get(path);
+ if (s == null) {
+ return null;
+ }
+ return s.get(attribute);
+ }
+
+ public HashMap<String, Field> getGlobalSettings(String path) {
+ HashMap<String, Field> s = globalSettings.get(path);
+ return s;
+ }
+
+ public void writeGlobalSettings(Writer out) throws Exception {
+ for (Map.Entry<String, HashMap<String, Field>> entry : this.globalSettings.entrySet()) {
+ out.write("<globalSetting>\n");
+ out.write("\t<id>" + entry.getKey() + "</id>\n");
+ for (Map.Entry<String, Field> setting : entry.getValue().entrySet()) {
+ out.write("\t<property>\n");
+ out.write("\t<id>" + setting.getKey() + "</id>\n");
+ out.write("\t<value>" + setting.getValue().value + "</value>\n");
+ out.write("\t</property>\n");
+ }
+ out.write("</globalSetting>\n");
+ }
+ }
+
+ public void readGlobalSettings(Element setting) {
+ String targetId = SystemModel.getElement(setting, "id");
+ NodeList propertyList = setting.getElementsByTagName("property");
+ for (int i = 0; i < propertyList.getLength(); ++i) {
+ Element t = (Element) propertyList.item(i);
+ String property = SystemModel.getElement(t, "id");
+ String value = SystemModel.getElement(t, "value");
+ this.setGlobalSetting(targetId, property, value);
+ }
+ }
+
+ // Writes MRW to file
+ public void writeXML(String filename) throws Exception {
+ Writer out = new BufferedWriter(new FileWriter(filename));
+ out.write("<targetInstances>\n");
+ out.write("<version>" + ServerWizard2.VERSION + "</version>\n");
+ this.writeEnumeration(out);
+ this.writeGlobalSettings(out);
+ HashMap<String, Boolean> targetWritten = new HashMap<String, Boolean>();
+ for (Target target : targetList) {
+ target.writeInstanceXML(out, targetLookup, targetWritten);
+ }
+ out.write("</targetInstances>\n");
+ out.close();
+ }
+
+ public void addTarget(Target parentTarget, Target newTarget) throws Exception {
+ if (parentTarget == null) {
+ this.rootTargets.add(newTarget);
+ } else {
+ parentTarget.addChild(newTarget.getName(), false);
+ }
+ this.updateTargetList(newTarget);
+ initBusses(newTarget);
+ changes.firePropertyChange("ADD_TARGET", "", "");
+ }
+
+ public Target getTargetInstance(String type) {
+ return targetInstances.get(type);
+ }
+
+ // Add target to target database.
+ // only contains targets that user has added
+ // not library targets
+ public void updateTargetList(Target target) throws Exception {
+ String id = target.getName();
+ if (!this.targetLookup.containsKey(id)) {
+ this.targetLookup.put(id, target);
+ this.targetList.add(target);
+ } else {
+ String msg="Duplicate Target: "+target.getName();
+ ServerWizard2.LOGGER.warning(msg);
+ throw new Exception(msg);
+ }
+ }
+
+ public void addParentAttributes(Target childTarget, Target t) {
+ if (t == null) {
+ return;
+ }
+ Target parent = targetModels.get(t.parent);
+ if (parent == null) {
+ return;
+ }
+ childTarget.copyAttributesFromParent(parent);
+ addParentAttributes(childTarget, parent);
+ }
+
+ public void loadTargetTypes(DefaultHandler errorHandler, String fileName) throws SAXException,
+ IOException, ParserConfigurationException {
+ ServerWizard2.LOGGER.info("Loading Target Types: " + fileName);
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ builder = factory.newDocumentBuilder();
+ builder.setErrorHandler(errorHandler);
+
+ Document document = builder.parse(fileName);
+ NodeList targetList = document.getElementsByTagName("targetType");
+ for (int i = 0; i < targetList.getLength(); ++i) {
+ Element t = (Element) targetList.item(i);
+ Target target = new Target();
+ target.readModelXML(t, attributes);
+ targetModels.put(target.getType(), target);
+ Vector<String> parentTypes = target.getParentType();
+ for (int j = 0; j < parentTypes.size(); j++) {
+ String parentType = parentTypes.get(j);
+ Vector<Target> childTypes = childTargetTypes.get(parentType);
+ if (childTypes == null) {
+ childTypes = new Vector<Target>();
+ childTargetTypes.put(parentType, childTypes);
+ }
+ childTypes.add(target);
+ }
+ }
+ for (Map.Entry<String, Target> entry : targetModels.entrySet()) {
+ Target target = entry.getValue();
+
+ // add inherited attributes
+ addParentAttributes(target, target);
+ if (target.getAttribute("CLASS").equals("BUS")) {
+ busTypes.add(target);
+ }
+ }
+ }
+
+ public void loadAttributes(DefaultHandler errorHandler, String fileName) throws SAXException,
+ IOException, ParserConfigurationException {
+ ServerWizard2.LOGGER.info("Loading Attributes: " + fileName);
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ builder = factory.newDocumentBuilder();
+ builder.setErrorHandler(errorHandler);
+
+ Document document = builder.parse(fileName);
+ NodeList enumList = document.getElementsByTagName("enumerationType");
+ for (int i = 0; i < enumList.getLength(); ++i) {
+ Element t = (Element) enumList.item(i);
+ Enumerator en = new Enumerator();
+ en.readXML(t);
+ enumerations.put(en.id, en);
+ }
+ NodeList attrList = document.getElementsByTagName("attribute");
+ for (int i = 0; i < attrList.getLength(); ++i) {
+ Element t = (Element) attrList.item(i);
+ Attribute a = new Attribute();
+ a.readModelXML(t);
+ attributes.put(a.name, a);
+
+ if (a.getValue().getType().equals("enumeration")) {
+ a.getValue().setEnumerator(enumerations.get(a.name));
+ }
+ }
+ }
+
+ public void loadTargetInstances(String filename) throws Exception {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setErrorHandler(new XmlHandler());
+ Document document = builder.parse(filename);
+ NodeList targetInstanceList = document.getElementsByTagName("targetInstance");
+ for (int i = 0; i < targetInstanceList.getLength(); ++i) {
+ Element t = (Element) targetInstanceList.item(i);
+ String type = SystemModel.getElement(t, "type");
+ if (type.length() > 0) {
+ Target targetModel = this.getTargetModel(type);
+ if (targetModel == null) {
+ ServerWizard2.LOGGER.severe("Invalid target type: " + type);
+ throw new Exception("Invalid target type: " + type);
+ } else {
+ Target target = new Target(targetModel);
+ target.readInstanceXML(t, targetModels);
+ if (target.instanceModel) {
+ targetInstances.put(type, target);
+ target.isLibraryTarget = true;
+ } else {
+ // this.targetLookup.put(target.getName(), target);
+ this.targetUnitList.add(target);
+ target.isLibraryTarget = true;
+ }
+ }
+ } else {
+ throw new Exception("Empty Target Type");
+ }
+ }
+ }
+
+ public void addUnitInstances() {
+ for (Target target : this.targetUnitList) {
+ this.targetLookup.put(target.getName(), target);
+ }
+ }
+
+ public void updateTargetPosition(Target target, Target parentTarget, int position) {
+ if (position > 0) {
+ target.setPosition(position);
+ return;
+ }
+ int p = -1;
+ // set target position to +1 of any target found of same type
+ for (Target t : targetList) {
+ if (t.getType().equals(target.getType())) {
+ if (t.getPosition() >= p) {
+ p = t.getPosition();
+ }
+ }
+ }
+ target.setPosition(p + 1);
+ target.setSpecialAttributes();
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/Target.java b/src/com/ibm/ServerWizard2/Target.java
new file mode 100644
index 0000000..01e8135
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/Target.java
@@ -0,0 +1,467 @@
+package com.ibm.ServerWizard2;
+
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class Target implements Comparable<Target>, java.io.Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private String name = "";
+ private String type = "";
+ private int position = -1;
+ public String parent = ""; // says which parent to inherit attributes from
+ // target_types
+ public boolean instanceModel = false;
+ public boolean isLibraryTarget = false;
+ private Vector<String> parentType = new Vector<String>();
+ private TreeMap<String, Attribute> attributes = new TreeMap<String, Attribute>();
+ //private Vector<Target> children = new Vector<Target>();
+ private Vector<String> children = new Vector<String>();
+ private Vector<String> childrenHidden = new Vector<String>();
+ private TreeMap<Target,Vector<Connection>> busses = new TreeMap<Target,Vector<Connection>>();
+ private Boolean busInited=false;
+ private Boolean hidden = false;
+ private HashMap<String,Boolean> childrenBusTypes = new HashMap<String,Boolean>();
+
+ public Target() {
+ }
+
+ public Target(Target s) {
+ this.setName(s.name);
+ this.setType(s.type);
+ this.parent = s.parent;
+ this.position = s.position;
+ this.hidden = s.hidden;
+ this.parentType.addAll(s.parentType);
+ this.isLibraryTarget=s.isLibraryTarget;
+
+ for (Map.Entry<String, Attribute> entry : s.getAttributes().entrySet()) {
+ String key = new String(entry.getKey());
+ Attribute value = new Attribute(entry.getValue());
+ this.attributes.put(key, value);
+ }
+ }
+ public TreeMap<Target,Vector<Connection>> getBusses() {
+ return busses;
+ }
+
+ public void hide(Boolean h) {
+ this.hidden=h;
+ }
+ public Boolean isHidden() {
+ return this.hidden;
+ }
+
+ public void linkBusses(Target t){
+ busses=t.getBusses();
+ }
+
+ public String getName() {
+ if (position==-1 && !name.isEmpty()) {
+ return name;
+ }
+ if (!name.isEmpty()) {
+ return name + "-" + position;
+ }
+ return getIdPrefix() + "-" + position;
+ }
+
+ public String getRawName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ ////////////////////////////////////////////
+ // Target children handling
+ public Vector<String> getChildren() {
+ return this.children;
+ }
+ public void copyChildren(Target t) {
+ for (String c : t.children) {
+ this.children.add(c);
+ }
+ for (String c : t.childrenHidden) {
+ this.childrenHidden.add(c);
+ }
+ }
+ public void removeChildren(String child) {
+ children.remove(child);
+ childrenHidden.remove(child);
+ }
+ public void addChild(String child,boolean hidden) {
+ if (hidden) {
+ childrenHidden.add(child);
+ } else {
+ children.add(child);
+ }
+ }
+
+ public Boolean isPluggable() {
+ String c = this.getAttribute("CLASS");
+
+ if (c == null) {
+ return false;
+ }
+
+ if (c.equals("CONNECTOR")) {
+ return true;
+ }
+ return false;
+ }
+
+ public void setPosition(String pos) {
+ this.position = Integer.parseInt(pos);
+ }
+
+ public void setPosition(int pos) {
+ this.position = pos;
+ }
+
+ public int getPosition() {
+ return this.position;
+ }
+
+ public Vector<String> getParentType() {
+ return this.parentType;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ public String getIdPrefix() {
+ String t = type.split("-")[1];
+ if (t.equals("processor")) {
+ t = "proc";
+ }
+ return t;
+ }
+
+ ////////////////////////////////////////////////////////
+ // Attribute handling
+ public TreeMap<String, Attribute> getAttributes() {
+ return attributes;
+ }
+ public void copyAttributes(Target s) {
+ for (Map.Entry<String, Attribute> entry : s.getAttributes().entrySet()) {
+ String key = new String(entry.getKey());
+ Attribute value = new Attribute(entry.getValue());
+ this.attributes.put(key, value);
+ }
+ }
+
+ public void linkAttributes(Target t) {
+ this.attributes.clear();
+ this.attributes = t.getAttributes();
+ }
+ public boolean attributeExists(String attribute) {
+ if (attributes.get(attribute) == null) {
+ return false;
+ }
+ return true;
+ }
+ public String getAttribute(String attribute) {
+ if (attributes.get(attribute) == null) {
+ return "";
+ }
+ return attributes.get(attribute).getValue().getValue();
+ }
+
+ public void copyAttributesFromParent(Target s) {
+ for (Map.Entry<String, Attribute> entry : s.getAttributes().entrySet()) {
+ String key = entry.getKey();
+ Attribute tmpAttribute = entry.getValue();
+ Attribute localAttribute = this.attributes.get(key);
+ // inherited attribute was already added when instance created
+ if (localAttribute != null) {
+ localAttribute.inherited = s.type;
+ }
+ else {
+ Attribute attribute = new Attribute(tmpAttribute);
+ attribute.inherited = s.type;
+ this.attributes.put(key, attribute);
+ }
+ }
+ }
+
+ public void updateAttributeValue(String attributeName, String value) {
+ Attribute attribute = attributes.get(attributeName);
+ if (attribute == null) {
+ throw new NullPointerException("Invalid Attribute " + attributeName + " in Target "
+ + this.type);
+ }
+ AttributeValue val = attribute.getValue();
+ val.setValue(value);
+ }
+
+ public void updateAttributeValue(String attributeName, AttributeValue value) {
+ Attribute attribute = attributes.get(attributeName);
+ if (attribute == null) {
+ throw new NullPointerException("Invalid Attribute " + attributeName + " in Target "
+ + this.type);
+ }
+ attribute.getValue().setValue(value);
+ }
+ public Boolean isInput() {
+ String dir = this.getAttribute("DIRECTION");
+ if (dir.equals("IN") || dir.equals("INOUT")) {
+ return true;
+ }
+ return false;
+ }
+ public Boolean isOutput() {
+ String dir = this.getAttribute("DIRECTION");
+ if (dir.equals("OUT") || dir.equals("INOUT")) {
+ return true;
+ }
+ return false;
+ }
+
+ public Boolean isSystem() {
+ return (this.getAttribute("CLASS").equals("SYS"));
+ }
+ public Boolean isCard() {
+ return (this.getAttribute("CLASS").equals("CARD") || this.getAttribute("CLASS").equals(
+ "MOTHERBOARD"));
+ }
+ public Boolean isConnector() {
+ return (this.getAttribute("CLASS").equals("CONNECTOR"));
+ }
+ public Boolean isNode() {
+ return (this.getAttribute("CLASS").equals("ENC"));
+ }
+
+ public void setAttributeValue(String attr, String value) {
+ Attribute attribute = this.attributes.get(attr);
+ if (attribute == null) {
+ return;
+ }
+ attribute.getValue().setValue(value);
+ }
+
+ public void setSpecialAttributes() {
+ this.setAttributeValue("POSITION", String.valueOf(this.getPosition()));
+
+ }
+/*
+ public String toString() {
+ String s = "TARGET: " + this.type;
+ for (Map.Entry<String, Attribute> entry : this.getAttributes().entrySet()) {
+ Attribute attr = new Attribute(entry.getValue());
+ s = s + "\t" + attr.toString() + "\n";
+ }
+ return s;
+ }
+*/
+ public int compareTo(Target arg0) {
+ Target t = (Target)arg0;
+ return this.getType().compareTo(t.getType());
+ }
+
+
+ ///////////////////////////////////////////////////
+ // connection/bus handling
+ public Boolean isBusHidden(String busType) {
+ return !this.childrenBusTypes.containsKey(busType);
+ }
+ public HashMap<String,Boolean> hideBusses(HashMap<String,Target> targetLookup) {
+ HashMap<String,Boolean> childBusTypes;
+ childrenBusTypes.clear();
+ String thisBusType = this.getAttribute("BUS_TYPE");
+ if (!thisBusType.isEmpty() &&!thisBusType.equals("NA")) {
+ this.childrenBusTypes.put(thisBusType,true);
+ }
+ for (String childStr : this.getChildren()) {
+ Target child = targetLookup.get(childStr);
+ if (child==null) {
+ ServerWizard2.LOGGER.severe("Child Target "+childStr+" not found");
+ }
+ String busType = child.getAttribute("BUS_TYPE");
+ if (!busType.isEmpty() && !busType.equals("NA")) {
+ this.childrenBusTypes.put(busType, true);
+ }
+ childBusTypes = child.hideBusses(targetLookup);
+ for (String bus : childBusTypes.keySet()) {
+ this.childrenBusTypes.put(bus, true);
+ }
+ }
+ return this.childrenBusTypes;
+ }
+ public Connection addConnection(Target busTarget,ConnectionEndpoint source,ConnectionEndpoint dest, boolean cabled) {
+ if (busTarget==null || source==null || dest==null) {
+ //TODO: error message
+ return null;
+ }
+ Vector<Connection> c = busses.get(busTarget);
+ if (c==null) {
+ c = new Vector<Connection>();
+ busses.put(busTarget, c);
+ }
+ Connection conn = new Connection();
+ conn.busType = busTarget.getType();
+ conn.source=source;
+ conn.dest=dest;
+ conn.cabled = cabled;
+ conn.busTarget = new Target(busTarget);
+ c.add(conn);
+ return conn;
+ }
+ public void deleteConnection(Target busTarget,Connection conn) {
+ Vector<Connection> connList = busses.get(busTarget);
+ connList.remove(conn);
+ }
+ public void initBusses(Vector<Target> v) {
+ if (busInited) { return; }
+ this.busInited=true;
+
+ for (Target s : v) {
+ Vector<Connection> connections = new Vector<Connection>();
+ this.busses.put(s, connections);
+ }
+ }
+
+ ////////////////////////////////////////////////////
+ // XML file handling
+ public void readModelXML(Element target, HashMap<String, Attribute> attrMap) {
+ type = SystemModel.getElement(target, "id");
+ parent = SystemModel.getElement(target, "parent");
+ NodeList parentList = target.getElementsByTagName("parent_type");
+ for (int i = 0; i < parentList.getLength(); i++) {
+ Element e = (Element) parentList.item(i);
+ parentType.add(e.getChildNodes().item(0).getNodeValue());
+ }
+ NodeList attributeList = target.getElementsByTagName("attribute");
+ for (int i = 0; i < attributeList.getLength(); ++i) {
+ String attrId = SystemModel.getElement((Element) attributeList.item(i), "id");
+ Attribute attributeLookup = attrMap.get(attrId);
+ if (attributeLookup == null) {
+ throw new NullPointerException("Invalid attribute id: " + attrId + "(" + type + ")");
+ }
+ Attribute a = new Attribute(attributeLookup);
+ if (a.value==null) {
+ throw new NullPointerException("Unknown attribute value type: " + attrId + "(" + type + ")");
+ }
+ attributes.put(a.name, a);
+ a.value.readInstanceXML((Element) attributeList.item(i));
+ }
+ }
+
+ public void readInstanceXML(Element t, TreeMap<String, Target> targetModels) throws Exception {
+ instanceModel = true;
+ name = SystemModel.getElement(t, "instance_name");
+ type = SystemModel.getElement(t, "type");
+ String library_target = SystemModel.getElement(t, "library_target");
+ if (library_target.equals("true")) {
+ this.isLibraryTarget=true;
+ } else {
+ this.isLibraryTarget=false;
+ }
+ if (name.isEmpty()) {
+ name = SystemModel.getElement(t, "id");
+ instanceModel = false;
+ } else {
+ String tmpPos = SystemModel.getElement(t, "position");
+ if (!tmpPos.isEmpty()) {
+ setPosition(tmpPos);
+ }
+ }
+
+ NodeList childList = t.getElementsByTagName("child_id");
+ for (int j = 0; j < childList.getLength(); ++j) {
+ Element attr = (Element) childList.item(j);
+ //TargetName targetName = new TargetName(attr.getFirstChild().getNodeValue(),false);
+ children.add(attr.getFirstChild().getNodeValue());
+ }
+ childList = t.getElementsByTagName("hidden_child_id");
+ for (int j = 0; j < childList.getLength(); ++j) {
+ Element attr = (Element) childList.item(j);
+ //argetName targetName = new TargetName(attr.getFirstChild().getNodeValue(),true);
+ childrenHidden.add(attr.getFirstChild().getNodeValue());
+ }
+
+ NodeList attrList = t.getElementsByTagName("attribute");
+ for (int j = 0; j < attrList.getLength(); ++j) {
+ Element attr = (Element) attrList.item(j);
+ String id = SystemModel.getElement(attr, "id");
+ Attribute a = attributes.get(id);
+ if (a==null) {
+ ServerWizard2.LOGGER.info("Attribute dropped: "+id+" from "+this.getName());
+ } else {
+ a.value.readInstanceXML(attr);
+ }
+ }
+ NodeList busList = t.getElementsByTagName("bus");
+ for (int j = 0; j < busList.getLength(); ++j) {
+ Element bus = (Element) busList.item(j);
+ String busType = SystemModel.getElement(bus, "bus_type");
+ Connection conn = new Connection();
+ conn.busType=busType;
+ Target busTarget=targetModels.get(busType);
+ if (busTarget==null) {
+ throw new Exception("Invalid Bus Type "+busType+" for target "+this.getName());
+ }
+ conn.busTarget = new Target(busTarget);
+ conn.readInstanceXML(bus);
+ busses.get(busTarget).add(conn);
+ }
+ }
+ public void writeInstanceXML(Writer out,HashMap<String,Target> targetLookup,HashMap<String,Boolean>targetWritten) throws Exception {
+ if (targetWritten.containsKey(this.getName())) {
+ return;
+ }
+ targetWritten.put(this.getName(), true);
+ out.write("<targetInstance>\n");
+ out.write("\t<id>" + this.getName() + "</id>\n");
+ out.write("\t<type>" + this.getType() + "</type>\n");
+ out.write("\t<library_target>" + this.isLibraryTarget + "</library_target>\n");
+ //out.write("\t<class>" + this.getAttribute("CLASS") + "</class>\n");
+ if (!this.name.isEmpty()) {
+ out.write("\t<instance_name>" + this.name + "</instance_name>\n");
+ } else {
+ out.write("\t<instance_name>" + this.getIdPrefix() + "</instance_name>\n");
+ }
+
+ out.write("\t<position>" + getPosition() + "</position>\n");
+ //write children
+ for (String childStr : this.children) {
+ out.write("\t<child_id>"+childStr+"</child_id>\n");
+ }
+ for (String childStr : this.childrenHidden) {
+ out.write("\t<hidden_child_id>"+childStr+"</hidden_child_id>\n");
+ }
+ //write attributes
+ for (Map.Entry<String, Attribute> entry : getAttributes().entrySet()) {
+ Attribute attr = new Attribute(entry.getValue());
+ attr.writeInstanceXML(out);
+
+ }
+ //write busses
+ for (Map.Entry<Target, Vector<Connection>> entry : busses.entrySet()) {
+ for (Connection conn : entry.getValue()) {
+ conn.writeInstanceXML(out);
+ }
+ }
+ out.write("</targetInstance>\n");
+
+ //recursively write children
+ for (String childStr : this.children) {
+ Target child = targetLookup.get(childStr);
+ child.writeInstanceXML(out, targetLookup, targetWritten);
+ }
+ for (String childStr : this.childrenHidden) {
+ Target child = targetLookup.get(childStr);
+ child.writeInstanceXML(out, targetLookup, targetWritten);
+ }
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/TargetWizardController.java b/src/com/ibm/ServerWizard2/TargetWizardController.java
new file mode 100644
index 0000000..dc5bdf4
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/TargetWizardController.java
@@ -0,0 +1,331 @@
+package com.ibm.ServerWizard2;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.TreeItem;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class TargetWizardController implements PropertyChangeListener {
+ SystemModel model;
+ MainDialog view;
+
+ public TargetWizardController() {
+ }
+
+ public void init() {
+ LibraryManager xmlLib = new LibraryManager();
+ xmlLib.init();
+ if (xmlLib.doUpdateCheck()) {
+ xmlLib.update();
+ }
+ try {
+ xmlLib.loadModel(model);
+ this.initModel();
+
+ } catch (Exception e) {
+ String btns[] = { "Close" };
+ ServerWizard2.LOGGER.severe(e.getMessage());
+ MessageDialog errDlg = new MessageDialog(view.getShell(), "Error",
+ null, e.getMessage(), MessageDialog.ERROR, btns, 0);
+ errDlg.open();
+ e.printStackTrace();
+ System.exit(4);
+ }
+
+ }
+ public void initModel() throws Exception {
+ model.deleteAllInstances();
+ model.addUnitInstances();
+
+ String parentTargetName = "sys-sys-power8";
+ Target parentTarget = model.getTargetModels().get(parentTargetName);
+ if (parentTarget == null) {
+ throw new Exception("Parent model " + parentTargetName
+ + " is not valid");
+ }
+ // Create root instance
+ Target sys = new Target(parentTarget);
+ sys.setPosition(0);
+ model.addTarget(null, sys);
+ }
+
+ public void importSDR(String filename) {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+
+ Vector<SdrRecord> sdrs = new Vector<SdrRecord>();
+ HashMap<Integer,HashMap<Integer,Vector<SdrRecord>>> sdrLookup = new HashMap<Integer,HashMap<Integer,Vector<SdrRecord>>>();
+
+ try {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setErrorHandler(new XmlHandler());
+
+ Document document = builder.parse(filename);
+
+ NodeList deviceList = document
+ .getElementsByTagName("device");
+
+ for (int i = 0; i < deviceList.getLength(); ++i) {
+ Element deviceElement = (Element) deviceList.item(i);
+ SdrRecord s = new SdrRecord();
+ s.readXML(deviceElement);
+
+ HashMap<Integer,Vector<SdrRecord>> idLookup = sdrLookup.get(s.getEntityId());
+ if (idLookup==null) {
+ idLookup = new HashMap<Integer,Vector<SdrRecord>>();
+ sdrLookup.put(s.getEntityId(), idLookup);
+ }
+ Vector<SdrRecord> sdrRecords = idLookup.get(s.getEntityInstance());
+ if (sdrRecords==null) {
+ sdrRecords = new Vector<SdrRecord>();
+ idLookup.put(s.getEntityInstance(), sdrRecords);
+ }
+ sdrRecords.add(s);
+ sdrs.add(s);
+ ServerWizard2.LOGGER.info(s.toString());
+ }
+ } catch (Exception e) {
+ MessageDialog.openError(null, "SDR Import Error", e.getMessage());
+ e.printStackTrace();
+ }
+ try {
+ HashMap<String,Boolean> instCheck = new HashMap<String,Boolean>();
+ model.logData="";
+ model.importSdr(null,sdrLookup,instCheck,"");
+ LogViewerDialog dlg = new LogViewerDialog(null);
+ dlg.setData(model.logData);
+ dlg.open();
+ } catch (Exception e) {
+ ServerWizard2.LOGGER.severe(e.getMessage());
+ MessageDialog.openError(null, "SDR Import Error", e.getMessage());
+ e.printStackTrace();
+ }
+ /*
+ HashMap<Target,Vector<String>> ipmiAttr = new HashMap<Target,Vector<String>>();
+ for (SdrRecord sdr : sdrs){
+ Target t = sdr.getTarget();
+ Vector<String> ipmiSensors = ipmiAttr.get(t);
+ if (ipmiSensors==null) {
+ ipmiSensors = new Vector<String>();
+ ipmiAttr.put(t, ipmiSensors);
+ }
+ ipmiSensors.add(String.format("0x%02x", sdr.getEntityId())+","+
+ String.format("0x%02x", sdr.getSensorId()));
+
+ //System.out.println(t.getName()+","+ipmiSensors);
+ }
+ for (Map.Entry<Target, Vector<String>> entry : ipmiAttr.entrySet()) {
+ Target t=entry.getKey();
+ String ipmiStr = "";
+ Vector<String> attrs = entry.getValue();
+ for (String a : attrs) {
+ ipmiStr = ipmiStr+a+",";
+ }
+ for (int i=attrs.size();i<16;i++) {
+ ipmiStr = ipmiStr+"0xFF,0xFF,";
+ }
+ //t.setAttributeValue("IPMI_SENSORS", ipmiStr);
+
+ }*/
+ }
+
+ public Target getTargetModel(String type) {
+ return model.getTargetModel(type);
+ }
+ public void setView(MainDialog view) {
+ this.view = view;
+ }
+
+ public void setModel(SystemModel model) {
+ this.model = model;
+ }
+
+ public Vector<String> getEnums(String e) {
+ if (model.enumerations.get(e)==null) {
+ ServerWizard2.LOGGER.severe("Enum not found: "+e);
+ return null;
+ }
+ return model.enumerations.get(e).enumList;
+ }
+ public Boolean isEnum(String e) {
+ if (model.enumerations.get(e)==null) {
+ return false;
+ }
+ return true;
+ }
+
+
+ public void deleteTarget(Target target) {
+ //model.deleteTarget(target, model.rootTarget);
+ model.deleteTarget(target);
+ }
+
+ public void addTargetInstance(Target targetModel, Target parentTarget,
+ TreeItem parentItem,String nameOverride) {
+
+ Target targetInstance;
+ Target instanceCheck = model.getTargetInstance(targetModel.getType());
+ if (instanceCheck!=null) {
+ //target instance found of this model type
+ targetInstance = new Target(instanceCheck);
+ targetInstance.copyChildren(instanceCheck);
+ } else {
+ targetInstance = new Target(targetModel);
+ }
+ targetInstance.setName(nameOverride);
+ model.updateTargetPosition(targetInstance, parentTarget, -1);
+ try {
+ model.addTarget(parentTarget, targetInstance);
+ view.updateInstanceTree(targetInstance, parentItem);
+ } catch (Exception e) {
+ MessageDialog.openError(null, "Add Target Error", e.getMessage());
+ }
+ }
+ public Target copyTargetInstance(Target target, Target parentTarget,Boolean incrementPosition) {
+ Target newTarget = new Target(target);
+ if (incrementPosition) {
+ newTarget.setPosition(newTarget.getPosition()+1);
+ newTarget.setSpecialAttributes();
+ }
+ try {
+ model.addTarget(parentTarget, newTarget);
+ newTarget.copyChildren(target);
+ } catch (Exception e) {
+ MessageDialog.openError(null, "Add Target Error", e.getMessage());
+ newTarget=null;
+ }
+ return newTarget;
+ }
+ public void deleteConnection(Target target,Target busTarget,Connection conn) {
+ target.deleteConnection(busTarget,conn);
+ }
+ public Vector<Target> getRootTargets() {
+ return model.rootTargets;
+ }
+
+ public void writeXML(String filename) {
+ try {
+ String tmpFilename=filename+".tmp";
+ model.writeXML(tmpFilename);
+ File from = new File(tmpFilename);
+ File to = new File(filename);
+ Files.copy( from.toPath(), to.toPath(),StandardCopyOption.REPLACE_EXISTING );
+ Files.delete(from.toPath());
+ ServerWizard2.LOGGER.info(filename + " Saved");
+ } catch (Exception exc) {
+ MessageDialog.openError(null, "Error", exc.getMessage());
+ exc.printStackTrace();
+ }
+ }
+
+ public void readXML(String filename) {
+ try {
+ model.readXML(filename);
+ } catch (Exception e) {
+ MessageDialog.openError(null, "Error", e.getMessage());
+ e.printStackTrace();
+ }
+ }
+ public Vector<Target> getConnectionCapableTargets() {
+ return model.getConnectionCapableTargets();
+ }
+ public void setGlobalSetting(String path,String attribute,String value) {
+ model.setGlobalSetting(path, attribute, value);
+ }
+ public Field getGlobalSetting(String path,String attribute) {
+ return model.getGlobalSetting(path, attribute);
+ }
+ public HashMap<String,Field> getGlobalSettings(String path) {
+ return model.getGlobalSettings(path);
+ }
+ public Vector<Target> getChildTargets(Target target) {
+ //if (target.instanceModel) {
+ // return model.getChildTargetTypes("");
+ //}
+ return model.getChildTargetTypes(target.getType());
+ }
+
+ public void hideBusses(Target target) {
+ target.hideBusses(model.getTargetLookup());
+ }
+ public Vector<Target> getVisibleChildren(Target target) {
+ Vector<Target> children = new Vector<Target>();
+ for (String c : target.getChildren()) {
+ Target t = model.getTarget(c);
+ if (t==null) {
+ String msg="Invalid Child target id: "+c;
+ ServerWizard2.LOGGER.severe(msg);
+ }
+ children.add(t);
+ }
+ return children;
+ }
+
+ public void initBusses(Target target) {
+ model.initBusses(target);
+ }
+ public Vector<Target> getBusTypes() {
+ return model.getBusTypes();
+ }
+ public void runChecks(String filename) {
+ String includePath = LibraryManager.getWorkingDir()+"scripts";
+ String script = LibraryManager.getWorkingDir()+"scripts"+System.getProperty("file.separator")+"processMrw.pl";
+
+ String commandLine[] = {
+ "perl",
+ "-I",
+ includePath,
+ script,
+ "-x",
+ filename,
+ "-f"
+ };
+ String commandLineStr="";
+ for (int i=0;i<commandLine.length;i++) {
+ commandLineStr=commandLineStr+commandLine[i]+" ";
+ }
+ ServerWizard2.LOGGER.info("Running: "+commandLineStr);
+ String line;
+ String msg="";
+ try {
+ Process proc = Runtime.getRuntime().exec(commandLine);
+ proc.waitFor();
+ InputStream error = proc.getErrorStream();
+ InputStream stdout = proc.getInputStream();
+ BufferedReader reader = new BufferedReader (new InputStreamReader(error));
+ BufferedReader reader2 = new BufferedReader (new InputStreamReader(stdout));
+ while ((line = reader.readLine ()) != null) {
+ msg=msg+"ERROR: " + line;
+ ServerWizard2.LOGGER.severe("ERROR: " + line);
+ }
+ while ((line = reader2.readLine ()) != null) {
+ msg=msg+line+"\n";
+ ServerWizard2.LOGGER.info(line);
+ }
+ LogViewerDialog dlg = new LogViewerDialog(null);
+ dlg.setData(msg);
+ dlg.open();
+ } catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ public void propertyChange(PropertyChangeEvent arg0) {
+ //view.setDirtyState(true);
+ }
+} \ No newline at end of file
diff --git a/src/com/ibm/ServerWizard2/XmlHandler.java b/src/com/ibm/ServerWizard2/XmlHandler.java
new file mode 100644
index 0000000..c2c0743
--- /dev/null
+++ b/src/com/ibm/ServerWizard2/XmlHandler.java
@@ -0,0 +1,39 @@
+package com.ibm.ServerWizard2;
+
+import java.util.ArrayList;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class XmlHandler extends DefaultHandler {
+ protected boolean validationError = false;
+ protected SAXParseException saxParseException = null;
+ protected ArrayList<String> warnings = new ArrayList<String>();
+
+ protected String detailedErrorString = "";
+
+ public void error(SAXParseException exception) throws SAXException {
+ detailedErrorString += "Line:" + exception.getLineNumber() + " , Col:" + exception.getColumnNumber() + ", Error:" + exception.getMessage() + "\n";
+ validationError = true;
+ saxParseException = exception;
+ }
+
+ public void fatalError(SAXParseException exception) throws SAXException {
+ detailedErrorString += "Line:" + exception.getLineNumber() + " , Col:" + exception.getColumnNumber() + ", Error:" + exception.getMessage() + "\n";
+ validationError = true;
+ saxParseException = exception;
+ }
+
+ public void warning(SAXParseException exception) throws SAXException {
+ warnings.add(exception.getMessage());
+ }
+
+ public String getDetailedErrorString(){
+ return detailedErrorString;
+ }
+
+ public ArrayList<String> getWarnings(){
+ return warnings;
+ }
+} \ No newline at end of file
diff --git a/src/manifest.txt b/src/manifest.txt
new file mode 100644
index 0000000..291b053
--- /dev/null
+++ b/src/manifest.txt
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path: lib/swt.jar
+Main-Class: ServerWizard2
diff --git a/src/org/eclipse/wb/swt/SWTResourceManager.java b/src/org/eclipse/wb/swt/SWTResourceManager.java
new file mode 100644
index 0000000..d8a2858
--- /dev/null
+++ b/src/org/eclipse/wb/swt/SWTResourceManager.java
@@ -0,0 +1,447 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Google, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Google, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wb.swt;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc.
+ * <p>
+ * !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the
+ * operating system resources managed by cached objects when those objects and OS resources are no longer
+ * needed (e.g. on application shutdown)
+ * <p>
+ * This class may be freely distributed as part of any application or plugin.
+ * <p>
+ * @author scheglov_ke
+ * @author Dan Rubel
+ */
+public class SWTResourceManager {
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Color
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>();
+ /**
+ * Returns the system {@link Color} matching the specific ID.
+ *
+ * @param systemColorID
+ * the ID value for the color
+ * @return the system {@link Color} matching the specific ID
+ */
+ public static Color getColor(int systemColorID) {
+ Display display = Display.getCurrent();
+ return display.getSystemColor(systemColorID);
+ }
+ /**
+ * Returns a {@link Color} given its red, green and blue component values.
+ *
+ * @param r
+ * the red component of the color
+ * @param g
+ * the green component of the color
+ * @param b
+ * the blue component of the color
+ * @return the {@link Color} matching the given red, green and blue component values
+ */
+ public static Color getColor(int r, int g, int b) {
+ return getColor(new RGB(r, g, b));
+ }
+ /**
+ * Returns a {@link Color} given its RGB value.
+ *
+ * @param rgb
+ * the {@link RGB} value of the color
+ * @return the {@link Color} matching the RGB value
+ */
+ public static Color getColor(RGB rgb) {
+ Color color = m_colorMap.get(rgb);
+ if (color == null) {
+ Display display = Display.getCurrent();
+ color = new Color(display, rgb);
+ m_colorMap.put(rgb, color);
+ }
+ return color;
+ }
+ /**
+ * Dispose of all the cached {@link Color}'s.
+ */
+ public static void disposeColors() {
+ for (Color color : m_colorMap.values()) {
+ color.dispose();
+ }
+ m_colorMap.clear();
+ }
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Image
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Maps image paths to images.
+ */
+ private static Map<String, Image> m_imageMap = new HashMap<String, Image>();
+ /**
+ * Returns an {@link Image} encoded by the specified {@link InputStream}.
+ *
+ * @param stream
+ * the {@link InputStream} encoding the image data
+ * @return the {@link Image} encoded by the specified input stream
+ */
+ protected static Image getImage(InputStream stream) throws IOException {
+ try {
+ Display display = Display.getCurrent();
+ ImageData data = new ImageData(stream);
+ if (data.transparentPixel > 0) {
+ return new Image(display, data, data.getTransparencyMask());
+ }
+ return new Image(display, data);
+ } finally {
+ stream.close();
+ }
+ }
+ /**
+ * Returns an {@link Image} stored in the file at the specified path.
+ *
+ * @param path
+ * the path to the image file
+ * @return the {@link Image} stored in the file at the specified path
+ */
+ public static Image getImage(String path) {
+ Image image = m_imageMap.get(path);
+ if (image == null) {
+ try {
+ image = getImage(new FileInputStream(path));
+ m_imageMap.put(path, image);
+ } catch (Exception e) {
+ image = getMissingImage();
+ m_imageMap.put(path, image);
+ }
+ }
+ return image;
+ }
+ /**
+ * Returns an {@link Image} stored in the file at the specified path relative to the specified class.
+ *
+ * @param clazz
+ * the {@link Class} relative to which to find the image
+ * @param path
+ * the path to the image file, if starts with <code>'/'</code>
+ * @return the {@link Image} stored in the file at the specified path
+ */
+ public static Image getImage(Class<?> clazz, String path) {
+ String key = clazz.getName() + '|' + path;
+ Image image = m_imageMap.get(key);
+ if (image == null) {
+ try {
+ image = getImage(clazz.getResourceAsStream(path));
+ m_imageMap.put(key, image);
+ } catch (Exception e) {
+ image = getMissingImage();
+ m_imageMap.put(key, image);
+ }
+ }
+ return image;
+ }
+ private static final int MISSING_IMAGE_SIZE = 10;
+ /**
+ * @return the small {@link Image} that can be used as placeholder for missing image.
+ */
+ private static Image getMissingImage() {
+ Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
+ //
+ GC gc = new GC(image);
+ gc.setBackground(getColor(SWT.COLOR_RED));
+ gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
+ gc.dispose();
+ //
+ return image;
+ }
+ /**
+ * Style constant for placing decorator image in top left corner of base image.
+ */
+ public static final int TOP_LEFT = 1;
+ /**
+ * Style constant for placing decorator image in top right corner of base image.
+ */
+ public static final int TOP_RIGHT = 2;
+ /**
+ * Style constant for placing decorator image in bottom left corner of base image.
+ */
+ public static final int BOTTOM_LEFT = 3;
+ /**
+ * Style constant for placing decorator image in bottom right corner of base image.
+ */
+ public static final int BOTTOM_RIGHT = 4;
+ /**
+ * Internal value.
+ */
+ protected static final int LAST_CORNER_KEY = 5;
+ /**
+ * Maps images to decorated images.
+ */
+ @SuppressWarnings("unchecked")
+ private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];
+ /**
+ * Returns an {@link Image} composed of a base image decorated by another image.
+ *
+ * @param baseImage
+ * the base {@link Image} that should be decorated
+ * @param decorator
+ * the {@link Image} to decorate the base image
+ * @return {@link Image} The resulting decorated image
+ */
+ public static Image decorateImage(Image baseImage, Image decorator) {
+ return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
+ }
+ /**
+ * Returns an {@link Image} composed of a base image decorated by another image.
+ *
+ * @param baseImage
+ * the base {@link Image} that should be decorated
+ * @param decorator
+ * the {@link Image} to decorate the base image
+ * @param corner
+ * the corner to place decorator image
+ * @return the resulting decorated {@link Image}
+ */
+ public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
+ if (corner <= 0 || corner >= LAST_CORNER_KEY) {
+ throw new IllegalArgumentException("Wrong decorate corner");
+ }
+ Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner];
+ if (cornerDecoratedImageMap == null) {
+ cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>();
+ m_decoratedImageMap[corner] = cornerDecoratedImageMap;
+ }
+ Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage);
+ if (decoratedMap == null) {
+ decoratedMap = new HashMap<Image, Image>();
+ cornerDecoratedImageMap.put(baseImage, decoratedMap);
+ }
+ //
+ Image result = decoratedMap.get(decorator);
+ if (result == null) {
+ Rectangle bib = baseImage.getBounds();
+ Rectangle dib = decorator.getBounds();
+ //
+ result = new Image(Display.getCurrent(), bib.width, bib.height);
+ //
+ GC gc = new GC(result);
+ gc.drawImage(baseImage, 0, 0);
+ if (corner == TOP_LEFT) {
+ gc.drawImage(decorator, 0, 0);
+ } else if (corner == TOP_RIGHT) {
+ gc.drawImage(decorator, bib.width - dib.width, 0);
+ } else if (corner == BOTTOM_LEFT) {
+ gc.drawImage(decorator, 0, bib.height - dib.height);
+ } else if (corner == BOTTOM_RIGHT) {
+ gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height);
+ }
+ gc.dispose();
+ //
+ decoratedMap.put(decorator, result);
+ }
+ return result;
+ }
+ /**
+ * Dispose all of the cached {@link Image}'s.
+ */
+ public static void disposeImages() {
+ // dispose loaded images
+ {
+ for (Image image : m_imageMap.values()) {
+ image.dispose();
+ }
+ m_imageMap.clear();
+ }
+ // dispose decorated images
+ for (int i = 0; i < m_decoratedImageMap.length; i++) {
+ Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i];
+ if (cornerDecoratedImageMap != null) {
+ for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) {
+ for (Image image : decoratedMap.values()) {
+ image.dispose();
+ }
+ decoratedMap.clear();
+ }
+ cornerDecoratedImageMap.clear();
+ }
+ }
+ }
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Font
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Maps font names to fonts.
+ */
+ private static Map<String, Font> m_fontMap = new HashMap<String, Font>();
+ /**
+ * Maps fonts to their bold versions.
+ */
+ private static Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>();
+ /**
+ * Returns a {@link Font} based on its name, height and style.
+ *
+ * @param name
+ * the name of the font
+ * @param height
+ * the height of the font
+ * @param style
+ * the style of the font
+ * @return {@link Font} The font matching the name, height and style
+ */
+ public static Font getFont(String name, int height, int style) {
+ return getFont(name, height, style, false, false);
+ }
+ /**
+ * Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline
+ * flags are also supported.
+ *
+ * @param name
+ * the name of the font
+ * @param size
+ * the size of the font
+ * @param style
+ * the style of the font
+ * @param strikeout
+ * the strikeout flag (warning: Windows only)
+ * @param underline
+ * the underline flag (warning: Windows only)
+ * @return {@link Font} The font matching the name, height, style, strikeout and underline
+ */
+ public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
+ String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
+ Font font = m_fontMap.get(fontName);
+ if (font == null) {
+ FontData fontData = new FontData(name, size, style);
+ if (strikeout || underline) {
+ try {
+ Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$
+ Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$
+ if (logFont != null && logFontClass != null) {
+ if (strikeout) {
+ logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
+ }
+ if (underline) {
+ logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
+ }
+ }
+ } catch (Throwable e) {
+ System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ font = new Font(Display.getCurrent(), fontData);
+ m_fontMap.put(fontName, font);
+ }
+ return font;
+ }
+ /**
+ * Returns a bold version of the given {@link Font}.
+ *
+ * @param baseFont
+ * the {@link Font} for which a bold version is desired
+ * @return the bold version of the given {@link Font}
+ */
+ public static Font getBoldFont(Font baseFont) {
+ Font font = m_fontToBoldFontMap.get(baseFont);
+ if (font == null) {
+ FontData fontDatas[] = baseFont.getFontData();
+ FontData data = fontDatas[0];
+ font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
+ m_fontToBoldFontMap.put(baseFont, font);
+ }
+ return font;
+ }
+ /**
+ * Dispose all of the cached {@link Font}'s.
+ */
+ public static void disposeFonts() {
+ // clear fonts
+ for (Font font : m_fontMap.values()) {
+ font.dispose();
+ }
+ m_fontMap.clear();
+ // clear bold fonts
+ for (Font font : m_fontToBoldFontMap.values()) {
+ font.dispose();
+ }
+ m_fontToBoldFontMap.clear();
+ }
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Cursor
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Maps IDs to cursors.
+ */
+ private static Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>();
+ /**
+ * Returns the system cursor matching the specific ID.
+ *
+ * @param id
+ * int The ID value for the cursor
+ * @return Cursor The system cursor matching the specific ID
+ */
+ public static Cursor getCursor(int id) {
+ Integer key = Integer.valueOf(id);
+ Cursor cursor = m_idToCursorMap.get(key);
+ if (cursor == null) {
+ cursor = new Cursor(Display.getDefault(), id);
+ m_idToCursorMap.put(key, cursor);
+ }
+ return cursor;
+ }
+ /**
+ * Dispose all of the cached cursors.
+ */
+ public static void disposeCursors() {
+ for (Cursor cursor : m_idToCursorMap.values()) {
+ cursor.dispose();
+ }
+ m_idToCursorMap.clear();
+ }
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // General
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Dispose of cached objects and their underlying OS resources. This should only be called when the cached
+ * objects are no longer needed (e.g. on application shutdown).
+ */
+ public static void dispose() {
+ disposeColors();
+ disposeImages();
+ disposeFonts();
+ disposeCursors();
+ }
+} \ No newline at end of file
OpenPOWER on IntegriCloud