protected void detachFromGuides(InstallOptionsWidget widget) { if (widget.getVerticalGuide() != null) { mVerticalGuide = widget.getVerticalGuide(); mVerticalAlign = mVerticalGuide.getAlignment(widget); mVerticalGuide.detachWidget(widget); } if (widget.getHorizontalGuide() != null) { mHorizontalGuide = widget.getHorizontalGuide(); mHorizontalAlign = mHorizontalGuide.getAlignment(widget); mHorizontalGuide.detachWidget(widget); } }
@Override public boolean close() { if (mSection != null) { INIFile iniFile = (INIFile) mSection.getParent(); if (iniFile != null) { iniFile.setValidateFixMode(mOldValidateFixMode); } } if (mCurrentWidget != null) { mCurrentWidget.removeModelCommandListener(InstallOptionsWidgetEditorDialog.this); mCurrentWidget.removePropertyChangeListener(InstallOptionsWidgetEditorDialog.this); if (mCurrentWidget.getParent() != null) { mCurrentWidget .getParent() .removePropertyChangeListener(InstallOptionsWidgetEditorDialog.this); } } return super.close(); }
@Override protected final void initCellEditor() { InstallOptionsWidget control = (InstallOptionsWidget) getEditPart().getModel(); IPropertyDescriptor descriptor = control.getPropertyDescriptor(getDirectEditProperty()); if (descriptor instanceof PropertyDescriptor) { try { ICellEditorValidator validator = PropertyDescriptorHelper.getCellEditorValidator((PropertyDescriptor) descriptor); if (validator != null) { getCellEditor().setValidator(validator); } } catch (Throwable t) { InstallOptionsPlugin.getDefault().log(t); } } String initialText = getInitialText(control); getCellEditor().setValue(initialText); selectCellEditorText(); }
@Override protected void okPressed() { if (mDialog.canUpdateINIFile()) { mDialog.updateINIFile(); if (mSection == null) { mSection = mCurrentWidget.getSection(); } super.okPressed(); } else { super.cancelPressed(); } }
public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(InstallOptionsModel.PROPERTY_INDEX)) { mDialog.moveChild(mCurrentWidget, ((Integer) evt.getNewValue()).intValue()); } else if (evt.getPropertyName().equals(InstallOptionsModel.PROPERTY_CHILDREN)) { if (Common.objectsAreEqual(mCurrentWidget, evt.getOldValue()) && evt.getNewValue() instanceof InstallOptionsWidget) { InstallOptionsWidget widget = (InstallOptionsWidget) evt.getNewValue(); mCurrentWidget.removeModelCommandListener(InstallOptionsWidgetEditorDialog.this); mCurrentWidget.removePropertyChangeListener(InstallOptionsWidgetEditorDialog.this); mCurrentWidget = widget; mSection = mCurrentWidget.getSection(); mCurrentWidget.addModelCommandListener(InstallOptionsWidgetEditorDialog.this); mCurrentWidget.addPropertyChangeListener(InstallOptionsWidgetEditorDialog.this); Display.getDefault() .asyncExec( new Runnable() { public void run() { mPage.selectionChanged(null, new StructuredSelection(mCurrentWidget)); } }); } } }
@Override protected Control createControl(Composite parent) { Composite propertyComposite = new Composite(parent, SWT.BORDER); GridLayout layout = new GridLayout(1, false); layout.marginWidth = layout.marginHeight = 0; propertyComposite.setLayout(layout); if (mPage instanceof Page) { ((Page) mPage) .init( new IPageSite() { public void registerContextMenu( String menuId, MenuManager menuManager, ISelectionProvider selectionProvider) {} public IActionBars getActionBars() { return null; } public IWorkbenchPage getPage() { return getWorkbenchWindow().getActivePage(); } public ISelectionProvider getSelectionProvider() { return null; } public Shell getShell() { return getWorkbenchWindow().getShell(); } public IWorkbenchWindow getWorkbenchWindow() { return PlatformUI.getWorkbench().getActiveWorkbenchWindow(); } public void setSelectionProvider(ISelectionProvider provider) {} @SuppressWarnings("unchecked") public Object getAdapter(Class adapter) { return null; } @SuppressWarnings("unchecked") public Object getService(Class api) { return null; } @SuppressWarnings("unchecked") public boolean hasService(Class api) { return false; } }); } if (mPage instanceof PropertySheetPage) { ((PropertySheetPage) mPage).setPropertySourceProvider(this); } mPage.createControl(propertyComposite); mPage.setActionBars(new DummyActionBars()); final Control control = mPage.getControl(); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); if (control instanceof Tree) { final Tree tree = (Tree) control; data.heightHint = tree.getItemHeight() * 13 + (tree.getLinesVisible() ? 12 * tree.getGridLineWidth() : 0) + (tree.getHeaderVisible() ? tree.getHeaderHeight() : 0) + 2 * tree.getBorderWidth() + (tree.getHorizontalBar() != null ? tree.getHorizontalBar().getSize().x : 0); tree.addControlListener( new ControlAdapter() { @Override public void controlResized(ControlEvent e) { Rectangle area = tree.getClientArea(); TreeColumn[] columns = tree.getColumns(); if (area.width > 0) { columns[0].setWidth(area.width * 40 / 100); columns[1].setWidth(area.width - columns[0].getWidth() - 4); } } }); } else if (control instanceof Composite) { control.addControlListener( new ControlAdapter() { @Override public void controlResized(ControlEvent e) { ((Composite) control).layout(true, true); } }); } control.setLayoutData(data); ISelection selection; if (mCurrentWidget == null) { Collection<InstallOptionsModelTypeDef> typeDefs = InstallOptionsModel.INSTANCE.getControlTypeDefs(); if (typeDefs.size() > 0) { InstallOptionsModelTypeDef typeDef = typeDefs.iterator().next(); InstallOptionsElementFactory factory = InstallOptionsElementFactory.getFactory(typeDef.getType()); mCurrentWidget = (InstallOptionsWidget) factory.getNewObject(); mDialog.addChild(mCurrentWidget); } } if (mCurrentWidget != null) { mCurrentWidget.addModelCommandListener(InstallOptionsWidgetEditorDialog.this); mCurrentWidget.addPropertyChangeListener(InstallOptionsWidgetEditorDialog.this); if (mCurrentWidget.getParent() != null) { mCurrentWidget.getParent().addPropertyChangeListener(InstallOptionsWidgetEditorDialog.this); } selection = new StructuredSelection(mCurrentWidget); } else { selection = StructuredSelection.EMPTY; } mPage.selectionChanged(null, selection); PlatformUI.getWorkbench().getHelpSystem().setHelp(mPage.getControl(), HELP_CONTEXT); PlatformUI.getWorkbench().getHelpSystem().setHelp(propertyComposite, HELP_CONTEXT); return propertyComposite; }
@Override public void execute() { detachFromGuides(mChild); mIndex = mChild.getIndex(); mParent.removeChild(mChild); }