Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 128106 Details for
Bug 218884
[DataBinding] Add API: WorkbenchObservables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch
clipboard.txt (text/plain), 20.29 KB, created by
Matthew Hall
on 2009-03-09 17:01:35 EDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Matthew Hall
Created:
2009-03-09 17:01:35 EDT
Size:
20.29 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.databinding.observable >Index: src/org/eclipse/core/databinding/observable/Observables.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Observables.java,v >retrieving revision 1.14 >diff -u -r1.14 Observables.java >--- src/org/eclipse/core/databinding/observable/Observables.java 17 Oct 2008 16:44:25 -0000 1.14 >+++ src/org/eclipse/core/databinding/observable/Observables.java 9 Mar 2009 21:00:21 -0000 >@@ -32,7 +32,9 @@ > import org.eclipse.core.databinding.observable.set.ObservableSet; > import org.eclipse.core.databinding.observable.value.DecoratingObservableValue; > import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.observable.value.IValueChangeListener; > import org.eclipse.core.databinding.observable.value.IVetoableValue; >+import org.eclipse.core.databinding.observable.value.ValueChangeEvent; > import org.eclipse.core.databinding.observable.value.ValueChangingEvent; > import org.eclipse.core.internal.databinding.observable.ConstantObservableValue; > import org.eclipse.core.internal.databinding.observable.DelayedObservableValue; >@@ -47,8 +49,8 @@ > import org.eclipse.core.runtime.Assert; > > /** >- * Contains static methods to operate on or return >- * {@link IObservable Observables}. >+ * Contains static methods to operate on or return {@link IObservable >+ * Observables}. > * > * @since 1.0 > */ >@@ -395,7 +397,8 @@ > public synchronized void addStaleListener(IStaleListener listener) { > } > >- public synchronized void addSetChangeListener(ISetChangeListener listener) { >+ public synchronized void addSetChangeListener( >+ ISetChangeListener listener) { > } > }; > } >@@ -518,7 +521,8 @@ > public synchronized void addStaleListener(IStaleListener listener) { > } > >- public synchronized void addListChangeListener(IListChangeListener listener) { >+ public synchronized void addListChangeListener( >+ IListChangeListener listener) { > } > }; > } >@@ -555,7 +559,8 @@ > * specified key in the given map > * @since 1.2 > */ >- public static IObservableValue observeMapEntry(IObservableMap map, Object key) { >+ public static IObservableValue observeMapEntry(IObservableMap map, >+ Object key) { > return observeMapEntry(map, key, map.getValueType()); > } > >@@ -573,8 +578,8 @@ > * @param key > * the key identifying the map entry to track. > * @param valueType >- * the type of the value. May be <code>null</code>, meaning >- * the value is untyped. >+ * the type of the value. May be <code>null</code>, meaning the >+ * value is untyped. > * @return an observable value that tracks the value associated with the > * specified key in the given map > * @since 1.1 >@@ -594,8 +599,8 @@ > * @param map > * the observable map whose entry will be tracked. > * @param valueType >- * the type of the value. May be <code>null</code>, meaning >- * the value is untyped. >+ * the type of the value. May be <code>null</code>, meaning the >+ * value is untyped. > * @return a factory for creating observable values tracking the value of > * the observable map entry identified by a particular key object. > * @since 1.1 >@@ -618,8 +623,8 @@ > * @param master > * the observable value that identifies which map entry to track. > * @param valueType >- * the type of the value. May be <code>null</code>, meaning >- * the value is untyped. >+ * the type of the value. May be <code>null</code>, meaning the >+ * value is untyped. > * @return an observable value tracking the current value of the specified > * key in the given map an observable value that tracks the current > * value of the named property for the current value of the master >@@ -631,4 +636,27 @@ > return MasterDetailObservables.detailValue(master, > mapEntryValueFactory(map, valueType), valueType); > } >+ >+ /** >+ * Copies the current value of the source observable to the destination >+ * observable, and upon value change events fired by the source observable, >+ * updates the destination observable accordingly, until the source >+ * observable is disposed. This method assumes that both observables are on >+ * the same realm. >+ * >+ * @param source >+ * the source observable >+ * @param destination >+ * the destination observable >+ * @since 1.2 >+ */ >+ public static void pipe(IObservableValue source, >+ final IObservableValue destination) { >+ destination.setValue(source.getValue()); >+ source.addValueChangeListener(new IValueChangeListener() { >+ public void handleValueChange(ValueChangeEvent event) { >+ destination.setValue(event.diff.getNewValue()); >+ } >+ }); >+ } > } >#P org.eclipse.ui.workbench >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/META-INF/MANIFEST.MF,v >retrieving revision 1.62 >diff -u -r1.62 MANIFEST.MF >--- META-INF/MANIFEST.MF 4 Mar 2009 02:47:53 -0000 1.62 >+++ META-INF/MANIFEST.MF 9 Mar 2009 21:00:22 -0000 >@@ -19,6 +19,7 @@ > org.eclipse.ui.browser;ui.workbench=split;mandatory:="ui.workbench", > org.eclipse.ui.commands, > org.eclipse.ui.contexts, >+ org.eclipse.ui.databinding, > org.eclipse.ui.dialogs;ui.workbench=split;mandatory:="ui.workbench", > org.eclipse.ui.dnd, > org.eclipse.ui.fieldassist, >@@ -96,7 +97,8 @@ > org.eclipse.swt;bundle-version="[3.3.0,4.0.0)", > org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)", > org.eclipse.jface.databinding;bundle-version="[1.1.0,2.0.0)", >- org.eclipse.core.databinding;bundle-version="[1.0.0,2.0.0)" >+ org.eclipse.core.databinding.property;bundle-version="[1.2.0,2.0.0)", >+ org.eclipse.core.databinding.observable;bundle-version="[1.2.0,2.0.0)" > Import-Package: com.ibm.icu.text, > com.ibm.icu.util, > javax.xml.parsers, >Index: Eclipse UI/org/eclipse/ui/databinding/WorkbenchObservables.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/databinding/WorkbenchObservables.java >diff -N Eclipse UI/org/eclipse/ui/databinding/WorkbenchObservables.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/databinding/WorkbenchObservables.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,101 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ * Matthew Hall - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.ui.databinding; >+ >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.IAdapterManager; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.ui.ISelectionService; >+import org.eclipse.ui.services.IServiceLocator; >+ >+/** >+ * Factory methods for creating observables for Workbench objects >+ * >+ * @since 3.5 >+ */ >+public class WorkbenchObservables { >+ /** >+ * Returns an observable with values of the given target type. If the >+ * wrapped observable's value is of the target type, or can be adapted to >+ * the target type, this is taken as the value of the returned observable, >+ * otherwise <code>null</code>. >+ * >+ * @param master >+ * the observable whose value should be adapted >+ * @param adapter >+ * the target type >+ * @return an observable with values of the given type, or <code>null</code> >+ * if the current value of the given observable does not adapt to >+ * the target type >+ */ >+ public static IObservableValue observeDetailAdaptedValue( >+ IObservableValue master, Class adapter) { >+ return observeDetailAdaptedValue(master, adapter, Platform >+ .getAdapterManager()); >+ } >+ >+ /** >+ * Returns an observable with values of the given target type. If the >+ * wrapped observable's value is of the target type, or can be adapted to >+ * the target type, this is taken as the value of the returned observable, >+ * otherwise <code>null</code>. >+ * >+ * @param master >+ * the observable whose value should be adapted >+ * @param adapter >+ * the target type >+ * @param adapterManager >+ * the adapter manager used to adapt the master value >+ * @return an observable with values of the given type, or <code>null</code> >+ * if the current value of the given observable does not adapt to >+ * the target type >+ */ >+ public static IObservableValue observeDetailAdaptedValue( >+ IObservableValue master, Class adapter, >+ IAdapterManager adapterManager) { >+ return WorkbenchProperties.adaptedValue(adapter, adapterManager) >+ .observeDetail(master); >+ } >+ >+ /** >+ * Returns an observable value that tracks the post selection of a selection >+ * service obtained through the given service locator, and adapts the first >+ * element of that selection to the given target type. >+ * <p> >+ * This method can be used by view or editor implementers to tie into the >+ * selection service, for example as follows: >+ * >+ * <pre> >+ * IObservableValue selection = WorkbenchObservables >+ * .observeAdaptedSingleSelection(getSite(), IResource.class); >+ * </pre> >+ * >+ * </p> >+ * >+ * @param locator >+ * a service locator with an available {@link ISelectionService} >+ * @param targetType >+ * the target type >+ * @return an observable value whose value type is the given target type >+ */ >+ public static IObservableValue observeAdaptedSingleSelection( >+ IServiceLocator locator, Class targetType) { >+ ISelectionService selectionService = (ISelectionService) locator >+ .getService(ISelectionService.class); >+ Assert.isNotNull(selectionService); >+ return WorkbenchProperties.singleSelection(null, true).value( >+ WorkbenchProperties.adaptedValue(targetType)).observe( >+ selectionService); >+ } >+} >Index: Eclipse UI/org/eclipse/ui/databinding/WorkbenchProperties.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/databinding/WorkbenchProperties.java >diff -N Eclipse UI/org/eclipse/ui/databinding/WorkbenchProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/databinding/WorkbenchProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,293 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ * Matthew Hall - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.databinding; >+ >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.core.databinding.observable.list.ListDiff; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.databinding.property.IProperty; >+import org.eclipse.core.databinding.property.ISimplePropertyListener; >+import org.eclipse.core.databinding.property.NativePropertyListener; >+import org.eclipse.core.databinding.property.list.IListProperty; >+import org.eclipse.core.databinding.property.list.SimpleListProperty; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.SimpleValueProperty; >+import org.eclipse.core.runtime.IAdapterManager; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.ui.ISelectionListener; >+import org.eclipse.ui.ISelectionService; >+import org.eclipse.ui.IWorkbenchPart; >+ >+/** >+ * Factory methods for creating properties for the Workbench. >+ * >+ * <p> >+ * Examples: >+ * >+ * <pre> >+ * WorkbenchProperties.singleSelection().observe( >+ * getSite().getService(ISelectionService.class)) >+ * </pre> >+ * >+ * </p> >+ * >+ * @since 3.5 >+ */ >+public class WorkbenchProperties { >+ /** >+ * Returns a value property which observes the source object as the adapted >+ * type, using the platform adapter manager. If the source is of the target >+ * type, or can be adapted to the target type, this is used as the value of >+ * property, otherwise <code>null</code>. >+ * >+ * @param adapter >+ * the adapter class >+ * @return a value property which observes the source object as the adapted >+ * type. >+ */ >+ public static IValueProperty adaptedValue(Class adapter) { >+ return adaptedValue(adapter, Platform.getAdapterManager()); >+ } >+ >+ /** >+ * Returns a value property which observes the source object as the adapted >+ * type. If the source object is of the target type, or can be adapted to >+ * the target type, this is used as the value of property, otherwise >+ * <code>null</code>. >+ * >+ * @param adapter >+ * the adapter class >+ * @param adapterManager >+ * the adapter manager used to adapt source objects >+ * @return a value property which observes the source object as the adapted >+ * type. >+ */ >+ public static IValueProperty adaptedValue(final Class adapter, >+ final IAdapterManager adapterManager) { >+ return new AdaptedValueProperty(adapter, adapterManager); >+ } >+ >+ /** >+ * Returns a property for observing the first element of a structured >+ * selection as exposed by {@link ISelectionService}. >+ * >+ * @return an observable value >+ */ >+ public static IValueProperty singleSelection() { >+ return singleSelection(null, false); >+ } >+ >+ /** >+ * Returns a property for observing the first element of a structured >+ * selection as exposed by {@link ISelectionService}. >+ * >+ * @param partId >+ * the part id, or <code>null</code> if the selection can be from >+ * any part >+ * @param postSelection >+ * <code>true</code> if the selection should be delayed for >+ * keyboard-triggered selections >+ * >+ * @return an observable value >+ */ >+ public static IValueProperty singleSelection(String partId, >+ boolean postSelection) { >+ return new SingleSelectionProperty(partId, postSelection); >+ } >+ >+ /** >+ * Returns a property for observing the elements of a structured selection >+ * as exposed by {@link ISelectionService}. >+ * >+ * @return an observable value >+ */ >+ public static IListProperty multipleSelection() { >+ return multipleSelection(null, false); >+ } >+ >+ /** >+ * Returns a property for observing the elements of a structured selection >+ * as exposed by {@link ISelectionService}. >+ * >+ * @param partId >+ * the part id, or <code>null</code> if the selection can be from >+ * any part >+ * @param postSelection >+ * <code>true</code> if the selection should be delayed for >+ * keyboard-triggered selections >+ * >+ * @return an observable value >+ */ >+ public static IListProperty multipleSelection(String partId, >+ boolean postSelection) { >+ return new MultiSelectionProperty(partId, postSelection); >+ } >+ >+ static final class AdaptedValueProperty extends SimpleValueProperty { >+ private final Class adapter; >+ private final IAdapterManager adapterManager; >+ >+ private AdaptedValueProperty(Class adapter, >+ IAdapterManager adapterManager) { >+ this.adapter = adapter; >+ this.adapterManager = adapterManager; >+ } >+ >+ public Object getValueType() { >+ return adapter; >+ } >+ >+ protected Object doGetValue(Object source) { >+ if (adapter.isInstance(source)) >+ return source; >+ return adapterManager.getAdapter(source, adapter); >+ } >+ >+ protected void doSetValue(Object source, Object value) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public INativePropertyListener adaptListener( >+ ISimplePropertyListener listener) { >+ return null; >+ } >+ } >+ >+ static class SingleSelectionProperty extends SimpleValueProperty { >+ private final String partId; >+ private final boolean post; >+ >+ SingleSelectionProperty(String partId, boolean post) { >+ this.partId = partId; >+ this.post = post; >+ } >+ >+ public INativePropertyListener adaptListener( >+ ISimplePropertyListener listener) { >+ return new SelectionServiceListener(this, listener, partId, post); >+ } >+ >+ protected Object doGetValue(Object source) { >+ ISelection selection; >+ if (partId != null) { >+ selection = ((ISelectionService) source).getSelection(partId); >+ } else { >+ selection = ((ISelectionService) source).getSelection(); >+ } >+ if (selection instanceof IStructuredSelection) { >+ return ((IStructuredSelection) selection).getFirstElement(); >+ } >+ return null; >+ } >+ >+ protected void doSetValue(Object source, Object value) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public Object getValueType() { >+ return Object.class; >+ } >+ } >+ >+ static class MultiSelectionProperty extends SimpleListProperty { >+ private final String partId; >+ private final boolean post; >+ >+ MultiSelectionProperty(String partId, boolean post) { >+ this.partId = partId; >+ this.post = post; >+ } >+ >+ public INativePropertyListener adaptListener( >+ ISimplePropertyListener listener) { >+ return new SelectionServiceListener(this, listener, partId, post); >+ } >+ >+ public Object getElementType() { >+ return Object.class; >+ } >+ >+ protected List doGetList(Object source) { >+ ISelection selection; >+ if (partId != null) { >+ selection = ((ISelectionService) source).getSelection(partId); >+ } else { >+ selection = ((ISelectionService) source).getSelection(); >+ } >+ if (selection instanceof IStructuredSelection) { >+ return new ArrayList(((IStructuredSelection) selection) >+ .toList()); >+ } >+ return Collections.EMPTY_LIST; >+ } >+ >+ protected void doSetList(Object source, List list, ListDiff diff) { >+ throw new UnsupportedOperationException(); >+ } >+ } >+ >+ static class SelectionServiceListener extends NativePropertyListener >+ implements ISelectionListener { >+ private final String partId; >+ private final boolean post; >+ >+ public SelectionServiceListener(IProperty property, >+ ISimplePropertyListener wrapped, String partID, boolean post) { >+ super(property, wrapped); >+ this.partId = partID; >+ this.post = post; >+ } >+ >+ protected void doAddTo(Object source) { >+ ISelectionService selectionService = (ISelectionService) source; >+ if (post) { >+ if (partId != null) { >+ selectionService.addPostSelectionListener(partId, this); >+ } else { >+ selectionService.addPostSelectionListener(this); >+ } >+ } else { >+ if (partId != null) { >+ selectionService.addSelectionListener(partId, this); >+ } else { >+ selectionService.addSelectionListener(this); >+ } >+ } >+ } >+ >+ protected void doRemoveFrom(Object source) { >+ ISelectionService selectionService = (ISelectionService) source; >+ if (post) { >+ if (partId != null) { >+ selectionService.removePostSelectionListener(partId, this); >+ } else { >+ selectionService.removePostSelectionListener(this); >+ } >+ } else { >+ if (partId != null) { >+ selectionService.removeSelectionListener(partId, this); >+ } else { >+ selectionService.removeSelectionListener(this); >+ } >+ } >+ } >+ >+ public void selectionChanged(IWorkbenchPart part, ISelection selection) { >+ fireChange(null, null); >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 218884
:
127983
|
127986
| 128106