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 127983 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
patch-218884.txt (text/plain), 13.01 KB, created by
Boris Bokowski
on 2009-03-09 00:23:44 EDT
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Boris Bokowski
Created:
2009-03-09 00:23:44 EDT
Size:
13.01 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:11:12 -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,70 @@ >+/******************************************************************************* >+ * 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.IAdapterManager; >+import org.eclipse.core.runtime.Platform; >+ >+/** >+ * 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; >+ } >+ }; >+ } >+} >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(); >+ } >+ >+ } >+}
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