@Override protected void createFieldEditors() { final INavigatorManager manager = INavigatorManager.Factory.getManager(); FieldEditor editor; final IManager uim = IManager.Factory.getManager(); for (final CEObjectHolder<EObject> pmt : manager.getPreferenceModelTypes()) { final IEditorInformation mt = manager.getEditorInformation(pmt.getObjectClass()); final String[][] translation = new String[mt.getEditors().size()][]; for (int i = 0; i < translation.length; i++) { final IEditorPartDescriptor d = mt.getEditors().get(i); translation[i] = new String[] {d.getName(), d.getId()}; } // IBindingObjectInformation.Factory.getLabel(mt.g) - upps - no class yet, just a name /* * TODO: change this to use a proper binding * * IBindingObjectInformation */ String n = mt.getModelType(); if (n.lastIndexOf('.') != -1) { n = n.substring(n.lastIndexOf('.') + 1); } if (n.matches("^I[A-Z]")) { n = n.substring(1); } String name = ToStringUtils.formatHumanReadable(n); final IModelClassInfo info = uim.getModelClassInfo(mt.getModelType(), null, false); if (info != null) { final Object l = info.getArguments().get(Constants.ARG_LABEL); if (l != null && l instanceof String) { name = (String) l; } } editor = new ComboFieldEditor(mt.getModelType(), name, translation, getFieldEditorParent()); addField(editor); } editor = new BooleanFieldEditor( NavigatorConstants.PREF_USE_GENERIC_EDITOR_PART_FALLBACK, "Fall back on generic editor part", getFieldEditorParent()); addField(editor); editor = new BooleanFieldEditor( NavigatorConstants.PREF_OPEN_MUST_OPEN_NEW, "Open command should open new editors", getFieldEditorParent()); addField(editor); editor = new BooleanFieldEditor( NavigatorConstants.PREF_SHOW_PIN_EDITOR_CONTRIBUTION, "Show 'pin editor' contribution in menus and toolbars", getFieldEditorParent()); addField(editor); editor = new BooleanFieldEditor( NavigatorConstants.PREF_PIN_EDITOR_BY_DEFAULT, "Pin new editors by default", getFieldEditorParent()); addField(editor); editor = new BooleanFieldEditor( NavigatorConstants.PREF_SHOW_CLONE_EDITOR_CONTRIBUTION, "Show 'clone editor' contribution in menus and toolbars", getFieldEditorParent()); addField(editor); editor = new BooleanFieldEditor( NavigatorConstants.PREF_SHOW_CLONE_EDITOR_CONTRIBUTION, "Show other contribution in menus and toolbars", getFieldEditorParent()); addField(editor); }
/** * Returns a Map with the current state for the specific event if specified. * * @param event the current event - possibly <code>null</code> * @return a Map with the current state */ public Map<String, Object> getCurrentState(final Event event) { final Map<String, Object> map = new HashMap<String, Object>(); final List<IObservableValue> values = new ArrayList<IObservableValue>(); resetMap(map); if (event.type == SWT.MenuDetect) { // LogUtils.debug(event, "MenuDetect"); } try { myLastBinding = IBindingContext.Factory.getBindingForWidget(event.widget); if (myLastBinding == null) return map; map.put(Constants.SOURCES_ACTIVE_CONTEXT, myLastBinding.getContext()); final ISourceProviderStateContext context = new ISourceProviderStateContext() { @Override public Event getEvent() { return event; } private Point myLocation = null; @Override public Point getLocation() { if (myLocation == null) { myLocation = new Point(event.x, event.y); switch (event.type) { case SWT.MenuDetect: /* * The location is relative to the display */ myLocation = event.widget.getDisplay().map(null, (Control) event.widget, myLocation); break; default: break; } } return myLocation; } @Override public Map<String, Object> getState() { return map; } @Override public void putSourceValue(String name, Object value) { map.put(name, value); } @Override public void addObservedValue(IObservableValue value) { values.add(value); } @Override public void setSelectionProvider(ISelectionProvider provider) { if (provider == myCurrentSelectionProvider) return; if (myCurrentSelectionProvider != null) { myCurrentSelectionProvider.removeSelectionChangedListener( myCurrentSelectionProviderListener); } myCurrentSelectionProvider = provider; if (myCurrentSelectionProvider != null) { myCurrentSelectionProvider.addSelectionChangedListener( myCurrentSelectionProviderListener); } } }; try { myLastBinding.updateSourceProviderState(context); } catch (final Exception ex) { LogUtils.error(myLastBinding, ex); } /* * If the active binding is a value binding, run all extenders as well... */ final Object activeBinding = map.get(Constants.SOURCES_ACTIVE_BINDING); if (activeBinding instanceof IValueBinding) { final IValueBinding vb = (IValueBinding) activeBinding; for (final IUIBindingDecoratorExtenderDescriptor d : IManager.Factory.getManager().getDecoratorExtenders()) { final CEObjectHolder<IUIBindingDecoratorExtender> factory = d.getFactory(); final IUIBindingDecoratorExtender extender = factory.getObject(); if (extender == null) { LogUtils.error(factory.getConfigurationElement(), "Cannot create extender"); continue; } try { if (!extender.isEnabled(vb)) { continue; } extender.updateSourceProviderState(vb, context); } catch (final Exception ex) { LogUtils.error(factory.getConfigurationElement(), ex); } } } observe(event, values); } catch (final Exception ex) { LogUtils.error(this, ex); } return map; }