diff --git a/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF index 95b10c8ffbb64bd47f318d9de17399482740e528..3376f5672017783fb8e19e38a2099a36336d73d2 100644 --- a/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF @@ -6,11 +6,14 @@ Bundle-Version: 0.0.1.qualifier Bundle-Activator: org.fortiss.tooling.kernel.ToolingKernelActivator Bundle-Vendor: fortiss Require-Bundle: org.eclipse.core.runtime;visibility:=reexport, + org.eclipse.core.databinding;visibility:=reexport, org.eclipse.ui;visibility:=reexport, org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100";visibility:=reexport, org.eclipse.emf.ecore;bundle-version="2.6.1";visibility:=reexport, + org.eclipse.gef;visibility:=reexport, org.conqat.ide.commons;bundle-version="2.7.0";visibility:=reexport, org.conqat.ide.commons.ui;bundle-version="2.7.0";visibility:=reexport, + org.conqat.ide.commons.gef;bundle-version="2.7.0", org.unicase.workspace, org.unicase.ecp.model, org.unicase.ui.common, diff --git a/org.fortiss.tooling.kernel/trunk/plugin.xml b/org.fortiss.tooling.kernel/trunk/plugin.xml index e83075af4ab1fd5ba12b03ff5ce5a7de02d91d7f..e6573c42a08454ba738fdd3987190e2a4d051b27 100644 --- a/org.fortiss.tooling.kernel/trunk/plugin.xml +++ b/org.fortiss.tooling.kernel/trunk/plugin.xml @@ -107,6 +107,66 @@ </menu> </menuContribution> </extension> + <extension + point="org.eclipse.core.runtime.adapters"> + <factory + adaptableType="org.eclipse.emf.ecore.EObject" + class="org.fortiss.tooling.kernel.internal.properties.PropertiesAdapterFactory"> + <adapter + type="org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor"> + </adapter> + </factory> + </extension> + <extension + point="org.eclipse.ui.views.properties.tabbed.propertyContributor"> + <propertyContributor + contributorId="org.fortiss.tooling.kernel.properties.Contributor" + labelProvider="org.fortiss.tooling.kernel.internal.navigator.NavigatorTreeLabelProvider" + typeMapper="org.conqat.ide.commons.gef.properties.EditPartTypeMapper"> + <propertyCategory + category="main"></propertyCategory> + </propertyContributor> + </extension> + <extension + point="org.eclipse.ui.views.properties.tabbed.propertyTabs"> + <propertyTabs + contributorId="org.fortiss.tooling.kernel.properties.Contributor"> + <propertyTab + category="main" + id="org.fortiss.tooling.kernel.property.tab.general" + label="General"> + </propertyTab> + <propertyTab + afterTab="org.fortiss.tooling.kernel.property.tab.general" + category="main" + id="org.fortiss.tooling.kernel.property.tab.internal" + label="Internal"> + </propertyTab> + </propertyTabs> + </extension> + <extension + point="org.eclipse.ui.views.properties.tabbed.propertySections"> + <propertySections + contributorId="org.fortiss.tooling.kernel.properties.Contributor"> + <propertySection + class="org.fortiss.tooling.kernel.internal.properties.IdLabeledPropertySection" + enablesFor="1" + id="org.fortiss.tooling.kernel.internal.properties.IdLabeledPropertySection" + tab="org.fortiss.tooling.kernel.property.tab.internal"> + <input + type="org.fortiss.tooling.kernel.model.IIdLabeled"> + </input> + </propertySection> + <propertySection + class="org.fortiss.tooling.kernel.internal.properties.NamedCommentedPropertySection" + id="org.fortiss.tooling.kernel.internal.properties.NamedCommentedPropertySection" + tab="org.fortiss.tooling.kernel.property.tab.general"> + <input + type="org.fortiss.tooling.kernel.model.INamedCommentedElement"> + </input> + </propertySection> + </propertySections> + </extension> <extension point="org.unicase.ecp.model.ecpModelPackage"> <modelPackage diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java index d24a91887a519af83ff09538073495c2a9f90cb9..befa712f75e51f6417bbd4b8783736afac7962e8 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java @@ -17,6 +17,7 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.base; +import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.ecore.EObject; import org.eclipse.ui.IEditorInput; @@ -48,6 +49,9 @@ public abstract class EditorBase<T extends EObject> extends EditorPart { /** The model element handler to be used with the {@link #editedObject}. */ protected IHandler<T> handler; + /** Databinding context used for model changes. */ + protected final DataBindingContext dbc = new DataBindingContext(); + /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/PropertySectionBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/PropertySectionBase.java new file mode 100644 index 0000000000000000000000000000000000000000..23d7b79b2436ce4ac36a9f175caf91425c9af2ac --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/PropertySectionBase.java @@ -0,0 +1,128 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 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.base; + +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.gef.EditPart; +import org.eclipse.jface.fieldassist.ControlDecoration; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; + +/** + * Base class for property sections, dealing with setting the input and + * providing some utility methods. + * + * @author hoelzl + * @author $Author$ + * @version $Rev$ + * @levd.rating YELLOW Rev: 2675 + */ +public abstract class PropertySectionBase extends AbstractPropertySection { + + /** Label width. */ + public static final int PROPERTIES_LABEL_WIDTH = 150; + + /** The main composite for the controls. */ + protected Composite composite; + + /** Stores the data binding context used. */ + protected DataBindingContext dbc = new DataBindingContext(); + + /** {@inheritDoc} */ + @Override + public void createControls(Composite parent, + TabbedPropertySheetPage tabbedPropertySheetPage) { + super.createControls(parent, tabbedPropertySheetPage); + + composite = getWidgetFactory().createFlatFormComposite(parent); + composite.setLayout(new GridLayout(2, false)); + } + + /** {@inheritDoc} */ + @Override + public void dispose() { + super.dispose(); + } + + /** {@inheritDoc} */ + @Override + public final void setInput(IWorkbenchPart part, ISelection selection) { + super.setInput(part, selection); + + if (!(selection instanceof IStructuredSelection)) { + return; + } + Object object = ((IStructuredSelection) selection).getFirstElement(); + if (object instanceof EditPart) { + object = ((EditPart) object).getModel(); + } + setSectionInput(object); + } + + /** This is used to set the single section input. The parameter may be null! */ + protected abstract void setSectionInput(Object input); + + /** + * Creates a text widget, which has a {@link ControlDecoration} attached. + * The decoration is stored as widget data for convenience. + */ + protected Text createDecoratedText(String labelText) { + // final Text text = createFormText(labelText); + // text.setData(DataBindingUtils.DECORATION_KEY, new ControlDecoration( + // text, SWT.LEFT | SWT.TOP)); + // return text; + return null; + } + + /** Creates form text field. */ + protected Text createFormText(String labelText) { + Text text = getWidgetFactory().createText(composite, ""); + createFormEntry(text, labelText); + return text; + } + + /** + * Creates a form entry. + */ + protected void createFormEntry(Control control, String labelName) { + labelName = labelName.trim(); + if (labelName.endsWith(":")) { + labelName = labelName.replaceAll(":$", ""); + } + + Label label = getWidgetFactory().createLabel(composite, labelName); + label.moveAbove(control); + GridDataFactory.defaultsFor(label) + .hint(PROPERTIES_LABEL_WIDTH, SWT.DEFAULT) + .align(SWT.BEGINNING, SWT.BEGINNING).applyTo(label); + GridData gd = GridDataFactory.defaultsFor(control).create(); + gd.heightHint = Math.min(50, gd.heightHint); + control.setLayoutData(gd); + } +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/databinding/EObjectObservableValue.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/databinding/EObjectObservableValue.java new file mode 100644 index 0000000000000000000000000000000000000000..6548fe3bf094a798b569cbd1c5e86a8ad8eb1e0e --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/databinding/EObjectObservableValue.java @@ -0,0 +1,128 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 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.databinding; + +import org.eclipse.core.databinding.observable.Diffs; +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.value.AbstractObservableValue; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.swt.widgets.Display; +import org.fortiss.tooling.kernel.services.ICommandStackService; + +/** + * Implementation of {@link IObservableValue} for {@link EObject}s. + * + * @author hummelb + * @author $Author$ + * @version $Rev$ + * @levd.rating YELLOW Rev: 2942 + */ +public class EObjectObservableValue extends AbstractObservableValue { + + /** The wrapped object. */ + private final EObject eObject; + + /** The wrapped structural feature. */ + private final EStructuralFeature structuralFeature; + + /** Flag used for detecting our own updates. */ + private boolean updating = false; + + /** The adapter for sending change events. */ + private final Adapter modelChangeAdapter = new AdapterImpl() { + /** {@inheritDoc} */ + @Override + public void notifyChanged(final Notification msg) { + if (!updating && msg.getFeature() == structuralFeature) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + fireValueChange(Diffs.createValueDiff( + msg.getOldValue(), msg.getNewValue())); + } + }); + } + } + }; + + /** Constructor. */ + public EObjectObservableValue(Realm realm, EObject eObject, + EStructuralFeature structuralFeature) { + super(realm); + this.eObject = eObject; + this.structuralFeature = structuralFeature; + + eObject.eAdapters().add(modelChangeAdapter); + } + + /** {@inheritDoc} */ + @Override + public synchronized void dispose() { + eObject.eAdapters().remove(modelChangeAdapter); + super.dispose(); + } + + /** {@inheritDoc} */ + @Override + protected Object doGetValue() { + return eObject.eGet(structuralFeature); + } + + /** {@inheritDoc} */ + @Override + protected void doSetValue(final Object value) { + Object oldValue = doGetValue(); + if (oldValue == null && value == null || oldValue != null + && oldValue.equals(value)) { + return; + } + + updating = true; + ICommandStackService.INSTANCE.runAsCommand(eObject, new Runnable() { + @Override + public void run() { + eObject.eSet(structuralFeature, value); + } + }); + updating = false; + } + + /** {@inheritDoc} */ + @Override + public Object getValueType() { + if (structuralFeature.isMany()) { + return EList.class; + } + + if (structuralFeature instanceof EAttribute) { + return ((EAttribute) structuralFeature).getEAttributeType() + .getInstanceClass(); + } + return ((EReference) structuralFeature).getEReferenceType() + .getInstanceClass(); + } + +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/databinding/Observables.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/databinding/Observables.java new file mode 100644 index 0000000000000000000000000000000000000000..8007c04ec81ffcdbb5f054046c264a241ebda9ad --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/databinding/Observables.java @@ -0,0 +1,48 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 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.databinding; + +import org.conqat.lib.commons.assertion.CCSMPre; +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * Observerables for EObject models. + * + * @author hummelb + * @author $Author$ + * @version $Rev$ + * @levd.rating GREEN Rev: 3427 + */ +public class Observables { + + /** Returns an observable for the given object and structural feature. */ + public static IObservableValue observeValue(EObject eObject, + EStructuralFeature structuralFeature) { + return observeValue(Realm.getDefault(), eObject, structuralFeature); + } + + /** Returns an observable for the given object and structural feature. */ + public static IObservableValue observeValue(Realm realm, EObject eObject, + EStructuralFeature structuralFeature) { + CCSMPre.isTrue(eObject != null, "Can not observe null value!"); + return new EObjectObservableValue(realm, eObject, structuralFeature); + } +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ICompositionContext.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ICompositionContext.java index 231f7902a73c018a7134fa32d294c0ac55f231b9..cc00aa7373ae3d8e0acdf98ab74ea7ccd40de45f 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ICompositionContext.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ICompositionContext.java @@ -1,4 +1,5 @@ /*--------------------------------------------------------------------------+ + $Id$ | | | Copyright 2011 ForTISS GmbH | diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/editor/BindingEditor.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/editor/BindingEditor.java index 21be42326f4154c19f48859565f547b419536c43..32560686680e0f8221af81ea11590e6c043346c2 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/editor/BindingEditor.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/editor/BindingEditor.java @@ -1,17 +1,20 @@ -/*-----------------------------------------------------------------------+ - | edu.tum.cs.ccts.model.base - | | - $Id$ - | | - | Copyright (c) 2004-2008 Technische Universitaet Muenchen | - | | - | Technische Universitaet Muenchen ######### ########## | - | Institut fuer Informatik - Lehrstuhl IV ## ## ## ## ## | - | Prof. Dr. Manfred Broy ## ## ## ## ## | - | Boltzmannstr. 3 ## ## ## ## ## | - | 85748 Garching bei Muenchen ## ## ## ## ## | - | Germany ## ###### ## ## | - +-----------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 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.internal.editor; import org.conqat.ide.commons.ui.logging.LoggingUtils; @@ -33,6 +36,7 @@ import org.fortiss.tooling.kernel.ToolingKernelActivator; import org.fortiss.tooling.kernel.interfaces.IEditorBinding; import org.fortiss.tooling.kernel.interfaces.IHandler; import org.fortiss.tooling.kernel.services.IEditorService; +import org.fortiss.tooling.kernel.services.IPropertiesService; /** * This editor is used for displaying multiple editors provided by editor @@ -49,10 +53,6 @@ public class BindingEditor extends MultiPageEditorPart implements /** The editor's ID. */ public static String ID = BindingEditor.class.getName(); - // TODO (FH): change this - /** The tabbed property sheet contributor ID. */ - public static final String TABBED_PROPERTY_CONTRIBUTOR_ID = "edu.tum.cs.ccts.model.base.properties.Contributor"; - /** * The object shown in this editor. This is valid as soon as * {@link #init(IEditorSite, IEditorInput)} has been called. @@ -177,7 +177,7 @@ public class BindingEditor extends MultiPageEditorPart implements */ @Override public String getContributorId() { - return TABBED_PROPERTY_CONTRIBUTOR_ID; + return IPropertiesService.TABBED_PROPERTY_CONTRIBUTOR_ID; } /** diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java index 945e85e293e34b627f3aeb02542dd9f840875d44..1319e0c8d41eee8f35a910f18e6f05db9dd34888 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java @@ -30,9 +30,7 @@ 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.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; @@ -45,11 +43,15 @@ import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.progress.UIJob; +import org.eclipse.ui.views.properties.IPropertySheetPage; +import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; import org.fortiss.tooling.kernel.ToolingKernelActivator; import org.fortiss.tooling.kernel.internal.NavigatorService; import org.fortiss.tooling.kernel.services.IActionService; import org.fortiss.tooling.kernel.services.IEditorService; import org.fortiss.tooling.kernel.services.INavigatorService; +import org.fortiss.tooling.kernel.services.IPropertiesService; import org.fortiss.tooling.kernel.util.EObjectSelectionUtils; import org.unicase.ecp.model.ECPWorkspaceManager; import org.unicase.ecp.model.NoWorkspaceException; @@ -67,7 +69,8 @@ import org.unicase.ecp.model.workSpaceModel.WorkSpaceModelPackage; * @levd.rating RED Rev: */ public final class NavigatorViewPart extends ViewPart implements - ISelectionListener, ISelectionChangedListener, IDoubleClickListener { + ISelectionListener, IDoubleClickListener, + ITabbedPropertySheetPageContributor { /** Stores the TreeViewer. */ private TreeViewer viewer; @@ -234,26 +237,12 @@ public final class NavigatorViewPart extends ViewPart implements /** {@inheritDoc} */ @Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { - IActionService.INSTANCE.update(); - // TODO (FH): implement link with editor feature here - } - - /** {@inheritDoc} */ - @Override - public void selectionChanged(SelectionChangedEvent event) { EObject selectedElement = EObjectSelectionUtils .getCurrentSelectionFirstElement(); if (selectedElement != null) { IActionService.INSTANCE.update(); } - - // if (event.getSelection() instanceof IStructuredSelection) { - // IStructuredSelection selection = (IStructuredSelection) event - // .getSelection(); - // Object obj = selection.getFirstElement(); - // FIXME: Whats that good for? - // setActiveECPProject(obj); - // } + // TODO (FH): implement link with editor feature here } /** Sets the active ECPProject element. */ @@ -299,4 +288,22 @@ public final class NavigatorViewPart extends ViewPart implements } } } + + /** {@inheritDoc} */ + @Override + public String getContributorId() { + return IPropertiesService.TABBED_PROPERTY_CONTRIBUTOR_ID; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if (adapter == IPropertySheetPage.class) { + return new TabbedPropertySheetPage(this); + } + return super.getAdapter(adapter); + } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/IdLabeledPropertySection.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/IdLabeledPropertySection.java new file mode 100644 index 0000000000000000000000000000000000000000..50b96836a3d3774b859e4ec430709fe9d2872ee9 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/IdLabeledPropertySection.java @@ -0,0 +1,73 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 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.internal.properties; + +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; +import org.fortiss.tooling.kernel.base.PropertySectionBase; +import org.fortiss.tooling.kernel.databinding.Observables; +import org.fortiss.tooling.kernel.model.FortissToolingKernelPackage; +import org.fortiss.tooling.kernel.model.IIdLabeled; + +/** + * Property section for {@link IIdLabeled} objects. + * + * @author hummelb + * @author $Author$ + * @version $Rev$ + * @levd.rating YELLOW Rev: 2675 + */ +public class IdLabeledPropertySection extends PropertySectionBase { + + /** The viewed object. */ + private IIdLabeled idLabeled; + + /** The text used for showing the ID. */ + private Text idText; + + /** {@inheritDoc} */ + @Override + public void createControls(Composite parent, + TabbedPropertySheetPage aTabbedPropertySheetPage) { + super.createControls(parent, aTabbedPropertySheetPage); + + idText = createFormText("ID"); + idText.setEnabled(false); + } + + /** {@inheritDoc} */ + @Override + protected void setSectionInput(Object input) { + idLabeled = (IIdLabeled) input; + } + + /** {@inheritDoc} */ + @Override + public void refresh() { + super.refresh(); + + IObservableValue modelObservable = Observables.observeValue(idLabeled, + FortissToolingKernelPackage.Literals.IID_LABELED__ID); + dbc.bindValue(SWTObservables.observeText(idText, SWT.None), + modelObservable, null, null); + } +} \ No newline at end of file diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/NamedCommentedPropertySection.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/NamedCommentedPropertySection.java new file mode 100644 index 0000000000000000000000000000000000000000..bcad8a2e5de93534ab3d927593e1289ec7c85762 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/NamedCommentedPropertySection.java @@ -0,0 +1,94 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 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.internal.properties; + +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; +import org.fortiss.tooling.kernel.base.PropertySectionBase; +import org.fortiss.tooling.kernel.databinding.Observables; +import org.fortiss.tooling.kernel.model.FortissToolingKernelPackage; +import org.fortiss.tooling.kernel.model.INamedCommentedElement; + +/** + * Property section for {@link INamedCommentedElement} objects. + * + * @author hummelb + * @author ratiu + * @author $Author$ + * @version $Rev$ + * @levd.rating YELLOW Rev: 2676 + */ +public class NamedCommentedPropertySection extends PropertySectionBase { + + /** Name edit widget. */ + private Text nameText; + + /** Comment edit widget. */ + private Text commentText; + + /** Model object. */ + protected INamedCommentedElement namedCommented; + + /** Constructor. */ + public NamedCommentedPropertySection() { + super(); + } + + /** + * {@inheritDoc} + */ + @Override + public void createControls(Composite parent, + TabbedPropertySheetPage aTabbedPropertySheetPage) { + super.createControls(parent, aTabbedPropertySheetPage); + + nameText = createFormText("Name"); + commentText = createFormText("Comment"); + } + + /** + * {@inheritDoc} + */ + @Override + protected void setSectionInput(Object input) { + namedCommented = (INamedCommentedElement) input; + } + + /** {@inheritDoc} */ + @Override + public void refresh() { + super.refresh(); + + IObservableValue modelObservable = Observables.observeValue( + namedCommented, + FortissToolingKernelPackage.Literals.INAMED_ELEMENT__NAME); + dbc.bindValue(SWTObservables.observeText(nameText, SWT.FocusOut), + modelObservable, null, null); + modelObservable = Observables + .observeValue( + namedCommented, + FortissToolingKernelPackage.Literals.INAMED_COMMENTED_ELEMENT__COMMENT); + dbc.bindValue(SWTObservables.observeText(commentText, SWT.FocusOut), + modelObservable, null, null); + } + +} \ No newline at end of file diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/PropertiesAdapterFactory.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/PropertiesAdapterFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..7ccda92448e1737e9010db10a931836969aba584 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/PropertiesAdapterFactory.java @@ -0,0 +1,62 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 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.internal.properties; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor; +import org.fortiss.tooling.kernel.services.IPropertiesService; +import org.fortiss.tooling.kernel.util.ProjectRootElementUtils; + +/** + * Adapter factory for tabbed property sheets. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +@SuppressWarnings("rawtypes") +public final class PropertiesAdapterFactory implements IAdapterFactory { + + /** {@inheritDoc} */ + @Override + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adapterType == ITabbedPropertySheetPageContributor.class + && adaptableObject instanceof EObject) { + EObject modelElement = (EObject) adaptableObject; + if (ProjectRootElementUtils.getECPProject(modelElement) != null) { + return new ITabbedPropertySheetPageContributor() { + + @Override + public String getContributorId() { + return IPropertiesService.TABBED_PROPERTY_CONTRIBUTOR_ID; + } + }; + } + } + return null; + } + + /** {@inheritDoc} */ + @Override + public Class[] getAdapterList() { + return new Class[] { ITabbedPropertySheetPageContributor.class }; + } + +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPropertiesService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPropertiesService.java index d5fdebf85a9931809277d7ee23f952c8674d13e3..48b7edffa7c8b1512e47a940f915e635a5adacc1 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPropertiesService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPropertiesService.java @@ -32,5 +32,6 @@ public interface IPropertiesService { /** Returns the singleton instance of the service. */ public static final IPropertiesService INSTANCE = new PropertiesService(); - // TODO (FH): define + /** The tabbed property sheet contributor ID. */ + public static final String TABBED_PROPERTY_CONTRIBUTOR_ID = "org.fortiss.tooling.kernel.properties.Contributor"; } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/DataBindingUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/DataBindingUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..5a086e0936564816310e170e2d54addbec6b65e3 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/DataBindingUtils.java @@ -0,0 +1,102 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 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.util; + +import org.conqat.ide.commons.ui.databinding.JFaceObservables; +import org.eclipse.core.databinding.Binding; +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.UpdateValueStrategy; +import org.eclipse.core.databinding.conversion.IConverter; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.jface.fieldassist.ControlDecoration; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Control; + +/** + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public final class DataBindingUtils { + + /** + * Decoration key for edit feedback. + */ + public static final String DECORATION_KEY = ControlDecoration.class + .getName(); + + /** + * Performs a complex binding of a text control to a model element. The + * validation is performed on modification (i.e. always), while model + * updates are only performed on focus out (if validation works). There is + * no validation support from model to text, as the model is considered to + * be always consistent. If the control has a {@link ControlDecoration} + * stored under the {@link #DECORATION_KEY} key, this is used to visualize + * the validation result. + */ + public static Binding[] performComplexTextBinding(DataBindingContext dbc, + Control control, IObservableValue modelValue, + IConverter modelToTextConverter, IConverter textToModelConverter, + IValidator textValidator, IValidator textPostConvertValidator) { + + Binding[] bindings = new Binding[3]; + + // normal model to control + UpdateValueStrategy modelToTextStrategy = new UpdateValueStrategy(true, + UpdateValueStrategy.POLICY_UPDATE) + .setConverter(modelToTextConverter); + + // use POLICY_UPDATE to actually perform the update + UpdateValueStrategy textToModelStrategyWithUpdate = new UpdateValueStrategy( + true, UpdateValueStrategy.POLICY_UPDATE) + .setConverter(textToModelConverter) + .setAfterGetValidator(textValidator) + .setAfterConvertValidator(textPostConvertValidator); + + // add the "normal" binding to actually update the model + bindings[0] = dbc.bindValue( + SWTObservables.observeText(control, SWT.FocusOut), modelValue, + textToModelStrategyWithUpdate, modelToTextStrategy); + + // here it is important to only use POLICY_CONVERT, to not write through + // to the model + UpdateValueStrategy textToModelStrategyNoUpdate = new UpdateValueStrategy( + true, UpdateValueStrategy.POLICY_CONVERT) + .setConverter(textToModelConverter) + .setAfterGetValidator(textValidator) + .setAfterConvertValidator(textPostConvertValidator); + + // perform a binding which only serves for validation purposes + bindings[1] = dbc.bindValue(SWTObservables.observeText(control, + SWT.Modify), modelValue, textToModelStrategyNoUpdate, + new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); + + // add validation of required/supported + final Object data = control.getData(DECORATION_KEY); + if (data instanceof ControlDecoration) { + bindings[2] = dbc.bindValue(JFaceObservables + .observeControlDecoration((ControlDecoration) data), + bindings[1].getValidationStatus(), null, null); + } + return bindings; + } +}