Skip to content

Commit

Permalink
Added attribute filtering
Browse files Browse the repository at this point in the history
Processes serverwizShow tag and enables attribute filtering
Also fixes xml ordering dependency
  • Loading branch information
nkskjames committed Aug 25, 2017
1 parent 4f068e7 commit d32588b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/com/ibm/ServerWizard2/ServerWizard2.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ServerWizard2 {
*/
public final static Logger LOGGER = Logger.getLogger(ServerWizard2.class.getName());
public final static int VERSION_MAJOR = 2;
public final static int VERSION_MINOR = 2;
public final static int VERSION_MINOR = 10;

public final static String PROPERTIES_FILE = "serverwiz.preferences";
public static String GIT_LOCATION = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.TreeMap;
import java.util.Vector;

import org.apache.logging.log4j.Level;
Expand Down Expand Up @@ -41,6 +42,10 @@ public Boolean getModelCreationMode() {
return this.modelCreationMode;
}

public TreeMap<String,Boolean> getAttributeFilters() {
return model.getAttributeFilters();
}

public void init() {
try {
String libraryLocation = ServerWizard2.GIT_LOCATION + File.separator + this.LIBRARY_NAME;
Expand Down Expand Up @@ -81,8 +86,8 @@ public void setModel(SystemModel model) {
public void deleteTarget(Target target) {
model.deleteTarget(target);
}
public Vector<Field> getAttributesAndGlobals(Target targetInstance, String path) {
return model.getAttributesAndGlobals(targetInstance, path, !this.modelCreationMode);
public Vector<Field> getAttributesAndGlobals(Target targetInstance, String path, String filter) {
return model.getAttributesAndGlobals(targetInstance, path, !this.modelCreationMode, filter);
}

public void addTargetInstance(Target targetModel, Target parentTarget,
Expand Down
9 changes: 5 additions & 4 deletions src/com/ibm/ServerWizard2/model/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

public class Attribute implements java.io.Serializable {
private static final long serialVersionUID = 1L;
public String show = "";
public String name = "";
public String group = "";
public AttributeValue value;
Expand All @@ -31,6 +32,7 @@ public Attribute() {

public Attribute(Attribute a) {
this.name = a.name;
this.show = a.show;
this.desc = a.desc;
this.group = a.group;
this.persistency = a.persistency;
Expand Down Expand Up @@ -123,12 +125,11 @@ public void readModelXML(Element attribute) {
if (SystemModel.isElementDefined(attribute,"writeable")) {
writeable=true;
}
if (SystemModel.isElementDefined(attribute,"serverwizHide") ||
name.equals("MODEL") || name.equals("TYPE") || name.equals("CLASS")) {
if (name.equals("MODEL") || name.equals("TYPE") || name.equals("CLASS")) {
hide=true;
}
if (SystemModel.isElementDefined(attribute,"serverwizReadonly")) {
readonly=true;
if (SystemModel.isElementDefined(attribute,"serverwizShow")) {
show = SystemModel.getElement(attribute, "serverwizShow");
}
Node simpleType = attribute.getElementsByTagName("simpleType").item(0);
if (simpleType!=null) {
Expand Down
28 changes: 19 additions & 9 deletions src/com/ibm/ServerWizard2/model/SystemModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class SystemModel {
private HashMap<String, Attribute> attributes = new HashMap<String, Attribute>();
private TreeMap<String, Vector<String>> attributeGroups = new TreeMap<String, Vector<String>>();
private TreeMap<String, Errata> errata = new TreeMap<String, Errata>();
private TreeMap<String, Boolean> attributeFilters = new TreeMap<String, Boolean>();

// List of targets in current system
private Vector<Target> targetList = new Vector<Target>();
Expand All @@ -68,7 +69,11 @@ public class SystemModel {
public Vector<Target> getBusTypes() {
return busTypes;
}
public TreeMap<String,Boolean> getAttributeFilters() {
return this.attributeFilters;
}


public Target getTarget(String t) {
return targetLookup.get(t);
}
Expand Down Expand Up @@ -525,11 +530,11 @@ private void readErrata(Element setting) {
* Returns a vector of attributes located in the target and global settings
* associated with a particular target instance
*/
public Vector<Field> getAttributesAndGlobals(Target targetInstance, String path, Boolean showGlobalSettings) {
public Vector<Field> getAttributesAndGlobals(Target targetInstance, String path, Boolean showGlobalSettings, String filter) {
Vector<Field> attributes = new Vector<Field>();
for (Map.Entry<String, Attribute> entry : targetInstance.getAttributes().entrySet()) {
Attribute attribute = entry.getValue();
if (!attribute.isHidden()) {
if (attribute.show.equals(filter) || filter.isEmpty()) {
if (attribute.isGlobal() && showGlobalSettings) {
if (!path.isEmpty()) {
Field field = getGlobalSetting(path, attribute.name);
Expand Down Expand Up @@ -666,10 +671,12 @@ public void loadAttributes(String fileName) throws SAXException,
}
grp.add(a.name);
}

if (a.getValue().getType().equals("enumeration")) {
a.getValue().setEnumerator(enumerations.get(a.value.getFields().get(0).name));
}
if (!a.show.isEmpty()) {
this.attributeFilters.put(a.show,true);
}
}
}

Expand Down Expand Up @@ -841,13 +848,16 @@ public void deleteTarget(Target deleteTarget) {
/////////////////////////////////////////////////////////////////
// Utility static methods
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 "";
NodeList nl = a.getChildNodes();
for (int i=0;i<nl.getLength();i++){
Node n = nl.item(i);
if (n.getNodeName().equals(e)) {
Node cn = n.getChildNodes().item(0);
if (cn == null) {
return "";
}
return cn.getNodeValue();
}
return cn.getNodeValue();
}
return "";
}
Expand Down
22 changes: 15 additions & 7 deletions src/com/ibm/ServerWizard2/model/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,26 @@ public void readModelXML(Element target, HashMap<String, Attribute> attrMap) {
parentType.add(e.getChildNodes().item(0).getNodeValue());
}
NodeList attributeList = target.getElementsByTagName("attribute");
boolean aerror = false;
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 + ")");
aerror = true;
System.out.println("Invalid attribute id: " + attrId + "(" + type + ")");
} else {
Attribute a = new Attribute(attributeLookup);
if (a.value==null) {
aerror = true;
System.out.println("Unknown attribute value type: " + attrId + "(" + type + ")");
} else {
attributes.put(a.name, a);
a.value.readInstanceXML((Element) attributeList.item(i));
}
}
attributes.put(a.name, a);
a.value.readInstanceXML((Element) attributeList.item(i));
}
if (aerror == true) {
throw new NullPointerException("Attribute import error");
}
}

Expand Down
37 changes: 34 additions & 3 deletions src/com/ibm/ServerWizard2/view/MainDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ public class MainDialog extends Dialog {
private Composite compositeDir;
private Button btnHideBusses;
private Button btnShowHidden;
private Combo showFilter;

private AttributeEditingSupport attributeEditor;
private Label label;
private Label label_1;
private Composite composite_1;
/**
* Create the dialog.
*
Expand Down Expand Up @@ -206,13 +208,23 @@ protected Control createDialogArea(Composite parent) {
+ "Select and Instance type. You can optionally enter a custom name. Then click 'Add Instance' button.");

columnName.setResizable(true);

composite_1 = new Composite(sashForm_1, SWT.NONE);

showFilter = new Combo(composite_1, SWT.READ_ONLY);
showFilter.setFont(SWTResourceManager.getFont("Arial", 9, SWT.READ_ONLY));
showFilter.setBounds(118, 0, 336, 23);

Label lblAttributeFilter = new Label(composite_1, SWT.NONE);
lblAttributeFilter.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
lblAttributeFilter.setBounds(15, 3, 97, 15);
lblAttributeFilter.setText("Attribute Filter:");

// 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
Expand Down Expand Up @@ -374,6 +386,14 @@ protected Control createDialogArea(Composite parent) {
this.initInstanceMode();
sashForm.setWeights(new int[] { 1, 1 });
columnName.pack();
sashForm_1.setWeights(new int[] {302, 37, 171});

showFilter.removeAll();
showFilter.add("");
for (String a : controller.getAttributeFilters().keySet()) {
showFilter.add(a);
}


return container;
}
Expand Down Expand Up @@ -693,7 +713,12 @@ private void updateView() {
//A target is selected so show the associated attributes
TreeItem item = tree.getSelection()[0];
ConnectionEndpoint ep = this.getEndpoint(item, null);
attributes = controller.getAttributesAndGlobals(targetInstance, "/"+ep.getName());
int s = showFilter.getSelectionIndex();
String show = "";
if (s>-1) {
show = showFilter.getItem(s);
}
attributes = controller.getAttributesAndGlobals(targetInstance, "/"+ep.getName(),show);
viewer.setInput(attributes);
viewer.refresh();

Expand Down Expand Up @@ -1077,6 +1102,12 @@ public void setFilename(String filename) {
}

private void addEvents() {
showFilter.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
updateView();
}
});
btnShowHidden.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
Expand Down Expand Up @@ -1212,7 +1243,7 @@ public void widgetSelected(SelectionEvent arg0) {
public void widgetSelected(SelectionEvent arg0) {
if (listBusses.getSelectionCount() > 0) {
Connection conn = (Connection) listBusses.getData(listBusses.getSelection()[0]);
attributes = controller.getAttributesAndGlobals(conn.busTarget, "");
attributes = controller.getAttributesAndGlobals(conn.busTarget, "","");
viewer.setInput(attributes);
viewer.refresh();
}
Expand Down

0 comments on commit d32588b

Please sign in to comment.