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