updated refreshing Diagram view based on the click of model element
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emfutils.content.extractor/src/org/eclipse/app4mc/emfutils/content/extractor/handlers/AbstractHandlerUtils.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emfutils.content.extractor/src/org/eclipse/app4mc/emfutils/content/extractor/handlers/AbstractHandlerUtils.java
index d9fcb95..0ae4661 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emfutils.content.extractor/src/org/eclipse/app4mc/emfutils/content/extractor/handlers/AbstractHandlerUtils.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emfutils.content.extractor/src/org/eclipse/app4mc/emfutils/content/extractor/handlers/AbstractHandlerUtils.java
@@ -279,7 +279,7 @@
((DiagramView) diagramView).getIdObjectsMap().putAll(id2ObjectsMap);
((DiagramView) diagramView).getBrowser()
- .setUrl(("file:/" + getValueFromPreferenceStore(PreferenceConstants.P_FOLDER_PATH)
+ .setUrl(("file:\\" + getValueFromPreferenceStore(PreferenceConstants.P_FOLDER_PATH)
+ "\\amalthea_element_" + fileNamePrefix + ".svg"));
}
catch (final PartInitException e) {
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emfutils.content.extractor/src/org/eclipse/app4mc/emfutils/content/extractor/views/DiagramView.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emfutils.content.extractor/src/org/eclipse/app4mc/emfutils/content/extractor/views/DiagramView.java
index 39c1408..d081070 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emfutils.content.extractor/src/org/eclipse/app4mc/emfutils/content/extractor/views/DiagramView.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emfutils.content.extractor/src/org/eclipse/app4mc/emfutils/content/extractor/views/DiagramView.java
@@ -16,6 +16,7 @@
import java.io.IOException;
import java.util.Collections;
+import java.util.Stack;
import org.eclipse.app4mc.emfutils.content.extractor.Activator;
import org.eclipse.app4mc.emfutils.content.extractor.builders.EClassAllReferencesBufferBuilder;
@@ -50,6 +51,13 @@
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
+import org.eclipse.swt.browser.ProgressEvent;
+import org.eclipse.swt.browser.ProgressListener;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
@@ -95,6 +103,8 @@
addActions();
}
+
+
/**
* This is a callback that will allow us to create the viewer and initialize it.
*/
@@ -104,281 +114,333 @@
this.browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- this.browser.addLocationListener(new LocationListener() {
-
- String lastSource = "";
-
- @Override
- public void changing(final LocationEvent event) {
-
- final String location = event.location;
-
- if (!location.endsWith(".svg")) {
- final int lastIndexOf = location.lastIndexOf("/");
-
- String id = "";
- if (lastIndexOf != -1) {
- id = location.substring(lastIndexOf + 1, location.length());
- }
- final Object source = event.getSource();
-
- if (source instanceof Browser) {
-
- try {
- ((Browser) source).setUrl(this.lastSource);
- }
- catch (final Exception e) {
- // skipping exception logging, as here goal is to still retain the same image
- }
- }
-
- final Object eObject = DiagramView.this.idObjectsMap.get(id);
-
- if (eObject != null) {
-
- if (eObject instanceof EObject) {
- if (Activator.getDefault().getPreferenceStore()
- .getBoolean(PreferenceConstants.P_DRILL_DOWN)) {
-
- /*- ======================================== Regeneration of SVG Buffer for populating content specific to the selection =====================*/
-
- StringBuffer buildBuffer = new StringBuffer();
-
-
- if (ExecutionUtil.isExecuting(ExecutionCategory.eClassHierarchy)
- && (eObject instanceof EClass)) {
-
- final EClassHierarchyBufferBuilder bufferBuilder = new EClassHierarchyBufferBuilder();
-
- buildBuffer = bufferBuilder.buildBuffer((EClass) eObject);
-
- getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
- }
- else if (ExecutionUtil.isExecuting(ExecutionCategory.eClassContentsAndHierarchy)
- && (eObject instanceof EClass)) {
-
- final EClassContentsAndHierarchyBufferBuilder bufferBuilder = new EClassContentsAndHierarchyBufferBuilder();
-
- buildBuffer = bufferBuilder.buildBuffer((EClass) eObject);
-
- getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
- }
- else if (ExecutionUtil.isExecuting(ExecutionCategory.eClassAllReferences)
- && (eObject instanceof EClass)) {
-
-
- final EClassAllReferencesBufferBuilder bufferBuilder = new EClassAllReferencesBufferBuilder();
-
- buildBuffer = bufferBuilder.buildBuffer((EClass) eObject);
-
- getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
-
-
- }
- else if (ExecutionUtil.isExecuting(ExecutionCategory.eClassContentsFromReference)
- && (eObject instanceof EClass)) {
-
-
- final EClassContentsFromReferenceBufferBuilder bufferBuilder = new EClassContentsFromReferenceBufferBuilder();
-
- buildBuffer = bufferBuilder.buildBuffer((EClass) eObject);
-
- getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
-
-
- }
-
- else {
-
- /*- EClassContents and EObjectRefs behaviour is included in ObjectContentBufferBuilder java class */
- final ObjectContentBufferBuilder bufferBuilder = new ObjectContentBufferBuilder();
-
- buildBuffer = bufferBuilder.buildBuffer((EObject) eObject);
-
- getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
- }
-
-
- System.out.println(buildBuffer);
-
- try {
-
-
- final String svgFile = AbstractHandlerUtils.generateSVGFile(buildBuffer,
- ((EObject) eObject).eClass().getName() + DiagramView.this.i++,
- new BasicEMap<String, Object>());
- ((Browser) source).setUrl(svgFile);
- }
- catch (final IOException e) {
- e.printStackTrace();
- }
-
-
- }
- else {
-
-
- if (ExecutionUtil.isExecuting(ExecutionCategory.eClassHierarchy)
- && (eObject instanceof EClass)) {
- // do nothing
- }
-
-
- else if (ExecutionUtil.isExecuting(ExecutionCategory.eClassContentsAndHierarchy)
- && (eObject instanceof EClass)) {
- // do nothing
- }
- else if (ExecutionUtil.isExecuting(ExecutionCategory.eClassAllReferences)
- && (eObject instanceof EClass)) {
- // do nothing
- }
- else {
- selectElement((EObject) eObject);
-
- }
- }
-
- }
- else if (eObject instanceof EList<?>) {
-
- if (Activator.getDefault().getPreferenceStore()
- .getBoolean(PreferenceConstants.P_DRILL_DOWN)) {
-
- /*- ======================================== Regeneration of SVG Buffer for populating content specific to the selection =====================*/
-
- final ObjectContentBufferBuilder bufferBuilder = new ObjectContentBufferBuilder();
-
- final StringBuffer buildBuffer = bufferBuilder
- .buildBufferForCollection((EList<?>) eObject);
- System.out.println(buildBuffer);
-
- try {
-
- getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
-
- final String svgFile = AbstractHandlerUtils.generateSVGFile(buildBuffer,
- "Collection" + DiagramView.this.i++, bufferBuilder.getId2ObjectsMap());
- ((Browser) source).setUrl(svgFile);
- }
- catch (final IOException e) {
- e.printStackTrace();
- }
-
-
- }
- else {
- MessageDialog.openError(Display.getDefault().getActiveShell(), "Element Selection",
- "Selection of list is not possible for AMALTHEA model");
-
- try {
- ((Browser) source).setUrl(this.lastSource);
-
- }
- catch (final Exception e) {
- throw e;
- }
- }
-
- }
-
-
- }
-
-
- }
-
-
- }
-
- @Override
- public void changed(final LocationEvent event) {
- this.lastSource = event.location;
- }
-
- /**
- * This method is used to select specified AMALTHEA element in the Sphinx editor
- *
- * @param element
- */
- private void selectElement(final EObject element) {
-
- final URIEditorInput input = EcoreUIUtil.createURIEditorInput(element.eResource());
- if (null != input) {
-
- final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
- ? PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
- : PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage();
-
- Display.getDefault().asyncExec(new java.lang.Runnable() {
-
- @Override
- public void run() {
- final IEditorReference[] editorReferences = page.getEditorReferences();
-
- for (final IEditorReference iEditorReference : editorReferences) {
-
-
- if (iEditorReference.getId().equals("org.eclipse.app4mc.amalthea.sphinx.ui.editor")
- || iEditorReference.getId().equals("org.itea2.amalthea.sphinx.ui.editor")) {
- try {
- final FileEditorInput editorInput = (FileEditorInput) iEditorReference
- .getEditorInput();
-
- final IFile fileFromEditor = editorInput.getFile();
-
- final Resource eResource = element.eResource();
-
- final URI uri = eResource.getURI();
-
- final IFile fileFromResource = ResourcesPlugin.getWorkspace().getRoot()
- .getFile(new Path(uri.toPlatformString(true)));
-
-
- if ((fileFromEditor != null && fileFromResource != null)
- && fileFromEditor.toString().equals(fileFromResource.toString())) {
-
- final IEditorPart activeEditor = iEditorReference.getEditor(false);
-
- if (activeEditor instanceof BasicTransactionalFormEditor) {
-
- IDE.openEditor(page, editorInput, iEditorReference.getId());
-
- if (canCollapseTreeElements()) {
-
- final Viewer viewer = ((BasicTransactionalFormEditor) activeEditor)
- .getViewer();
-
- if (viewer instanceof TreeViewer) {
- ((TreeViewer) viewer).collapseAll();
- }
- }
- ((BasicTransactionalFormEditor) activeEditor)
- .setSelectionToViewer(Collections.singleton(element));
- }
-
- }
- }
- catch (final PartInitException e) {
- e.printStackTrace();
- }
- }
- }
-
- }
-
- private boolean canCollapseTreeElements() {
- return Activator.getDefault().getPreferenceStore()
- .getBoolean(PreferenceConstants.P_REDRAW_TREE_ON_SELECTION);
- }
- });
-
- }
-
- }
- });
+ CustomBrowserListener listener = new CustomBrowserListener();
+ this.browser.addKeyListener(listener );
+
+ this.browser.addLocationListener(listener);
+
+
}
+
+ class CustomBrowserListener implements LocationListener, KeyListener {
+
+ String lastSource = "";
+
+ public Stack<String> urls=new Stack<>();;
+
+ boolean isBackButtonPressed=false;
+
+ @Override
+ public void changing(final LocationEvent event) {
+
+ if(isBackButtonPressed) {
+ isBackButtonPressed=false;
+ return;
+ }
+
+ final String location = event.location;
+//TODO: found this
+ if (!location.endsWith(".svg")) {
+ final int lastIndexOf = location.lastIndexOf("/");
+
+ String id = "";
+ if (lastIndexOf != -1) {
+ id = location.substring(lastIndexOf + 1, location.length());
+ }
+ final Object source = event.getSource();
+
+ if (source instanceof Browser) {
+
+ try {
+// ((Browser) source).setUrl(this.lastSource);
+ }
+ catch (final Exception e) {
+ // skipping exception logging, as here goal is to still retain the same image
+ }
+ }
+
+ final Object eObject = DiagramView.this.idObjectsMap.get(id);
+
+ if (eObject != null) {
+
+ if (eObject instanceof EObject) {
+ if (Activator.getDefault().getPreferenceStore()
+ .getBoolean(PreferenceConstants.P_DRILL_DOWN)) {
+
+ /*- ======================================== Regeneration of SVG Buffer for populating content specific to the selection =====================*/
+
+ StringBuffer buildBuffer = new StringBuffer();
+
+
+ if (ExecutionUtil.isExecuting(ExecutionCategory.eClassHierarchy)
+ && (eObject instanceof EClass)) {
+
+ final EClassHierarchyBufferBuilder bufferBuilder = new EClassHierarchyBufferBuilder();
+
+ buildBuffer = bufferBuilder.buildBuffer((EClass) eObject);
+
+ getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
+ }
+ else if (ExecutionUtil.isExecuting(ExecutionCategory.eClassContentsAndHierarchy)
+ && (eObject instanceof EClass)) {
+
+ final EClassContentsAndHierarchyBufferBuilder bufferBuilder = new EClassContentsAndHierarchyBufferBuilder();
+
+ buildBuffer = bufferBuilder.buildBuffer((EClass) eObject);
+
+ getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
+ }
+ else if (ExecutionUtil.isExecuting(ExecutionCategory.eClassAllReferences)
+ && (eObject instanceof EClass)) {
+
+
+ final EClassAllReferencesBufferBuilder bufferBuilder = new EClassAllReferencesBufferBuilder();
+
+ buildBuffer = bufferBuilder.buildBuffer((EClass) eObject);
+
+ getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
+
+
+ }
+ else if (ExecutionUtil.isExecuting(ExecutionCategory.eClassContentsFromReference)
+ && (eObject instanceof EClass)) {
+
+
+ final EClassContentsFromReferenceBufferBuilder bufferBuilder = new EClassContentsFromReferenceBufferBuilder();
+
+ buildBuffer = bufferBuilder.buildBuffer((EClass) eObject);
+
+ getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
+
+
+ }
+
+ else {
+
+ /*- EClassContents and EObjectRefs behaviour is included in ObjectContentBufferBuilder java class */
+ final ObjectContentBufferBuilder bufferBuilder = new ObjectContentBufferBuilder();
+
+ buildBuffer = bufferBuilder.buildBuffer((EObject) eObject);
+
+ getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
+ }
+
+
+ System.out.println(buildBuffer);
+
+ try {
+
+
+ final String svgFile = AbstractHandlerUtils.generateSVGFile(buildBuffer,
+ ((EObject) eObject).eClass().getName() + DiagramView.this.i++,
+ new BasicEMap<String, Object>());
+ ((Browser) source).setUrl(svgFile);
+ }
+ catch (final IOException e) {
+ e.printStackTrace();
+ }
+
+
+ }
+ else {
+
+
+ if (ExecutionUtil.isExecuting(ExecutionCategory.eClassHierarchy)
+ && (eObject instanceof EClass)) {
+ // do nothing
+ }
+
+
+ else if (ExecutionUtil.isExecuting(ExecutionCategory.eClassContentsAndHierarchy)
+ && (eObject instanceof EClass)) {
+ // do nothing
+ }
+ else if (ExecutionUtil.isExecuting(ExecutionCategory.eClassAllReferences)
+ && (eObject instanceof EClass)) {
+ // do nothing
+ }
+ else {
+ selectElement((EObject) eObject);
+
+ }
+
+// ((Browser)source).stop();
+
+ event.doit=false;
+ }
+
+ }
+ else if (eObject instanceof EList<?>) {
+
+ if (Activator.getDefault().getPreferenceStore()
+ .getBoolean(PreferenceConstants.P_DRILL_DOWN)) {
+
+ /*- ======================================== Regeneration of SVG Buffer for populating content specific to the selection =====================*/
+
+ final ObjectContentBufferBuilder bufferBuilder = new ObjectContentBufferBuilder();
+
+ final StringBuffer buildBuffer = bufferBuilder
+ .buildBufferForCollection((EList<?>) eObject);
+ System.out.println(buildBuffer);
+
+ try {
+
+ getIdObjectsMap().addAll(bufferBuilder.getId2ObjectsMap());
+
+ final String svgFile = AbstractHandlerUtils.generateSVGFile(buildBuffer,
+ "Collection" + DiagramView.this.i++, bufferBuilder.getId2ObjectsMap());
+ ((Browser) source).setUrl(svgFile);
+ }
+ catch (final IOException e) {
+ e.printStackTrace();
+ }
+
+
+ }
+ else {
+ MessageDialog.openError(Display.getDefault().getActiveShell(), "Element Selection",
+ "Selection of list is not possible for AMALTHEA model");
+
+ try {
+ ((Browser) source).setUrl(this.lastSource);
+
+ }
+ catch (final Exception e) {
+ throw e;
+ }
+ }
+
+ }
+
+
+ }
+
+
+ }
+
+
+ }
+
+ @Override
+ public void changed(final LocationEvent event) {
+ this.lastSource = event.location;
+ urls.push(this.lastSource);
+ }
+
+ /**
+ * This method is used to select specified AMALTHEA element in the Sphinx editor
+ *
+ * @param element
+ */
+ private void selectElement(final EObject element) {
+
+ final URIEditorInput input = EcoreUIUtil.createURIEditorInput(element.eResource());
+ if (null != input) {
+
+ final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
+ ? PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ : PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage();
+
+ Display.getDefault().asyncExec(new java.lang.Runnable() {
+
+ @Override
+ public void run() {
+ final IEditorReference[] editorReferences = page.getEditorReferences();
+
+ for (final IEditorReference iEditorReference : editorReferences) {
+
+
+ if (iEditorReference.getId().equals("org.eclipse.app4mc.amalthea.sphinx.ui.editor")
+ || iEditorReference.getId().equals("org.itea2.amalthea.sphinx.ui.editor")) {
+ try {
+ final FileEditorInput editorInput = (FileEditorInput) iEditorReference
+ .getEditorInput();
+
+ final IFile fileFromEditor = editorInput.getFile();
+
+ final Resource eResource = element.eResource();
+
+ final URI uri = eResource.getURI();
+
+ final IFile fileFromResource = ResourcesPlugin.getWorkspace().getRoot()
+ .getFile(new Path(uri.toPlatformString(true)));
+
+
+ if ((fileFromEditor != null && fileFromResource != null)
+ && fileFromEditor.toString().equals(fileFromResource.toString())) {
+
+ final IEditorPart activeEditor = iEditorReference.getEditor(false);
+
+ if (activeEditor instanceof BasicTransactionalFormEditor) {
+
+ IDE.openEditor(page, editorInput, iEditorReference.getId());
+
+ if (canCollapseTreeElements()) {
+
+ final Viewer viewer = ((BasicTransactionalFormEditor) activeEditor)
+ .getViewer();
+
+ if (viewer instanceof TreeViewer) {
+ ((TreeViewer) viewer).collapseAll();
+ }
+ }
+ ((BasicTransactionalFormEditor) activeEditor)
+ .setSelectionToViewer(Collections.singleton(element));
+ }
+
+ }
+ }
+ catch (final PartInitException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+ private boolean canCollapseTreeElements() {
+ return Activator.getDefault().getPreferenceStore()
+ .getBoolean(PreferenceConstants.P_REDRAW_TREE_ON_SELECTION);
+ }
+ });
+
+ }
+
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+
+ if(e.character=='\b') {
+ isBackButtonPressed=true;
+ Object source = e.getSource();
+ if (source instanceof Browser) {
+
+ try {
+ if(urls.isEmpty()==false) {
+ String pop = urls.pop();
+
+ if(urls.isEmpty()==false) {
+ pop = urls.pop();
+ ((Browser) source).setUrl(pop);
+ }
+ }
+ }
+ catch (final Exception exception) {
+ // skipping exception logging, as here goal is to still retain the same image
+ }
+ }
+
+ }
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+
+
+ }
+ };
private void addActions() {
final String P_DRILL_DOWN = Activator.getDefault().getPreferenceStore()