diff options
author | lunkpeter | 2016-06-02 15:21:39 +0000 |
---|---|---|
committer | lunkpeter | 2016-06-09 11:22:36 +0000 |
commit | 421c1070634469b77cab8204bdbd9f78fb6ffd35 (patch) | |
tree | a565e37ba82a454e102f5910e76f465c375899d4 | |
parent | 2048879aa8acb01f27ccce39170a0f87993bf4fc (diff) | |
download | org.eclipse.viatra-change/73709/7.tar.gz org.eclipse.viatra-change/73709/7.tar.xz org.eclipse.viatra-change/73709/7.zip |
[493206] Added a generic EMF-edit-based model view. change/73709/7
This view is updated as the transformation progresses, and support the
properties view.
Change-Id: I051963c57b2628d7848d340019a8239303855d08
16 files changed, 403 insertions, 118 deletions
diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/META-INF/MANIFEST.MF b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/META-INF/MANIFEST.MF index b9ca9abd0..d210b1f9c 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/META-INF/MANIFEST.MF +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/META-INF/MANIFEST.MF @@ -17,6 +17,7 @@ Require-Bundle: org.eclipse.xtend.lib;bundle-version="[2.8.0,3.0.0)", org.eclipse.jdt.ui, org.eclipse.xtend.ide;bundle-version="[2.8.0,3.0.0)", org.eclipse.xtext.ui;bundle-version="[2.8.0,3.0.0)", - org.eclipse.viatra.query.patternlanguage.emf.ui + org.eclipse.viatra.query.patternlanguage.emf.ui, + org.eclipse.emf.ecore.editor Bundle-Activator: org.eclipse.viatra.transformation.debug.ui.activator.TransformationDebugUIActivator Bundle-ActivationPolicy: lazy diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/AddConditionalBreakpointHandler.java b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/AddConditionalBreakpointHandler.java index b7a05411d..2c4af88a2 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/AddConditionalBreakpointHandler.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/AddConditionalBreakpointHandler.java @@ -10,14 +10,11 @@ */ package org.eclipse.viatra.transformation.debug.ui.handlers; -import java.lang.reflect.InvocationTargetException; - import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.ui.actions.ExportBreakpointsOperation; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.window.Window; @@ -25,7 +22,6 @@ import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.viatra.transformation.debug.model.TransformationThread; import org.eclipse.viatra.transformation.debug.model.TransformationThreadFactory; import org.eclipse.viatra.transformation.debug.model.breakpoint.ConditionalTransformationBreakpoint; -import org.eclipse.viatra.transformation.debug.ui.util.BreakpointCacheUtil; import org.eclipse.viatra.transformation.evm.api.adapter.AdaptableEVM; import com.google.inject.Inject; @@ -55,14 +51,9 @@ public class AddConditionalBreakpointHandler extends AbstractHandler { .createMarker(breakpoint.getMarkerIdentifier())); breakpoint.setEnabled(true); DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(breakpoint); - ExportBreakpointsOperation operation = new ExportBreakpointsOperation( - BreakpointCacheUtil.filterBreakpoints(thread.getBreakpoints()), - BreakpointCacheUtil.getBreakpointCacheLocation()); - operation.run(null); - } } - } catch (CoreException | InvocationTargetException e) { + } catch (CoreException e) { throw new ExecutionException("Error while adding conditional breakpoint", e); } diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/AddRuleBreakpointHandler.java b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/AddRuleBreakpointHandler.java index 39d2c7822..75d084d06 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/AddRuleBreakpointHandler.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/AddRuleBreakpointHandler.java @@ -10,14 +10,11 @@ */ package org.eclipse.viatra.transformation.debug.ui.handlers; -import java.lang.reflect.InvocationTargetException; - import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.ui.actions.ExportBreakpointsOperation; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; @@ -26,7 +23,6 @@ import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.viatra.transformation.debug.model.TransformationThread; import org.eclipse.viatra.transformation.debug.model.TransformationThreadFactory; import org.eclipse.viatra.transformation.debug.model.breakpoint.RuleBreakpoint; -import org.eclipse.viatra.transformation.debug.ui.util.BreakpointCacheUtil; import org.eclipse.viatra.transformation.evm.api.adapter.AdaptableEVM; public class AddRuleBreakpointHandler extends AbstractHandler { @@ -51,14 +47,10 @@ public class AddRuleBreakpointHandler extends AbstractHandler { .createMarker(breakpoint.getMarkerIdentifier())); breakpoint.setEnabled(true); DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(breakpoint); - ExportBreakpointsOperation operation = new ExportBreakpointsOperation( - BreakpointCacheUtil.filterBreakpoints(thread.getBreakpoints()), - BreakpointCacheUtil.getBreakpointCacheLocation()); - operation.run(null); } } - } catch (CoreException | InvocationTargetException e) { + } catch (CoreException e) { throw new ExecutionException("Error while adding rule breakpoint", e); } return null; diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/SelectNextActivationHandler.java b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/SelectNextActivationHandler.java index 1677103db..ce8314767 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/SelectNextActivationHandler.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/SelectNextActivationHandler.java @@ -30,7 +30,7 @@ public class SelectNextActivationHandler extends AbstractHandler { TransformationThread thread = DebugUIUtil .getActivationThread((Activation<?>) ((IStructuredSelection) selection).getFirstElement()); if (thread != null) { - thread.setNextActivation((Activation<?>) selection); + thread.setNextActivation((Activation<?>) ((IStructuredSelection) selection).getFirstElement()); } } diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/ToggleActivationBreakpointHandler.java b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/ToggleActivationBreakpointHandler.java index ba6318200..2b701ee7a 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/ToggleActivationBreakpointHandler.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/handlers/ToggleActivationBreakpointHandler.java @@ -36,7 +36,7 @@ public class ToggleActivationBreakpointHandler extends AbstractHandler { .getActivationThread((Activation<?>) ((IStructuredSelection) selection).getFirstElement()); if (thread != null) { TransformationBreakpoint transformationBreakpoint = new TransformationBreakpoint( - (Activation<?>) selection); + (Activation<?>) ((IStructuredSelection) selection).getFirstElement()); transformationBreakpoint.setMarker(thread.getTransformationType().getResource() .createMarker(transformationBreakpoint.getMarkerIdentifier())); transformationBreakpoint.setEnabled(true); diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/model/DebugModelPresentation.java b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/model/DebugModelPresentation.java index b7aa7f4af..8bc1f50ca 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/model/DebugModelPresentation.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/model/DebugModelPresentation.java @@ -38,7 +38,7 @@ public class DebugModelPresentation extends LabelProvider implements IDebugModel for (RuleParameterTrace parameterTrace : breakpoint.getTrace().getRuleParameterTraces()) { parameters += parameterTrace.getParameterName() + " : " + parameterTrace.getObjectId() + " "; } - return "Rule: " + breakpoint.getTrace().getRuleName() + "(" + parameters + ")"; + return "Transformation Activation Breakpoint - Rule: " + breakpoint.getTrace().getRuleName() + "(" + parameters + ")"; } else if (element instanceof TransformationStackFrame) { return ((TransformationStackFrame) element).getName(); @@ -56,8 +56,6 @@ public class DebugModelPresentation extends LabelProvider implements IDebugModel @Override public void computeDetail(IValue value, IValueDetailListener listener) { - // TODO support details for values - } @Override diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/ModelInstanceViewer.java b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/ModelInstanceViewer.java index b9d60407e..e414c630c 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/ModelInstanceViewer.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/ModelInstanceViewer.java @@ -11,124 +11,312 @@ package org.eclipse.viatra.transformation.debug.ui.views; import java.util.List; -import java.util.NoSuchElementException; +import java.util.Map; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugException; import org.eclipse.emf.common.notify.Notifier; import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; +import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; +import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.part.ViewPart; -import org.eclipse.ui.progress.IWorkbenchSiteProgressService; +import org.eclipse.ui.views.properties.IPropertySheetPage; +import org.eclipse.ui.views.properties.PropertySheetPage; import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; import org.eclipse.viatra.query.runtime.api.scope.QueryScope; import org.eclipse.viatra.query.runtime.emf.EMFScope; import org.eclipse.viatra.transformation.debug.model.ITransformationStateListener; import org.eclipse.viatra.transformation.debug.model.TransformationState; +import org.eclipse.viatra.transformation.debug.model.TransformationThread; import org.eclipse.viatra.transformation.debug.model.TransformationThreadFactory; +import org.eclipse.viatra.transformation.debug.ui.activator.TransformationDebugUIActivator; +import org.eclipse.viatra.transformation.debug.ui.views.transformationbrowser.AdaptableTransformationBrowser; +import org.eclipse.viatra.transformation.evm.api.adapter.AdaptableEVM; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; public class ModelInstanceViewer extends ViewPart implements ITransformationStateListener { public ModelInstanceViewer() { } public static final String ID = "org.eclipse.viatra.transformation.ui.debug.TransformationViewer"; - private TreeViewer treeViewer; + + private CTabFolder tabFolder; + private Composite composite; - private ViatraQueryEngine engine; + + private ISelectionListener listener; + + private ReflectiveItemProviderAdapterFactory adapterFactory; + + private AdapterFactoryLabelProvider adapterFactoryLabelProvider; + + private AdapterFactoryContentProvider adapterFactoryContentProvider; + + private Map<CTabItem, TreeViewer> tabMap = Maps.newHashMap(); + + private ISelectionService sService; + + private TabbedSelectionProviderWrapper selectionProviderWrapper; @Override public void createPartControl(Composite parent) { + adapterFactory = new ReflectiveItemProviderAdapterFactory(); + sService = getSite().getWorkbenchWindow().getSelectionService(); + + adapterFactoryLabelProvider = new AdapterFactoryLabelProvider(adapterFactory); + adapterFactoryContentProvider = new AdapterFactoryContentProvider(adapterFactory); composite = new Composite(parent, SWT.NONE); composite.setLayout(new FillLayout(SWT.HORIZONTAL)); - treeViewer = new TreeViewer(composite, SWT.BORDER); + tabFolder = new CTabFolder(composite, SWT.BORDER); + tabFolder.setBorderVisible(true); + tabFolder.setSelectionBackground( + Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT)); + + selectionProviderWrapper = new TabbedSelectionProviderWrapper(); + getSite().setSelectionProvider(selectionProviderWrapper); + tabFolder.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + if (e.item instanceof CTabItem) { + selectionProviderWrapper.setActiveProvider(tabMap.get(tabFolder.getSelection())); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + + }); + + listener = new ISelectionListener() { + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if (!selection.isEmpty() && selection instanceof StructuredSelection) { + Object firstElement = ((StructuredSelection) selection).getFirstElement(); + try { + if (firstElement instanceof AdaptableEVM) { + TransformationThread thread = TransformationThreadFactory.getInstance() + .getTransformationThread(((AdaptableEVM) firstElement).getIdentifier()); + if (thread != null) { + maintainTabs(getResources(thread.getEngine())); + TransformationThreadFactory.getInstance().unRegisterListener(ModelInstanceViewer.this); + TransformationThreadFactory.getInstance().registerListener(ModelInstanceViewer.this, + ((AdaptableEVM) firstElement).getIdentifier()); + } + } + } catch (Exception e) { + ErrorDialog.openError(composite.getShell(), "An error has occured", e.getMessage(), new Status(IStatus.ERROR, TransformationDebugUIActivator.PLUGIN_ID, e.getMessage())); + } + } + + } + }; + + sService.addSelectionListener(AdaptableTransformationBrowser.ID, listener); + + } + + private void maintainTabs(ResourceSet[] resourceSets) { + tabMap.clear(); + for (CTabItem item : tabFolder.getItems()) { + item.getControl().dispose(); + item.dispose(); + } + for (ResourceSet rs : resourceSets) { + EList<Resource> resources = rs.getResources(); + for (Resource resource : resources) { + CTabItem ritem = new CTabItem(tabFolder, SWT.NONE); + ritem.setText(resource.getURI().lastSegment()); + + TreeViewer treeViewer = new TreeViewer(tabFolder, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.VIRTUAL); + + ritem.setControl(treeViewer.getTree()); + tabMap.put(ritem, treeViewer); + + treeViewer.setContentProvider(adapterFactoryContentProvider); + treeViewer.setLabelProvider(adapterFactoryLabelProvider); + + if (resource.getContents().size() == 1) { + treeViewer.setInput(resource.getContents().get(0)); + ritem.setControl(treeViewer.getControl()); + } + + } + } + if (tabFolder.getItems().length > 0) { + tabFolder.setSelection(tabFolder.getItems()[0]); + selectionProviderWrapper.setActiveProvider(tabMap.get(tabFolder.getSelection())); + } + + } + + private ResourceSet[] getResources(ViatraQueryEngine engine) { + List<ResourceSet> retVal = Lists.newArrayList(); + QueryScope scope = engine.getScope(); + if (scope instanceof EMFScope) { + for (Notifier notifier : ((EMFScope) scope).getScopeRoots()) { + if (notifier instanceof ResourceSet) { + retVal.add((ResourceSet) notifier); + } + } + } + return retVal.toArray(new ResourceSet[retVal.size()]); } @Override public void setFocus() { - treeViewer.getControl().setFocus(); + tabFolder.setFocus(); + } + + @Override + public void dispose() { + selectionProviderWrapper.dispose(); + super.dispose(); } @Override public void transformationStateChanged(final TransformationState state, String id) { - treeViewer.getControl().getDisplay().syncExec(new Runnable() { + tabFolder.getDisplay().syncExec(new Runnable() { @Override public void run() { - if (engine == null) { - engine = state.getEngine(); - treeViewer.setInput(getModel()); - } + maintainTabs(getResources(state.getEngine())); } + }); } @Override - public void transformationStateDisposed(TransformationState state, final String id) { - treeViewer.getControl().getDisplay().syncExec(new Runnable() { + public void transformationStateDisposed(TransformationState state, String id) { + tabFolder.getDisplay().syncExec(new Runnable() { + @Override public void run() { - engine = null; - treeViewer.setInput(null); + for (CTabItem item : tabFolder.getItems()) { + item.getControl().dispose(); + item.dispose(); + } } + }); + + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public Object getAdapter(Class adapter) { + if (adapter.equals(IPropertySheetPage.class)) { + return getPropertySheetPage(); + } + return super.getAdapter(adapter); } - private List<EObject> getModel() { - QueryScope scope = engine.getScope(); - if (scope instanceof EMFScope) { - List<EObject> input = Lists.newArrayList(); - if (((EMFScope) scope).getScopeRoots().size() > 0) { - Notifier root = Lists.newArrayList(((EMFScope) scope).getScopeRoots()).get(0); - if (root instanceof ResourceSet) { - EList<Resource> resources = ((ResourceSet) root).getResources(); - for (Resource resource : resources) { - input.addAll(((Resource) resource).getContents()); - } + public IPropertySheetPage getPropertySheetPage() { + PropertySheetPage propertySheetPage = new PropertySheetPage(); + propertySheetPage.setPropertySourceProvider(adapterFactoryContentProvider); + return propertySheetPage; + } + + + /** + * Based on org.eclipse.debug.internal.ui.views.variables.VariablesView + * @author Peter Lunk + * + */ + private static class TabbedSelectionProviderWrapper implements ISelectionProvider { + private final ListenerList fListenerList; + + private final ISelectionChangedListener fListener; + private ISelectionProvider fActiveProvider; + + private TabbedSelectionProviderWrapper() { + fListenerList = new ListenerList(ListenerList.IDENTITY); + fListener = new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + fireSelectionChanged(event); } + }; + } + + public void setActiveProvider(ISelectionProvider provider) { + if (fActiveProvider == provider || this == provider) { + return; + } + if (fActiveProvider != null) { + fActiveProvider.removeSelectionChangedListener(fListener); + } + if (provider != null) { + provider.addSelectionChangedListener(fListener); } + fActiveProvider = provider; + fireSelectionChanged(new SelectionChangedEvent(this, getSelection())); + } - return input; + private void dispose() { + fListenerList.clear(); + setActiveProvider(null); } - return null; - } + private void fireSelectionChanged(SelectionChangedEvent event) { + Object[] listeners = fListenerList.getListeners(); + for (int i = 0; i < listeners.length; i++) { + ISelectionChangedListener listener = (ISelectionChangedListener) listeners[i]; + listener.selectionChanged(event); + } + } - public void registerToId(String id) { - try { - TransformationThreadFactory.getInstance().registerListener(this, id); - } catch (NoSuchElementException | DebugException e) { - ErrorDialog.openError(composite.getShell(), "An error has occured during initialization", e.getMessage(), - new Status(IStatus.ERROR, "org.eclipse.viatra.transformation.debug.ui", e.getMessage())); + @Override + public void addSelectionChangedListener(ISelectionChangedListener listener) { + fListenerList.add(listener); } - } - @Override - public void dispose() { - super.dispose(); - engine = null; - TransformationThreadFactory.getInstance().unRegisterListener(this); - } + @Override + public ISelection getSelection() { + if (fActiveProvider != null) { + return fActiveProvider.getSelection(); + } + return StructuredSelection.EMPTY; + } - public IWorkbenchSiteProgressService getProgressService() { - IWorkbenchSiteProgressService service = null; - Object siteService = getSite().getAdapter(IWorkbenchSiteProgressService.class); - if (siteService != null) { - service = (IWorkbenchSiteProgressService) siteService; + @Override + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + fListenerList.remove(listener); } - return service; - } + @Override + public void setSelection(ISelection selection) { + if (fActiveProvider != null) { + fActiveProvider.setSelection(selection); + } + } + } } diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/transformationbrowser/AdaptableEVMDoubleClickListener.java b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/transformationbrowser/AdaptableEVMDoubleClickListener.java index c3dc499b3..6bac9d46d 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/transformationbrowser/AdaptableEVMDoubleClickListener.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/transformationbrowser/AdaptableEVMDoubleClickListener.java @@ -10,15 +10,12 @@ */ package org.eclipse.viatra.transformation.debug.ui.views.transformationbrowser; -import java.lang.reflect.InvocationTargetException; - import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.debug.ui.actions.ImportBreakpointsOperation; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.search.SearchEngine; import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; @@ -32,7 +29,6 @@ import org.eclipse.jface.window.Window; import org.eclipse.ui.dialogs.SelectionDialog; import org.eclipse.viatra.transformation.debug.launch.TransformationLaunchConfigurationDelegate; import org.eclipse.viatra.transformation.debug.model.TransformationThreadFactory; -import org.eclipse.viatra.transformation.debug.ui.util.BreakpointCacheUtil; import org.eclipse.viatra.transformation.evm.api.adapter.AdaptableEVM; @SuppressWarnings("restriction") @@ -83,19 +79,11 @@ public class AdaptableEVMDoubleClickListener implements IDoubleClickListener { DebugUITools.launch(workingCopy, "debug"); - if(BreakpointCacheUtil.breakpointCacheExists()){ - ImportBreakpointsOperation operation = new ImportBreakpointsOperation( - BreakpointCacheUtil.getBreakpointCacheLocation().trim(), - false, - false); - operation.run(null); - } - TransformationThreadFactory.getInstance().registerListener(view, vm.getIdentifier()); - } catch (CoreException | InvocationTargetException e) { + } catch (CoreException e) { e.printStackTrace(); } diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/transformationbrowser/AdaptableTransformationBrowser.java b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/transformationbrowser/AdaptableTransformationBrowser.java index e6dfec3ac..0ea2ce3a0 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/transformationbrowser/AdaptableTransformationBrowser.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/views/transformationbrowser/AdaptableTransformationBrowser.java @@ -15,16 +15,23 @@ import java.util.List; import java.util.Map; import org.eclipse.jface.viewers.IContentProvider; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.part.ViewPart; import org.eclipse.viatra.transformation.debug.model.ITransformationStateListener; +import org.eclipse.viatra.transformation.debug.model.TransformationStackFrame; import org.eclipse.viatra.transformation.debug.model.TransformationState; +import org.eclipse.viatra.transformation.debug.model.TransformationThread; import org.eclipse.viatra.transformation.debug.model.TransformationThreadFactory; import org.eclipse.viatra.transformation.evm.api.Activation; import org.eclipse.viatra.transformation.evm.api.RuleSpecification; @@ -46,12 +53,14 @@ public class AdaptableTransformationBrowser extends ViewPart private Multimap<Class<?>, Object> expandedElementsMap = ArrayListMultimap.create(); private TreeViewer treeViewer; private Object selection; - +// private ISelectionListener listener; + private ISelectionService sService; + @Override public void createPartControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new FillLayout(SWT.HORIZONTAL)); - + sService = getSite().getWorkbenchWindow().getSelectionService(); treeViewer = new TreeViewer(composite, SWT.BORDER); treeViewer.setContentProvider(new RuleBrowserContentProvider(this)); @@ -67,8 +76,28 @@ public class AdaptableTransformationBrowser extends ViewPart } } }); - + +// listener = new ISelectionListener() { +// @Override +// public void selectionChanged(IWorkbenchPart part, ISelection selection) { +// if (!selection.isEmpty() && selection instanceof StructuredSelection) { +// Object firstElement = ((StructuredSelection) selection).getFirstElement(); +// if (firstElement instanceof TransformationThread) { +// treeViewer.setSelection(new StructuredSelection(((TransformationThread) firstElement).getAdaptableEvm())); +// } else if (firstElement instanceof TransformationStackFrame){ +// treeViewer.setSelection(new StructuredSelection(((TransformationThread) ((TransformationStackFrame) firstElement).getThread()).getAdaptableEvm())); +// } +// } +// +// } +// }; + + + getSite().setSelectionProvider(treeViewer); AdaptableEVMFactory.getInstance().registerListener(this); + +// sService.addSelectionListener("org.eclipse.debug.ui.DebugView", listener); + } @Override @@ -221,5 +250,5 @@ public class AdaptableTransformationBrowser extends ViewPart return elements.toArray(new Object[elements.size()]); } - } + } } diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug/META-INF/MANIFEST.MF b/transformation/plugins/org.eclipse.viatra.transformation.debug/META-INF/MANIFEST.MF index 200b8bef0..ed3d4ea50 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug/META-INF/MANIFEST.MF +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug/META-INF/MANIFEST.MF @@ -16,6 +16,7 @@ Require-Bundle: org.eclipse.viatra.query.runtime;bundle-version="[1.3.0,1.4.0)", org.eclipse.emf.edit, org.eclipse.emf.edit.ui, org.eclipse.xtext.ui;bundle-version="2.9.2", + org.eclipse.debug.ui, org.eclipse.viatra.query.patternlanguage.emf.ui Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.viatra.transformation.debug, diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/activator/TransformationDebugActivator.java b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/activator/TransformationDebugActivator.java new file mode 100644 index 000000000..37672631d --- /dev/null +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/activator/TransformationDebugActivator.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2010-2016, Peter Lunk, IncQuery Labs Ltd. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Peter Lunk - initial API and implementation + */ +package org.eclipse.viatra.transformation.debug.activator; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +public class TransformationDebugActivator extends AbstractUIPlugin { + public static final String PLUGIN_ID = "org.eclipse.viatra.transformation.debug"; //$NON-NLS-1$ + + private static TransformationDebugActivator plugin; + + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static TransformationDebugActivator getDefault() { + return plugin; + } + +} diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/TransformationThread.java b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/TransformationThread.java index 9f0e6fa7a..9e4b5f9ac 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/TransformationThread.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/TransformationThread.java @@ -10,6 +10,7 @@ */ package org.eclipse.viatra.transformation.debug.model; +import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.Set; @@ -22,6 +23,8 @@ import org.eclipse.debug.core.IBreakpointListener; import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IThread; +import org.eclipse.debug.ui.actions.ExportBreakpointsOperation; +import org.eclipse.debug.ui.actions.ImportBreakpointsOperation; import org.eclipse.jdt.core.IType; import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; import org.eclipse.viatra.transformation.debug.DebuggerActions; @@ -29,12 +32,14 @@ import org.eclipse.viatra.transformation.debug.ITransformationDebugListener; import org.eclipse.viatra.transformation.debug.TransformationDebugger; import org.eclipse.viatra.transformation.debug.model.breakpoint.ConditionalTransformationBreakpoint; import org.eclipse.viatra.transformation.debug.model.breakpoint.ITransformationBreakpoint; +import org.eclipse.viatra.transformation.debug.util.BreakpointCacheUtil; import org.eclipse.viatra.transformation.evm.api.Activation; import org.eclipse.viatra.transformation.evm.api.RuleSpecification; import org.eclipse.viatra.transformation.evm.api.adapter.AdaptableEVM; import org.eclipse.viatra.transformation.evm.api.event.EventFilter; import org.eclipse.xtext.xbase.lib.Pair; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; public class TransformationThread extends TransformationDebugElement implements IThread, ITransformationDebugListener, IBreakpointListener { @@ -55,11 +60,27 @@ public class TransformationThread extends TransformationDebugElement implements protected TransformationThread(TransformationDebugTarget target, TransformationDebugger debugger, AdaptableEVM evm, IType transformationType) { super(target); + Preconditions.checkNotNull(debugger, "Viatra Debugger must not be null."); + Preconditions.checkNotNull(evm, "Adaptable EVM instance must not be null."); + Preconditions.checkNotNull(transformationType, "Transformation Class must not be null."); this.debugger = debugger; this.evm = evm; this.transformationType = transformationType; this.state = debugger.registerTransformationDebugListener(this); DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); + + + if(BreakpointCacheUtil.breakpointCacheExists()){ + ImportBreakpointsOperation operation = new ImportBreakpointsOperation( + BreakpointCacheUtil.getBreakpointCacheLocation().trim(), + false, + false); + try { + operation.run(null); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } } @Override @@ -223,11 +244,6 @@ public class TransformationThread extends TransformationDebugElement implements public void terminated() throws CoreException, DebugException { terminated = true; DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this); - for (ITransformationBreakpoint iTransformationBreakpoint : breakpoints) { - debugger.removeBreakpoint(iTransformationBreakpoint); - DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(iTransformationBreakpoint, true); - } - breakpoints.clear(); fireTerminateEvent(); try { ((TransformationDebugTarget) getDebugTarget()).requestTermination(); @@ -237,12 +253,12 @@ public class TransformationThread extends TransformationDebugElement implements for (ITransformationStateListener listener : stateListeners) { listener.transformationStateDisposed(state, evm.getIdentifier()); } + dispose(); } - protected void dispose(){ - + protected void dispose(){ stateListeners.clear(); TransformationThreadFactory.getInstance().deleteTransformationThread(this); } @@ -291,8 +307,10 @@ public class TransformationThread extends TransformationDebugElement implements } public void registerTransformationStateListener(ITransformationStateListener listener) { - stateListeners.add(listener); - notifyListeners(state); + if(!stateListeners.contains(listener)){ + stateListeners.add(listener); + notifyListeners(state); + } } public void unRegisterTransformationStateListener(ITransformationStateListener listener) { @@ -338,6 +356,16 @@ public class TransformationThread extends TransformationDebugElement implements } breakpoints.add((ITransformationBreakpoint) breakpoint); debugger.addBreakpoint((ITransformationBreakpoint) breakpoint); + + ExportBreakpointsOperation operation = new ExportBreakpointsOperation( + BreakpointCacheUtil.filterBreakpoints(getBreakpoints()), + BreakpointCacheUtil.getBreakpointCacheLocation()); + + try { + operation.run(null); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } } } @@ -346,6 +374,16 @@ public class TransformationThread extends TransformationDebugElement implements if(breakpoint instanceof ITransformationBreakpoint){ breakpoints.remove(breakpoint); debugger.removeBreakpoint((ITransformationBreakpoint) breakpoint); + + ExportBreakpointsOperation operation = new ExportBreakpointsOperation( + BreakpointCacheUtil.filterBreakpoints(getBreakpoints()), + BreakpointCacheUtil.getBreakpointCacheLocation()); + + try { + operation.run(null); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } } } diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/TransformationThreadFactory.java b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/TransformationThreadFactory.java index 7d7dc98b1..62503c16a 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/TransformationThreadFactory.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/TransformationThreadFactory.java @@ -79,6 +79,10 @@ public class TransformationThreadFactory { } catch (NoSuchElementException | DebugException e) { throw e; } + if(!listenersToAdd.containsEntry(id, listener)){ + listenersToAdd.put(id, listener); + } + } public void unRegisterListener(ITransformationStateListener listener){ diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/breakpoint/ConditionalTransformationBreakpoint.java b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/breakpoint/ConditionalTransformationBreakpoint.java index 22aeb55f7..d6fe3445f 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/breakpoint/ConditionalTransformationBreakpoint.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/breakpoint/ConditionalTransformationBreakpoint.java @@ -46,8 +46,11 @@ import com.google.inject.Injector; public class ConditionalTransformationBreakpoint extends Breakpoint implements ITransformationBreakpoint, IMatchUpdateListener { private AdvancedViatraQueryEngine engine; private String patternString; + private String toString; private boolean matcherChanged = false; + + public ConditionalTransformationBreakpoint() { super(); } @@ -107,10 +110,12 @@ public class ConditionalTransformationBreakpoint extends Breakpoint implements I public void setEngine(ViatraQueryEngine engine) { this.engine = AdvancedViatraQueryEngine.from(engine); + toString = "Conditional Transformation Breakpoint - "; ViatraQueryMatcher<? extends IPatternMatch> matcher; try { List<IQuerySpecification<?>> parsePatterns = parsePatterns(); for (IQuerySpecification<?> iQuerySpecification : parsePatterns) { + toString += "Query specification name: "+iQuerySpecification.getFullyQualifiedName(); matcher = engine.getMatcher(iQuerySpecification); this.engine.addMatchUpdateListener(matcher, this, false); } @@ -146,5 +151,10 @@ public class ConditionalTransformationBreakpoint extends Breakpoint implements I } return null; } + + @Override + public String toString() { + return toString; + } } diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/breakpoint/RuleBreakpoint.java b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/breakpoint/RuleBreakpoint.java index 0e78fd56f..e95312d2e 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/breakpoint/RuleBreakpoint.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/model/breakpoint/RuleBreakpoint.java @@ -16,12 +16,12 @@ import org.eclipse.debug.core.model.Breakpoint; import org.eclipse.viatra.transformation.debug.model.TransformationDebugElement; import org.eclipse.viatra.transformation.evm.api.Activation; -public class RuleBreakpoint extends Breakpoint implements ITransformationBreakpoint{ +public class RuleBreakpoint extends Breakpoint implements ITransformationBreakpoint { private String ruleId; - public RuleBreakpoint() {} - - + public RuleBreakpoint() { + } + public RuleBreakpoint(String ruleId) { super(); this.ruleId = ruleId; @@ -34,34 +34,39 @@ public class RuleBreakpoint extends Breakpoint implements ITransformationBreakpo @Override public boolean shouldBreak(Activation<?> a) { - return a.getInstance().getSpecification().getName().equals(ruleId); + return a.getInstance().getSpecification().getName().equals(ruleId); } @Override public String getMarkerIdentifier() { return RULE; } - + @Override public boolean equals(Object item) { - if(item instanceof RuleBreakpoint){ + if (item instanceof RuleBreakpoint) { return ((RuleBreakpoint) item).getRuleId().equals(getRuleId()); - } else{ + } else { return false; } } - + protected String getRuleId() { return ruleId; } - -@Override + + @Override public void setMarker(IMarker marker) throws CoreException { super.setMarker(marker); - if(ruleId != null){ + if (ruleId != null) { marker.setAttribute("content", ruleId); - }else{ + } else { ruleId = marker.getAttribute("content", ruleId); } } + + @Override + public String toString() { + return "Rule Transformation Breakpoint - Rule name: "+ruleId; + } } diff --git a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/util/BreakpointCacheUtil.java b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/util/BreakpointCacheUtil.java index 08e055271..1a0258360 100644 --- a/transformation/plugins/org.eclipse.viatra.transformation.debug.ui/src/org/eclipse/viatra/transformation/debug/ui/util/BreakpointCacheUtil.java +++ b/transformation/plugins/org.eclipse.viatra.transformation.debug/src/org/eclipse/viatra/transformation/debug/util/BreakpointCacheUtil.java @@ -8,23 +8,23 @@ * Contributors: * Peter Lunk - initial API and implementation */ -package org.eclipse.viatra.transformation.debug.ui.util; +package org.eclipse.viatra.transformation.debug.util; import java.io.File; import java.util.List; import org.eclipse.core.runtime.IPath; import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.viatra.transformation.debug.activator.TransformationDebugActivator; import org.eclipse.viatra.transformation.debug.model.breakpoint.ConditionalTransformationBreakpoint; import org.eclipse.viatra.transformation.debug.model.breakpoint.RuleBreakpoint; -import org.eclipse.viatra.transformation.debug.ui.activator.TransformationDebugUIActivator; import com.google.common.collect.Lists; public class BreakpointCacheUtil { public static String getBreakpointCacheLocation(){ - TransformationDebugUIActivator activator = new TransformationDebugUIActivator(); + TransformationDebugActivator activator = new TransformationDebugActivator(); IPath stateLocation = activator.getStateLocation(); String location = stateLocation.toString(); String fileLocation = location+"/persistentbreakpoints.brpkt"; |