75 lines
2.7 KiB
Java
Executable File
75 lines
2.7 KiB
Java
Executable File
package pyUML.listeners;
|
|
|
|
import org.eclipse.core.resources.IFile;
|
|
import org.eclipse.core.resources.IProject;
|
|
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
|
|
import org.eclipse.ui.IEditorPart;
|
|
import org.eclipse.ui.IPropertyListener;
|
|
import org.eclipse.ui.PlatformUI;
|
|
|
|
import pyUML.backend.EclipseHelperMethods;
|
|
import pyUML.backend.GlobalConstants;
|
|
import pyUML.backend.UMLToolsHelperMethods;
|
|
import pyUML.views.SynchronizeModelByView;
|
|
|
|
|
|
|
|
/**
|
|
* This listener synchronizes the global model and
|
|
* all other pyUML.views whenever a view is saved
|
|
*/
|
|
public class ViewChangeListener implements IPropertyListener {
|
|
private IProject project;
|
|
|
|
public ViewChangeListener(IProject project) {
|
|
super();
|
|
this.project = project;
|
|
}
|
|
|
|
public void propertyChanged(Object source, int propId) {
|
|
if (source instanceof DiagramEditor) {
|
|
DiagramEditor umlEditor = (DiagramEditor) source;
|
|
if (! umlEditor.isDirty()) {
|
|
// editor was just saved, otherwise it would be dirty.
|
|
// -> synchronize model every time the view is saved
|
|
|
|
|
|
|
|
String openEditorName=umlEditor.getTitle();
|
|
String viewPath = this.project.getLocation()
|
|
.append(GlobalConstants.getPyUmlDir())
|
|
.append(openEditorName.replace(GlobalConstants.getDiagramExtension(), "")
|
|
+ GlobalConstants.getViewUmlExtension()).toOSString();
|
|
SynchronizeModelByView.synchronizeGlobalModel(viewPath, this.project);
|
|
|
|
|
|
IFile globalModelDiagramFile = this.project.getWorkspace()
|
|
.getRoot().getFile(this.project.getFullPath()
|
|
.append(GlobalConstants.getPyUmlDir())
|
|
.append(project.getName()+GlobalConstants
|
|
.getDiagramExtension()));
|
|
|
|
// close all sub-package pyUML.views of global model diagram
|
|
for ( org.eclipse.ui.IEditorReference editor :
|
|
EclipseHelperMethods.lookForOpenEditorByName(project.getName()+"::.*")) {
|
|
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
|
.getActivePage().closeEditor(editor.getEditor(true), true);
|
|
}
|
|
|
|
// after creating model, be sure the diagram view is reloaded
|
|
boolean diagramOpened = null != EclipseHelperMethods
|
|
.lookForOpenEditorByName(project.getName()+GlobalConstants.getDiagramExtension());
|
|
if (diagramOpened) {
|
|
// set focus to updated diagram only if no diagram is currently active
|
|
boolean keepFocus = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
|
.getActivePage().getActiveEditor().getTitle()
|
|
.matches(".*"+GlobalConstants.getDiagramExtension());
|
|
IEditorPart modelDiagram = UMLToolsHelperMethods.refreshDiagramEditor(project, globalModelDiagramFile, keepFocus);
|
|
modelDiagram.addPropertyListener(new ModelChangeListener(project));
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|