001: /*
002: *Copyright 2007 Wilken GmbH
003: */
004: package newprocess.diagram.sheet;
005:
006: import java.util.ArrayList;
007: import java.util.Iterator;
008:
009: import org.eclipse.ui.IWorkbenchPart;
010: import org.eclipse.core.runtime.IAdaptable;
011: import org.eclipse.emf.common.notify.AdapterFactory;
012: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
013: import org.eclipse.emf.edit.provider.IItemPropertySource;
014: import org.eclipse.emf.edit.ui.provider.PropertySource;
015: import org.eclipse.jface.viewers.ISelection;
016: import org.eclipse.jface.viewers.StructuredSelection;
017: import org.eclipse.emf.transaction.TransactionalEditingDomain;
018:
019: import org.eclipse.emf.transaction.util.TransactionUtil;
020:
021: import org.eclipse.gmf.runtime.diagram.ui.properties.sections.AdvancedPropertySection;
022:
023: import org.eclipse.ui.views.properties.IPropertySource;
024: import org.eclipse.ui.views.properties.IPropertySourceProvider;
025:
026: /**
027: * @generated
028: */
029: public class EnvironmentPropertySection extends AdvancedPropertySection
030: implements IPropertySourceProvider {
031:
032: /**
033: * @generated
034: */
035: public IPropertySource getPropertySource(Object object) {
036: if (object instanceof IPropertySource) {
037: return (IPropertySource) object;
038: }
039: AdapterFactory af = getAdapterFactory(object);
040: if (af != null) {
041: IItemPropertySource ips = (IItemPropertySource) af.adapt(
042: object, IItemPropertySource.class);
043: if (ips != null) {
044: return new PropertySource(object, ips);
045: }
046: }
047: if (object instanceof IAdaptable) {
048: return (IPropertySource) ((IAdaptable) object)
049: .getAdapter(IPropertySource.class);
050: }
051: return null;
052: }
053:
054: /**
055: * Modify/unwrap selection.
056: * @generated
057: */
058: protected Object transformSelection(Object selected) {
059: return selected;
060: }
061:
062: /**
063: * @generated
064: */
065: protected IPropertySourceProvider getPropertySourceProvider() {
066: return this ;
067: }
068:
069: /**
070: * @generated
071: */
072: public void setInput(IWorkbenchPart part, ISelection selection) {
073: if (selection.isEmpty()
074: || false == selection instanceof StructuredSelection) {
075: super .setInput(part, selection);
076: return;
077: }
078: final StructuredSelection structuredSelection = ((StructuredSelection) selection);
079: ArrayList transformedSelection = new ArrayList(
080: structuredSelection.size());
081: for (Iterator it = structuredSelection.iterator(); it.hasNext();) {
082: Object r = transformSelection(it.next());
083: if (r != null) {
084: transformedSelection.add(r);
085: }
086: }
087: super .setInput(part, new StructuredSelection(
088: transformedSelection));
089: }
090:
091: /**
092: * @generated
093: */
094: protected AdapterFactory getAdapterFactory(Object object) {
095: if (getEditingDomain() instanceof AdapterFactoryEditingDomain) {
096: return ((AdapterFactoryEditingDomain) getEditingDomain())
097: .getAdapterFactory();
098: }
099: TransactionalEditingDomain editingDomain = TransactionUtil
100: .getEditingDomain(object);
101: if (editingDomain != null) {
102: return ((AdapterFactoryEditingDomain) editingDomain)
103: .getAdapterFactory();
104: }
105: return null;
106: }
107: }
|