this.saveAs = new Action("Save As...") {
public void run() {
FdToUml fd2uml = FdToUml.getInstance();
try {
FileDialog FDialog = new FileDialog(FileLibrary.getShell(),
SWT.SAVE);
FDialog.setFilterPath(FileLibrary.getActiveProject()
.getLocation().toOSString()); // Current project path
FDialog.setFilterExtensions(new String[] { "*"+FileLibrary.ASSOC_EXT });
String fileName = FDialog.open();
if(fileName != null){
DiagramListFileHelper.write(fd2uml.getDiagramsObj(),
fileName);
FdToUml.setCurrentConfigurationFile(fileName);
}
try {
FileLibrary.getActiveProject().refreshLocal(1, null);
} catch (CoreException e) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
this.saveAs.setImageDescriptor(FileLibrary
.getFile("SaveAs.gif"));
this.save = new Action("Save") {
public void run() {
FdToUml fd2uml = FdToUml.getInstance();
try {
if(!FdToUml.getCurrentConfigurationFile().isEmpty()){
DiagramListFileHelper.write(fd2uml.getDiagramsObj(),
FdToUml.getCurrentConfigurationFile());
} else {
FileDialog FDialog = new FileDialog(FileLibrary.getShell(),
SWT.SAVE);
FDialog.setFilterPath(FileLibrary.getActiveProject()
.getLocation().toOSString()); // Current project path
FDialog.setFilterExtensions(new String[] { "*"+FileLibrary.ASSOC_EXT });
String fileName = FDialog.open();
if(fileName != null){
DiagramListFileHelper.write(fd2uml.getDiagramsObj(),
fileName);
FdToUml.setCurrentConfigurationFile(fileName);
}
}
try {
FileLibrary.getActiveProject().refreshLocal(1, null);
} catch (CoreException e) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
this.save.setImageDescriptor(FileLibrary
.getFile("save.gif"));
this.load = new Action("Load") {
public void run() {
if (FileLibrary.getActiveProject() != null) {
FdToUml fd2uml = FdToUml.getInstance();
FileDialog FDialog = new FileDialog(FileLibrary.getShell(),
SWT.OPEN);
FDialog.setFilterPath(FileLibrary.getActiveProject()
.getLocation().toOSString()); // Current project
// path
FDialog.setFilterExtensions(new String[] { "*"
+ FileLibrary.ASSOC_EXT });
String fileName = FDialog.open();
if (fileName != null
&& fileName.contains(FileLibrary.ASSOC_EXT)) {
try {
DiagramList DL = DiagramListFileHelper
.read(fileName);
fd2uml.setDiagramsObj(DL);
fd2uml.setCurrentDiagramId(DL.getDiagrams().get(0)
.getID());
FdToUml.refreshConfigurationElementsDataFromDiagram();
tree.getTree().removeAll();
tree.setInput(DL);
tree.refresh();
FdToUml.setCurrentConfigurationFile(fileName);
if (!DL.isEmpty())
for (Diagram diagram : DL.getDiagrams()) {
if (!diagram.getDiagramAssociations()
.getElements().isEmpty())
for (AssociatedElement element : diagram
.getDiagramAssociations()
.getElements()) {
tree.setChecked(element, element
.isChecked());
}
}
tree.expandAll();
} catch (Exception e) {
MessageDialog
.openError(FileLibrary.getShell(),
"File Read Error",
"Invalid data in configuration file '"+FileLibrary.getFileName(fileName)+"'!");
//e.printStackTrace();
}
}
} else {
MessageDialog
.openInformation(FileLibrary.getShell(),
"Open Configuration",
"Please open atleast one FD diagram to load configuration.");
}
}
};
this.load.setImageDescriptor(FileLibrary.getFile("load.gif"));
this.selectAllAction = new Action("Slelect All Diagrams") {
public void run() {
FdToUml fd2uml = FdToUml.getInstance();
for (Diagram DG : fd2uml.getDiagramsObj().getDiagrams()) {
tree.setChecked(DG, true);
}
}
};
this.selectAllAction.setImageDescriptor(FileLibrary
.getFile("SelectAll.gif"));
this.deSelectAllAction = new Action("Select None Diagrams") {
public void run() {
FdToUml fd2uml = FdToUml.getInstance();
for (Diagram DG : fd2uml.getDiagramsObj().getDiagrams()) {
tree.setChecked(DG, false);
}
}
};
this.deSelectAllAction.setImageDescriptor(FileLibrary
.getFile("DeSelectAll.gif"));
this.deleteItemAction = new Action("Clear All") {
public void run() {
// Object[] o = tree.getCheckedElements();
FdToUml fd2uml = FdToUml.getInstance();
if (!fd2uml.getDiagramsObj().isEmpty()) {
if (MessageDialog
.openConfirm(FileLibrary.getShell(),
"Confirm Delete",
"Are you sure you want to clear all diagram associations?")) {
tree.getTree().removeAll();
fd2uml.getDiagramsObj().emptyDiagramList();
fd2uml.setCurrentDiagramId("");
tree.refresh();
}
}
}
};
this.deleteItemAction.setImageDescriptor(FileLibrary
.getFile("Delete.gif"));
this.generateClassDiagram = new Action("Generate UML Class") {
public void run() {
FdToUml.refreshConfigurationElementsDataFromDiagram();
Object[] oArray = tree.getCheckedElements();
ArrayList<Diagram> diagrams = new ArrayList<Diagram>();
FdToUml fd2uml = FdToUml.getInstance();
boolean wereSelectedDiagrams = false;
for (Object o : oArray)
if (o instanceof Diagram) {
diagrams.add((Diagram) o);