From 9608e213d6c510f78bf7e823fa75da92a333a9ee Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Mon, 2 Jan 2012 10:50:12 +0000 Subject: [PATCH] added constraints for af3.expression added double-click feature to marker service refs 436 --- .../internal/ModelEditorBindingService.java | 18 +++++-- .../kernel/ui/internal/views/DoubleClick.java | 49 +++++++++++++++++++ .../ui/internal/views/MarkerViewPart.java | 3 +- .../ui/internal/views/NavigatorViewPart.java | 23 ++------- .../base/ConstraintViolationBase.java | 11 ++++- .../extension/data/IConstraintViolation.java | 17 +++++-- 6 files changed, 90 insertions(+), 31 deletions(-) create mode 100644 org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/DoubleClick.java diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java index eea2b71b2..b9fb2c513 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import org.conqat.lib.commons.collections.CollectionUtils; +import org.eclipse.core.runtime.Assert; import org.eclipse.emf.common.command.CommandStackListener; import org.eclipse.emf.ecore.EObject; import org.eclipse.ui.IEditorPart; @@ -43,8 +44,8 @@ import org.fortiss.tooling.kernel.ui.extension.IModelEditorBinding; import org.fortiss.tooling.kernel.ui.internal.editor.ExtendableMultiPageEditor; import org.fortiss.tooling.kernel.ui.internal.editor.ModelElementEditorInput; import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService; -import org.fortiss.tooling.kernel.utils.LoggingUtils; import org.fortiss.tooling.kernel.utils.KernelModelElementUtils; +import org.fortiss.tooling.kernel.utils.LoggingUtils; /** * This class implements the {@link IModelEditorBindingService} interface. @@ -52,7 +53,7 @@ import org.fortiss.tooling.kernel.utils.KernelModelElementUtils; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating YELLOW Hash: A842DA4DA68483EDE3410085E5A0628F + * @ConQAT.Rating YELLOW Hash: B22AF6BFF05488F229A48209695AF5F9 */ public class ModelEditorBindingService extends EObjectAwareServiceBase<IModelEditorBinding<EObject>> implements @@ -86,7 +87,16 @@ public class ModelEditorBindingService extends /** {@inheritDoc} */ @Override public void openInEditor(EObject element) { + openInEditor(element, 2); + } + + /** Opens the editor or proceeds with parent element. */ + private void openInEditor(EObject element, int depth) { + Assert.isTrue(depth >= 0); if (getBindings(element).isEmpty()) { + if (depth > 0 && element.eContainer() != null) { + openInEditor(element.eContainer(), depth - 1); + } return; } try { @@ -159,8 +169,8 @@ public class ModelEditorBindingService extends public void closeEditors(EObject parentElement) { for (IEditorPart editor : currentEditors.keySet()) { EObject editedElement = currentEditors.get(editor); - if (KernelModelElementUtils - .isChildElementOf(editedElement, parentElement)) { + if (KernelModelElementUtils.isChildElementOf(editedElement, + parentElement)) { closeEditor(editor); } } diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/DoubleClick.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/DoubleClick.java new file mode 100644 index 000000000..159a82047 --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/DoubleClick.java @@ -0,0 +1,49 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2012 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.kernel.ui.internal.views; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService; +import org.fortiss.tooling.kernel.ui.util.EObjectSelectionUtils; + +/** + * Double-click listener for navigator and marker view. + * + * @author hoelzl + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating YELLOW Hash: 53A68C6E1A420B57E77FAF9B3E1B472A + */ +final class DoubleClick implements IDoubleClickListener { + + /** {@inheritDoc} */ + @Override + public void doubleClick(DoubleClickEvent event) { + // delegate to the editor service + if (event.getSelection() instanceof IStructuredSelection) { + EObject element = EObjectSelectionUtils.getFirstElement(event + .getSelection()); + if (element != null) { + IModelEditorBindingService.INSTANCE.openInEditor(element); + } + } + } +} diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/MarkerViewPart.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/MarkerViewPart.java index 159854b72..04c93f343 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/MarkerViewPart.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/MarkerViewPart.java @@ -54,7 +54,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating YELLOW Hash: 95A61D97067260DAA89DB0B0D46DC436 + * @ConQAT.Rating YELLOW Hash: 8E0E8EEE1C47D3C3885B66756CABB8A6 */ public class MarkerViewPart extends ViewPart { @@ -187,6 +187,7 @@ public class MarkerViewPart extends ViewPart { } }); + gui.getTreeViewer().addDoubleClickListener(new DoubleClick()); gui.getTreeViewer().setInput(IMarkerService.INSTANCE); createToggleActions(); diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java index ff130561f..6a3081de2 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java @@ -26,11 +26,8 @@ import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.viewers.DecoratingLabelProvider; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IDoubleClickListener; 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; @@ -61,7 +58,6 @@ import org.fortiss.tooling.kernel.ui.internal.editor.ModelElementEditorInput; import org.fortiss.tooling.kernel.ui.presentation.ModelElementLabelProvider; import org.fortiss.tooling.kernel.ui.service.IActionService; import org.fortiss.tooling.kernel.ui.service.IContextMenuService; -import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService; import org.fortiss.tooling.kernel.ui.service.INavigatorService; import org.fortiss.tooling.kernel.ui.util.EObjectSelectionUtils; import org.fortiss.tooling.kernel.ui.util.PropertiesConstantUtils; @@ -72,10 +68,10 @@ import org.fortiss.tooling.kernel.ui.util.PropertiesConstantUtils; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating YELLOW Hash: F3E7AFD73EE644B6A2076DC96F4D0048 + * @ConQAT.Rating YELLOW Hash: ACD21394DB82D14D4F491169376384D8 */ public final class NavigatorViewPart extends ViewPart implements - ISelectionListener, ISelectionChangedListener, IDoubleClickListener, + ISelectionListener, ISelectionChangedListener, ITabbedPropertySheetPageContributor, ContextMenuContextProvider, ISaveablesSource, ISaveablePart { @@ -141,7 +137,7 @@ public final class NavigatorViewPart extends ViewPart implements viewer.setInput(IPersistencyService.INSTANCE); - viewer.addDoubleClickListener(this); + viewer.addDoubleClickListener(new DoubleClick()); IActionService.INSTANCE.registerGlobalActions(getViewSite() .getActionBars()); @@ -273,19 +269,6 @@ public final class NavigatorViewPart extends ViewPart implements super.dispose(); } - /** {@inheritDoc} */ - @Override - public void doubleClick(DoubleClickEvent event) { - // delegate to the editor service - if (event.getSelection() instanceof IStructuredSelection) { - EObject element = EObjectSelectionUtils.getFirstElement(event - .getSelection()); - if (element != null) { - IModelEditorBindingService.INSTANCE.openInEditor(element); - } - } - } - /** {@inheritDoc} */ @Override public String getContributorId() { diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/ConstraintViolationBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/ConstraintViolationBase.java index 11c5a671d..25b87cba1 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/ConstraintViolationBase.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/base/ConstraintViolationBase.java @@ -29,7 +29,7 @@ import org.fortiss.tooling.kernel.extension.data.IConstraintViolation; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating YELLOW Hash: 1A36E001A5464667E3FC4A57AB2FEB29 + * @ConQAT.Rating YELLOW Hash: 9DA8E3ED348BEB666713A27DF89CBD64 */ public class ConstraintViolationBase<T extends EObject> implements IConstraintViolation<T> { @@ -74,4 +74,13 @@ public class ConstraintViolationBase<T extends EObject> implements public IQuickFixHandler getQuickFixHandler() { return null; } + + /** {@inheritDoc} */ + @Override + public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { + if (adapter == EObject.class) { + return getSource(); + } + return null; + } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/IConstraintViolation.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/IConstraintViolation.java index f49ef4510..65ecad005 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/IConstraintViolation.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/IConstraintViolation.java @@ -19,20 +19,27 @@ package org.fortiss.tooling.kernel.extension.data; import java.util.Comparator; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.extension.base.ConstraintViolationBase; /** * This interface describes a constraint violation produced by some constraint - * checker. A constraint violation has a severity of type {@link ESeverity}, an - * explanation of type String and possibly a quick fix handler of type - * {@link IQuickFixHandler}. + * checker. A constraint violation has a source object, a severity of type + * {@link ESeverity}, an explanation of type String and possibly a quick fix + * handler of type {@link IQuickFixHandler}. + * <p> + * Sub-classes should adapt to {@link EObject} in {@link #getAdapter(Class)} and + * return the source element. + * + * @see ConstraintViolationBase * * @author hoelzlf * @author $Author$ * @version $Rev$ - * @ConQAT.Rating GREEN Hash: 6340788DB3948AD781A97861749504DB + * @ConQAT.Rating YELLOW Hash: 11AEB121B98133BB02808AA44C0BFFDB */ -public interface IConstraintViolation<T extends EObject> { +public interface IConstraintViolation<T extends EObject> extends IAdaptable { /** Returns the source of the constraint violation. */ T getSource(); -- GitLab