Skip to content

Commit d32588b

Browse files
committed
Added attribute filtering
Processes serverwizShow tag and enables attribute filtering Also fixes xml ordering dependency
1 parent 4f068e7 commit d32588b

File tree

6 files changed

+81
-26
lines changed

6 files changed

+81
-26
lines changed

src/com/ibm/ServerWizard2/ServerWizard2.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ServerWizard2 {
2323
*/
2424
public final static Logger LOGGER = Logger.getLogger(ServerWizard2.class.getName());
2525
public final static int VERSION_MAJOR = 2;
26-
public final static int VERSION_MINOR = 2;
26+
public final static int VERSION_MINOR = 10;
2727

2828
public final static String PROPERTIES_FILE = "serverwiz.preferences";
2929
public static String GIT_LOCATION = "";

src/com/ibm/ServerWizard2/controller/TargetWizardController.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.StringWriter;
77
import java.nio.file.Files;
88
import java.nio.file.StandardCopyOption;
9+
import java.util.TreeMap;
910
import java.util.Vector;
1011

1112
import org.apache.logging.log4j.Level;
@@ -41,6 +42,10 @@ public Boolean getModelCreationMode() {
4142
return this.modelCreationMode;
4243
}
4344

45+
public TreeMap<String,Boolean> getAttributeFilters() {
46+
return model.getAttributeFilters();
47+
}
48+
4449
public void init() {
4550
try {
4651
String libraryLocation = ServerWizard2.GIT_LOCATION + File.separator + this.LIBRARY_NAME;
@@ -81,8 +86,8 @@ public void setModel(SystemModel model) {
8186
public void deleteTarget(Target target) {
8287
model.deleteTarget(target);
8388
}
84-
public Vector<Field> getAttributesAndGlobals(Target targetInstance, String path) {
85-
return model.getAttributesAndGlobals(targetInstance, path, !this.modelCreationMode);
89+
public Vector<Field> getAttributesAndGlobals(Target targetInstance, String path, String filter) {
90+
return model.getAttributesAndGlobals(targetInstance, path, !this.modelCreationMode, filter);
8691
}
8792

8893
public void addTargetInstance(Target targetModel, Target parentTarget,

src/com/ibm/ServerWizard2/model/Attribute.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
public class Attribute implements java.io.Serializable {
99
private static final long serialVersionUID = 1L;
10+
public String show = "";
1011
public String name = "";
1112
public String group = "";
1213
public AttributeValue value;
@@ -31,6 +32,7 @@ public Attribute() {
3132

3233
public Attribute(Attribute a) {
3334
this.name = a.name;
35+
this.show = a.show;
3436
this.desc = a.desc;
3537
this.group = a.group;
3638
this.persistency = a.persistency;
@@ -123,12 +125,11 @@ public void readModelXML(Element attribute) {
123125
if (SystemModel.isElementDefined(attribute,"writeable")) {
124126
writeable=true;
125127
}
126-
if (SystemModel.isElementDefined(attribute,"serverwizHide") ||
127-
name.equals("MODEL") || name.equals("TYPE") || name.equals("CLASS")) {
128+
if (name.equals("MODEL") || name.equals("TYPE") || name.equals("CLASS")) {
128129
hide=true;
129130
}
130-
if (SystemModel.isElementDefined(attribute,"serverwizReadonly")) {
131-
readonly=true;
131+
if (SystemModel.isElementDefined(attribute,"serverwizShow")) {
132+
show = SystemModel.getElement(attribute, "serverwizShow");
132133
}
133134
Node simpleType = attribute.getElementsByTagName("simpleType").item(0);
134135
if (simpleType!=null) {

src/com/ibm/ServerWizard2/model/SystemModel.java

+19-9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class SystemModel {
4848
private HashMap<String, Attribute> attributes = new HashMap<String, Attribute>();
4949
private TreeMap<String, Vector<String>> attributeGroups = new TreeMap<String, Vector<String>>();
5050
private TreeMap<String, Errata> errata = new TreeMap<String, Errata>();
51+
private TreeMap<String, Boolean> attributeFilters = new TreeMap<String, Boolean>();
5152

5253
// List of targets in current system
5354
private Vector<Target> targetList = new Vector<Target>();
@@ -68,7 +69,11 @@ public class SystemModel {
6869
public Vector<Target> getBusTypes() {
6970
return busTypes;
7071
}
72+
public TreeMap<String,Boolean> getAttributeFilters() {
73+
return this.attributeFilters;
74+
}
7175

76+
7277
public Target getTarget(String t) {
7378
return targetLookup.get(t);
7479
}
@@ -525,11 +530,11 @@ private void readErrata(Element setting) {
525530
* Returns a vector of attributes located in the target and global settings
526531
* associated with a particular target instance
527532
*/
528-
public Vector<Field> getAttributesAndGlobals(Target targetInstance, String path, Boolean showGlobalSettings) {
533+
public Vector<Field> getAttributesAndGlobals(Target targetInstance, String path, Boolean showGlobalSettings, String filter) {
529534
Vector<Field> attributes = new Vector<Field>();
530535
for (Map.Entry<String, Attribute> entry : targetInstance.getAttributes().entrySet()) {
531536
Attribute attribute = entry.getValue();
532-
if (!attribute.isHidden()) {
537+
if (attribute.show.equals(filter) || filter.isEmpty()) {
533538
if (attribute.isGlobal() && showGlobalSettings) {
534539
if (!path.isEmpty()) {
535540
Field field = getGlobalSetting(path, attribute.name);
@@ -666,10 +671,12 @@ public void loadAttributes(String fileName) throws SAXException,
666671
}
667672
grp.add(a.name);
668673
}
669-
670674
if (a.getValue().getType().equals("enumeration")) {
671675
a.getValue().setEnumerator(enumerations.get(a.value.getFields().get(0).name));
672676
}
677+
if (!a.show.isEmpty()) {
678+
this.attributeFilters.put(a.show,true);
679+
}
673680
}
674681
}
675682

@@ -841,13 +848,16 @@ public void deleteTarget(Target deleteTarget) {
841848
/////////////////////////////////////////////////////////////////
842849
// Utility static methods
843850
public static String getElement(Element a, String e) {
844-
Node n = a.getElementsByTagName(e).item(0);
845-
if (n != null) {
846-
Node cn = n.getChildNodes().item(0);
847-
if (cn == null) {
848-
return "";
851+
NodeList nl = a.getChildNodes();
852+
for (int i=0;i<nl.getLength();i++){
853+
Node n = nl.item(i);
854+
if (n.getNodeName().equals(e)) {
855+
Node cn = n.getChildNodes().item(0);
856+
if (cn == null) {
857+
return "";
858+
}
859+
return cn.getNodeValue();
849860
}
850-
return cn.getNodeValue();
851861
}
852862
return "";
853863
}

src/com/ibm/ServerWizard2/model/Target.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,26 @@ public void readModelXML(Element target, HashMap<String, Attribute> attrMap) {
350350
parentType.add(e.getChildNodes().item(0).getNodeValue());
351351
}
352352
NodeList attributeList = target.getElementsByTagName("attribute");
353+
boolean aerror = false;
353354
for (int i = 0; i < attributeList.getLength(); ++i) {
354355
String attrId = SystemModel.getElement((Element) attributeList.item(i), "id");
355356
Attribute attributeLookup = attrMap.get(attrId);
356357
if (attributeLookup == null) {
357-
throw new NullPointerException("Invalid attribute id: " + attrId + "(" + type + ")");
358-
}
359-
Attribute a = new Attribute(attributeLookup);
360-
if (a.value==null) {
361-
throw new NullPointerException("Unknown attribute value type: " + attrId + "(" + type + ")");
358+
aerror = true;
359+
System.out.println("Invalid attribute id: " + attrId + "(" + type + ")");
360+
} else {
361+
Attribute a = new Attribute(attributeLookup);
362+
if (a.value==null) {
363+
aerror = true;
364+
System.out.println("Unknown attribute value type: " + attrId + "(" + type + ")");
365+
} else {
366+
attributes.put(a.name, a);
367+
a.value.readInstanceXML((Element) attributeList.item(i));
368+
}
362369
}
363-
attributes.put(a.name, a);
364-
a.value.readInstanceXML((Element) attributeList.item(i));
370+
}
371+
if (aerror == true) {
372+
throw new NullPointerException("Attribute import error");
365373
}
366374
}
367375

src/com/ibm/ServerWizard2/view/MainDialog.java

+34-3
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,12 @@ public class MainDialog extends Dialog {
114114
private Composite compositeDir;
115115
private Button btnHideBusses;
116116
private Button btnShowHidden;
117+
private Combo showFilter;
117118

118119
private AttributeEditingSupport attributeEditor;
119120
private Label label;
120121
private Label label_1;
122+
private Composite composite_1;
121123
/**
122124
* Create the dialog.
123125
*
@@ -206,13 +208,23 @@ protected Control createDialogArea(Composite parent) {
206208
+ "Select and Instance type. You can optionally enter a custom name. Then click 'Add Instance' button.");
207209

208210
columnName.setResizable(true);
211+
212+
composite_1 = new Composite(sashForm_1, SWT.NONE);
213+
214+
showFilter = new Combo(composite_1, SWT.READ_ONLY);
215+
showFilter.setFont(SWTResourceManager.getFont("Arial", 9, SWT.READ_ONLY));
216+
showFilter.setBounds(118, 0, 336, 23);
217+
218+
Label lblAttributeFilter = new Label(composite_1, SWT.NONE);
219+
lblAttributeFilter.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
220+
lblAttributeFilter.setBounds(15, 3, 97, 15);
221+
lblAttributeFilter.setText("Attribute Filter:");
209222

210223
// Create attribute table
211224
viewer = new TableViewer(sashForm_1, SWT.VIRTUAL | SWT.H_SCROLL | SWT.V_SCROLL
212225
| SWT.FULL_SELECTION | SWT.BORDER);
213226

214227
this.createAttributeTable();
215-
sashForm_1.setWeights(new int[] { 1, 1 });
216228

217229
// //////////////////////////////////////////////////////////
218230
// Tab folders
@@ -374,6 +386,14 @@ protected Control createDialogArea(Composite parent) {
374386
this.initInstanceMode();
375387
sashForm.setWeights(new int[] { 1, 1 });
376388
columnName.pack();
389+
sashForm_1.setWeights(new int[] {302, 37, 171});
390+
391+
showFilter.removeAll();
392+
showFilter.add("");
393+
for (String a : controller.getAttributeFilters().keySet()) {
394+
showFilter.add(a);
395+
}
396+
377397

378398
return container;
379399
}
@@ -693,7 +713,12 @@ private void updateView() {
693713
//A target is selected so show the associated attributes
694714
TreeItem item = tree.getSelection()[0];
695715
ConnectionEndpoint ep = this.getEndpoint(item, null);
696-
attributes = controller.getAttributesAndGlobals(targetInstance, "/"+ep.getName());
716+
int s = showFilter.getSelectionIndex();
717+
String show = "";
718+
if (s>-1) {
719+
show = showFilter.getItem(s);
720+
}
721+
attributes = controller.getAttributesAndGlobals(targetInstance, "/"+ep.getName(),show);
697722
viewer.setInput(attributes);
698723
viewer.refresh();
699724

@@ -1077,6 +1102,12 @@ public void setFilename(String filename) {
10771102
}
10781103

10791104
private void addEvents() {
1105+
showFilter.addSelectionListener(new SelectionAdapter() {
1106+
@Override
1107+
public void widgetSelected(SelectionEvent arg0) {
1108+
updateView();
1109+
}
1110+
});
10801111
btnShowHidden.addSelectionListener(new SelectionAdapter() {
10811112
@Override
10821113
public void widgetSelected(SelectionEvent arg0) {
@@ -1212,7 +1243,7 @@ public void widgetSelected(SelectionEvent arg0) {
12121243
public void widgetSelected(SelectionEvent arg0) {
12131244
if (listBusses.getSelectionCount() > 0) {
12141245
Connection conn = (Connection) listBusses.getData(listBusses.getSelection()[0]);
1215-
attributes = controller.getAttributesAndGlobals(conn.busTarget, "");
1246+
attributes = controller.getAttributesAndGlobals(conn.busTarget, "","");
12161247
viewer.setInput(attributes);
12171248
viewer.refresh();
12181249
}

0 commit comments

Comments
 (0)