Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to export cards #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/com/ibm/ServerWizard2/controller/TargetWizardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void addTargetInstance(Target targetModel, Target parentTarget,
// target instance found of this model type
targetInstance = new Target(instanceCheck);
targetInstance.copyChildren(instanceCheck);
targetInstance.copyBusses(instanceCheck);
} else {
targetInstance = new Target(targetModel);
}
Expand Down Expand Up @@ -157,6 +158,21 @@ public Target copyTargetInstance(Target target, Target parentTarget,
}
return newTarget;
}

public void exportAsPart(Target target, String fileName, Boolean defaultAttributes) {
try {
String tmpFilename = fileName + ".tmp";
model.writeXML(tmpFilename, target, defaultAttributes);
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 e) {
ServerwizMessageDialog.openError(null, "Export Part Error", e.getMessage());
}
}

public void deleteConnection(Target target, Target busTarget,
Connection conn) {
Expand Down
15 changes: 15 additions & 0 deletions src/com/ibm/ServerWizard2/model/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ public String getName() {
}
return source.getName()+seperator+dest.getName();
}
public Connection() {
// TODO Auto-generated constructor stub
}
public Connection(Connection other) {
id = other.id;
busType = other.busType;
source = new ConnectionEndpoint();
dest = new ConnectionEndpoint();
source.setTargetName(other.source.getTargetName());
source.setPath(other.source.getPath());
dest.setTargetName(other.dest.getTargetName());
dest.setPath(other.dest.getPath());
cabled = other.cabled;
busTarget = new Target(other.busTarget);
}
public void writeInstanceXML(Writer out) throws Exception {
out.write("\t<bus>\n");
out.write("\t\t<bus_id>"+getName()+"</bus_id>\n");
Expand Down
22 changes: 20 additions & 2 deletions src/com/ibm/ServerWizard2/model/SystemModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ public void writeXML(String filename, Boolean partsMode) throws Exception {
HashMap<String, Boolean> targetWritten = new HashMap<String, Boolean>();
for (Target target : targetList) {
if (partsMode) {
target.writeTargetXML(out, targetLookup, targetWritten);
target.writeTargetXML(out, targetLookup, targetWritten, false, false, null);
} else {
target.writeInstanceXML(out, targetLookup, targetWritten);
}
Expand All @@ -624,7 +624,25 @@ public void writeXML(String filename, Boolean partsMode) throws Exception {
out.write("</"+topTag+">\n");
out.close();
}


/*
* Write XML to a parts file (only the supplied target and it's children)
*/
public void writeXML(String filename, Target topTarget, Boolean defaultAttributes) throws Exception {
Writer out = new BufferedWriter(new FileWriter(filename));

out.write("<partInstance>\n");
out.write("<version>"+ServerWizard2.getVersionString()+"</version>\n");
out.write("<targetInstances>\n");
HashMap<String, Boolean> targetWritten = new HashMap<String, Boolean>();
topTarget.writeTargetXML(out, targetLookup, targetWritten, true, true,
defaultAttributes ? attributes : null);
out.write("</targetInstances>\n");
out.write("</partInstance>\n");
out.close();
}


/*
* Add a target instance to the model
*/
Expand Down
47 changes: 37 additions & 10 deletions src/com/ibm/ServerWizard2/model/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ public void copyChildren(Target t) {
this.childrenHidden.add(c);
}
}
public void copyBusses(Target t) {
for (Map.Entry<Target, Vector<Connection>> entry : t.busses.entrySet()) {
Target newTarget = new Target(entry.getKey());
Vector<Connection> newConns = new Vector<Connection>();
for (Connection conn : entry.getValue()) {
newConns.add(new Connection(conn));
}
busses.put(newTarget, newConns);
}
busInited = true;
}
public void removeChildren(String child) {
children.remove(child);
childrenHidden.remove(child);
Expand Down Expand Up @@ -234,7 +245,8 @@ public Boolean isOutput() {
public Boolean isSystem() {
return (this.getAttribute("CLASS").equals("SYS"));
}
Boolean isCard() {

public Boolean isCard() {
return (this.getAttribute("CLASS").equals("CARD") || this.getAttribute("CLASS").equals(
"MOTHERBOARD"));
}
Expand Down Expand Up @@ -527,27 +539,39 @@ public void readTargetXML(Element t, TreeMap<String, Target> targetModels, HashM
}
conn.busTarget = new Target(busTarget);
conn.readInstanceXML(bus);
busses.get(busTarget).add(conn);

if(busses.containsKey(busTarget)) {
busses.get(busTarget).add(conn);
} else {
Vector<Connection> conns = new Vector<Connection>();
conns.add(conn);
busses.put(busTarget, conns);
}
}
}
public void writeTargetXML(Writer out,HashMap<String,Target> targetLookup, HashMap<String,Boolean>targetWritten) throws Exception {
public void writeTargetXML(Writer out,HashMap<String,Target> targetLookup, HashMap<String,Boolean>targetWritten,
Boolean targetExport, Boolean forceRoot, HashMap<String, Attribute> attrMap) throws Exception {
if (targetWritten.containsKey(this.getName())) {
return;
}
targetWritten.put(this.getName(), true);
out.write("<targetPart>\n");
out.write("\t<id>" + this.getName() + "</id>\n");
out.write("\t<type>" + this.getType() + "</type>\n");
if(forceRoot) {
out.write("\t<type>" + this.getAttribute("CLASS").toLowerCase() + "-" + this.name + "</type>\n");
} else {
out.write("\t<type>" + this.getType() + "</type>\n");
}
String rootStr = "false";
if (this.isRoot()) { rootStr = "true"; }
if (this.isRoot() || forceRoot) { rootStr = "true"; }
out.write("\t<is_root>" + rootStr + "</is_root>\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");
out.write("\t<position>" + (forceRoot ? "-1" : getPosition()) + "</position>\n");
out.write("\t<parent>" + this.parent + "</parent>\n");
for (String p_type : this.parentType) {
out.write("\t<parent_type>" + p_type + "</parent_type>\n");
Expand All @@ -562,9 +586,12 @@ public void writeTargetXML(Writer out,HashMap<String,Target> targetLookup, HashM
}
//write attributes
for (Map.Entry<String, Attribute> entry : getAttributes().entrySet()) {
Attribute attr = new Attribute(entry.getValue());
attr.writeInstanceXML(out);

if(attrMap != null) {
attrMap.get(entry.getKey()).writeInstanceXML(out);
} else {
Attribute attr = new Attribute(entry.getValue());
attr.writeInstanceXML(out);
}
}
//write busses
for (Map.Entry<Target, Vector<Connection>> entry : busses.entrySet()) {
Expand All @@ -577,7 +604,7 @@ public void writeTargetXML(Writer out,HashMap<String,Target> targetLookup, HashM
//recursively write children
for (String childStr : this.getAllChildren()) {
Target child = targetLookup.get(childStr);
child.writeTargetXML(out, targetLookup, targetWritten);
child.writeTargetXML(out, targetLookup, targetWritten, targetExport, false, attrMap);
}
}
}
37 changes: 37 additions & 0 deletions src/com/ibm/ServerWizard2/view/MainDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class MainDialog extends Dialog {
// Buttons
private Button btnAddTarget;
private Button btnCopyInstance;
private Button btnExportPart;
private Button btnDefaults;
private Button btnDeleteTarget;
private Button btnSave;
Expand Down Expand Up @@ -287,6 +288,12 @@ protected Control createDialogArea(Composite parent) {
btnCopyInstance.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
btnCopyInstance.setEnabled(false);

btnExportPart = new Button(compositeInstance, SWT.NONE);
btnExportPart.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
btnExportPart.setText("Export Part");
btnExportPart.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
btnExportPart.setEnabled(false);

btnDefaults = new Button(compositeInstance, SWT.NONE);
btnDefaults.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
btnDefaults.setText("Restore Defaults");
Expand Down Expand Up @@ -714,6 +721,7 @@ private void updateView() {
btnAddTarget.setEnabled(false);
btnDeleteTarget.setEnabled(false);
btnCopyInstance.setEnabled(false);
btnExportPart.setEnabled(false);
btnDefaults.setEnabled(false);
updateChildCombo(null);
return;
Expand Down Expand Up @@ -743,6 +751,11 @@ private void updateView() {
} else {
btnCopyInstance.setEnabled(false);
}
if (targetInstance.isCard()) {
btnExportPart.setEnabled(true);
} else {
btnExportPart.setEnabled(false);
}
btnDefaults.setEnabled(true);
}

Expand Down Expand Up @@ -1211,6 +1224,30 @@ public void widgetSelected(SelectionEvent arg0) {
setDirtyState(true);
}
});

btnExportPart.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
TreeItem selectedItem = tree.getSelection()[0];
if (selectedItem == null) {
return;
}
Target target = (Target) selectedItem.getData();
Button b = (Button) arg0.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;
}
Boolean defaultAttrs =
MessageDialog.openQuestion(null, "Default Attributes", "Would you like to default all attributes of the exported part?");
controller.exportAsPart(target, filename, defaultAttrs);
}
});

btnDefaults.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
Expand Down