89 lines
2.4 KiB
Java
Executable File
89 lines
2.4 KiB
Java
Executable File
package pyUML.actions;
|
|
|
|
|
|
import org.eclipse.core.resources.IFile;
|
|
import org.eclipse.core.resources.IProject;
|
|
import org.eclipse.jface.action.IAction;
|
|
import org.eclipse.jface.dialogs.MessageDialog;
|
|
import org.eclipse.jface.viewers.ISelection;
|
|
import org.eclipse.jface.viewers.TreeSelection;
|
|
import org.eclipse.ui.IEditorPart;
|
|
import org.eclipse.ui.IWorkbenchWindow;
|
|
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
|
|
|
|
import pyUML.backend.EclipseHelperMethods;
|
|
import pyUML.backend.GlobalConstants;
|
|
import pyUML.backend.UMLToolsHelperMethods;
|
|
import pyUML.listeners.ModelChangeListener;
|
|
|
|
|
|
|
|
public class OpenModelAction implements IWorkbenchWindowActionDelegate{
|
|
|
|
IProject project = null;
|
|
|
|
public void dispose() {
|
|
// Auto-generated method stub
|
|
}
|
|
|
|
public void init(IWorkbenchWindow window) {
|
|
// Auto-generated method stub
|
|
}
|
|
|
|
/**
|
|
* Opens the UML diagram for the given project
|
|
* @param project
|
|
*/
|
|
public static void runOpenModel(IProject project) {
|
|
OpenModelAction delegate = new OpenModelAction();
|
|
delegate.project = project;
|
|
delegate.run((IAction) null);
|
|
}
|
|
|
|
public void run(IAction action) {
|
|
this.openModel();
|
|
}
|
|
|
|
|
|
/**
|
|
* This is the central method -
|
|
* A UML diagram is opened. The project set
|
|
* in this object is used
|
|
*/
|
|
public void openModel() {
|
|
|
|
// Ensure a project was given
|
|
if (this.project == null) {
|
|
return;
|
|
}
|
|
|
|
// save all open editors
|
|
EclipseHelperMethods.saveAllOpenEditors();
|
|
|
|
// open diagram
|
|
IFile diagramFile = this.project.getWorkspace()
|
|
.getRoot().getFile(this.project.getFullPath()
|
|
.append(GlobalConstants.getPyUmlDir())
|
|
.append(project.getName()+GlobalConstants
|
|
.getDiagramExtension()));
|
|
|
|
if (! diagramFile.exists()) {
|
|
MessageDialog.openWarning(null, "Opening UML diagram failed",
|
|
"Failed to open UML diagram, because it does not seem to exist.\n" +
|
|
"Please use 'synchronize Model' to create a new Diagram!");
|
|
return;
|
|
}else {
|
|
IEditorPart modelEditor = UMLToolsHelperMethods.openDiagram(project, diagramFile, project.getName()+".uml", true);
|
|
modelEditor.addPropertyListener(new ModelChangeListener(project));
|
|
}
|
|
}
|
|
|
|
public void selectionChanged(IAction action, ISelection selection) {
|
|
if (selection instanceof TreeSelection) {
|
|
TreeSelection ts = (TreeSelection) selection;
|
|
Object selectedElement = ts.getFirstElement();
|
|
this.project = (IProject) selectedElement;
|
|
}
|
|
}
|
|
}
|