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 127986 Details for
Bug 218884
[DataBinding] Add API: WorkbenchObservables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
better patch
patch-218884.txt (text/plain), 19.24 KB, created by
Boris Bokowski
on 2009-03-09 00:45:10 EDT
(
hide
)
Description:
better patch
Filename:
MIME Type:
Creator:
Boris Bokowski
Created:
2009-03-09 00:45:10 EDT
Size:
19.24 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#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 04:41:23 -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,103 @@ >+/******************************************************************************* >+ * 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 - bugs 206839, 124684, 239302, 245647, 194734, 195222, >+ * 264286 >+ *******************************************************************************/ >+ >+package org.eclipse.ui.databinding; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.value.DecoratingObservableValue; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.observable.value.ValueChangeEvent; >+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 JFace viewers >+ * >+ * @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 observable >+ * the observable whose value should be adapted >+ * @param targetType >+ * 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 observeAdaptedValue(IObservableValue observable, >+ final Class targetType) { >+ final IAdapterManager adapterManager = Platform.getAdapterManager(); >+ return new DecoratingObservableValue(observable, false) { >+ public Object getValue() { >+ return adapted(super.getValue()); >+ } >+ >+ protected void handleValueChange(ValueChangeEvent event) { >+ fireValueChange(Diffs.createValueDiff(adapted(event.diff.getOldValue()), >+ adapted(event.diff.getNewValue()))); >+ } >+ >+ private Object adapted(Object object) { >+ if (targetType.isInstance(object)) { >+ return object; >+ } >+ return adapterManager.getAdapter(object, targetType); >+ } >+ >+ public Object getValueType() { >+ return targetType; >+ } >+ }; >+ } >+ >+ /** >+ * 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 observeAdaptedValue(WorkbenchProperties.singleSelection(null, true) >+ .observe(selectionService), targetType); >+ } >+} >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,273 @@ >+/******************************************************************************* >+ * 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 >+ *******************************************************************************/ >+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.ISimplePropertyListener; >+import org.eclipse.core.databinding.property.SimplePropertyEvent; >+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.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.ui.ISelectionListener; >+import org.eclipse.ui.ISelectionService; >+import org.eclipse.ui.IWorkbenchPart; >+ >+/** >+ * Helper class for providing observables for the Workbench. >+ * >+ * <p> >+ * Examples: >+ * >+ * <pre> >+ * WorkbenchProperties.singleSelection().observe( >+ * getSite().getService(ISelectionService.class)) >+ * </pre> >+ * >+ * </p> >+ * >+ * @since 3.5 >+ */ >+public class WorkbenchProperties { >+ >+ /** >+ * 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 class SingleSelectionProperty extends SimpleValueProperty { >+ >+ private final String partId; >+ private final boolean post; >+ >+ SingleSelectionProperty(String partId, boolean post) { >+ this.partId = partId; >+ this.post = post; >+ } >+ >+ class SingleSelectionListener implements INativePropertyListener, >+ ISelectionListener { >+ private final ISimplePropertyListener wrapped; >+ >+ public SingleSelectionListener(ISimplePropertyListener wrapped) { >+ this.wrapped = wrapped; >+ } >+ >+ public void addTo(Object source) { >+ if (post) { >+ if (partId != null) { >+ ((ISelectionService) source).addPostSelectionListener(partId, >+ this); >+ } else { >+ ((ISelectionService) source).addPostSelectionListener(this); >+ } >+ } else { >+ if (partId != null) { >+ ((ISelectionService) source).addSelectionListener(partId, this); >+ } else { >+ ((ISelectionService) source).addSelectionListener(this); >+ } >+ } >+ } >+ >+ public void removeFrom(Object source) { >+ if (post) { >+ if (partId != null) { >+ ((ISelectionService) source).removePostSelectionListener(partId, >+ this); >+ } else { >+ ((ISelectionService) source).removePostSelectionListener(this); >+ } >+ } else { >+ if (partId != null) { >+ ((ISelectionService) source) >+ .removeSelectionListener(partId, this); >+ } else { >+ ((ISelectionService) source).removeSelectionListener(this); >+ } >+ } >+ } >+ >+ public void selectionChanged(IWorkbenchPart part, ISelection selection) { >+ wrapped.handleEvent(new SimplePropertyEvent(SimplePropertyEvent.CHANGE, >+ null, SingleSelectionProperty.this, null)); >+ } >+ } >+ >+ public INativePropertyListener adaptListener(ISimplePropertyListener listener) { >+ return null; >+ } >+ >+ 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; >+ } >+ >+ class SingleSelectionListener implements INativePropertyListener, >+ ISelectionListener { >+ private final ISimplePropertyListener wrapped; >+ >+ public SingleSelectionListener(ISimplePropertyListener wrapped) { >+ this.wrapped = wrapped; >+ } >+ >+ public void addTo(Object source) { >+ if (post) { >+ if (partId != null) { >+ ((ISelectionService) source).addPostSelectionListener(partId, >+ this); >+ } else { >+ ((ISelectionService) source).addPostSelectionListener(this); >+ } >+ } else { >+ if (partId != null) { >+ ((ISelectionService) source).addSelectionListener(partId, this); >+ } else { >+ ((ISelectionService) source).addSelectionListener(this); >+ } >+ } >+ } >+ >+ public void removeFrom(Object source) { >+ if (post) { >+ if (partId != null) { >+ ((ISelectionService) source).removePostSelectionListener(partId, >+ this); >+ } else { >+ ((ISelectionService) source).removePostSelectionListener(this); >+ } >+ } else { >+ if (partId != null) { >+ ((ISelectionService) source) >+ .removeSelectionListener(partId, this); >+ } else { >+ ((ISelectionService) source).removeSelectionListener(this); >+ } >+ } >+ } >+ >+ public void selectionChanged(IWorkbenchPart part, ISelection selection) { >+ wrapped.handleEvent(new SimplePropertyEvent(SimplePropertyEvent.CHANGE, >+ null, MultiSelectionProperty.this, null)); >+ } >+ } >+ >+ public INativePropertyListener adaptListener(ISimplePropertyListener listener) { >+ return null; >+ } >+ >+ 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(); >+ } >+ >+ } >+} >#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 04:41:24 -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()); >+ } >+ }); >+ } > }
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