private void validatePage() {
    String errorMessage = null;
    String newText = fWorkingSetName.getText();

    if (newText.trim().length() == 0) {
      errorMessage = PDEUIMessages.PluginWorkingSet_emptyName;
      if (fFirstCheck) {
        setPageComplete(false);
        fFirstCheck = false;
        return;
      }
    }
    if (errorMessage == null && fTree.getCheckboxTreeViewer().getCheckedElements().length == 0) {
      errorMessage = PDEUIMessages.PluginWorkingSet_noPluginsChecked;
    }

    if (errorMessage == null && fWorkingSet == null) {
      IWorkingSet[] workingSets = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
      for (int i = 0; i < workingSets.length; i++) {
        if (newText.equals(workingSets[i].getName())) {
          errorMessage = PDEUIMessages.PluginWorkingSet_nameInUse;
          break;
        }
      }
    }
    setErrorMessage(errorMessage);
    setPageComplete(errorMessage == null);
  }
  /**
   * Creates the SWT controls for this workbench part.
   *
   * @param parent the parent control
   */
  public void createSection(Composite parent) {
    super.createSection(parent);
    FormToolkit toolkit = getFormToolkit(parent.getDisplay());

    Section section =
        toolkit.createSection(
            parent,
            ExpandableComposite.TWISTIE
                | ExpandableComposite.EXPANDED
                | ExpandableComposite.TITLE_BAR
                | Section.DESCRIPTION
                | ExpandableComposite.FOCUS_TITLE);
    section.setText(Messages.configurationEditorPortsSection);
    section.setDescription(Messages.configurationEditorPortsDescription);
    section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));

    // ports
    Composite composite = toolkit.createComposite(section);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 8;
    layout.marginWidth = 8;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.FILL_HORIZONTAL));
    IWorkbenchHelpSystem whs = PlatformUI.getWorkbench().getHelpSystem();
    whs.setHelp(composite, ContextIds.CONFIGURATION_EDITOR_PORTS);
    toolkit.paintBordersFor(composite);
    section.setClient(composite);

    ports = toolkit.createTable(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
    ports.setHeaderVisible(true);
    ports.setLinesVisible(true);
    whs.setHelp(ports, ContextIds.CONFIGURATION_EDITOR_PORTS_LIST);

    TableLayout tableLayout = new TableLayout();

    TableColumn col = new TableColumn(ports, SWT.NONE);
    col.setText(Messages.configurationEditorPortNameColumn);
    ColumnWeightData colData = new ColumnWeightData(15, 150, true);
    tableLayout.addColumnData(colData);

    col = new TableColumn(ports, SWT.NONE);
    col.setText(Messages.configurationEditorPortValueColumn);
    colData = new ColumnWeightData(8, 80, true);
    tableLayout.addColumnData(colData);

    GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    data.widthHint = 230;
    data.heightHint = 100;
    ports.setLayoutData(data);
    ports.setLayout(tableLayout);

    viewer = new TableViewer(ports);
    viewer.setColumnProperties(new String[] {"name", "port"});

    initialize();
  }
Exemplo n.º 3
0
 public static void removeFocusTracker(IServiceLocator serviceLocator, Control control) {
   if (PlatformUI.getWorkbench().isClosing()) {
     // TODO: it is a bug in eclipse. During workbench shutdown disposed service returned.
     return;
   }
   final IFocusService focusService = serviceLocator.getService(IFocusService.class);
   if (focusService != null) {
     focusService.removeFocusTracker(control);
   } else {
     log.debug("Focus service not found in " + serviceLocator);
   }
 }
Exemplo n.º 4
0
 public static boolean isContextActive(String contextId) {
   Collection<?> contextIds =
       PlatformUI.getWorkbench()
           .getActiveWorkbenchWindow()
           .getService(IContextService.class)
           .getActiveContextIds();
   for (Object id : contextIds) {
     if (contextId.equals(id)) {
       return true;
     }
   }
   return false;
 }
  /* (non-Javadoc)
   * @see org.eclipse.ui.dialogs.IWorkingSetPage#finish()
   */
  public void finish() {
    Object[] checked = fTree.getCheckboxTreeViewer().getCheckedElements();
    ArrayList<PersistablePluginObject> list = new ArrayList<PersistablePluginObject>();
    for (int i = 0; i < checked.length; i++) {
      String id = ((IPluginModelBase) checked[i]).getPluginBase().getId();
      if (id != null && id.length() > 0) list.add(new PersistablePluginObject(id));
    }
    PersistablePluginObject[] objects = list.toArray(new PersistablePluginObject[list.size()]);

    String workingSetName = fWorkingSetName.getText().trim();
    if (fWorkingSet == null) {
      IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
      fWorkingSet = workingSetManager.createWorkingSet(workingSetName, objects);
    } else {
      fWorkingSet.setName(workingSetName);
      fWorkingSet.setElements(objects);
    }
  }
 private void handleAddWorkingSet() {
   IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
   IWorkingSetSelectionDialog dialog =
       manager.createWorkingSetSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), true);
   if (dialog.open() == Window.OK) {
     IWorkingSet[] workingSets = dialog.getSelection();
     IProduct product = getProduct();
     IProductModelFactory factory = product.getModel().getFactory();
     ArrayList<IProductPlugin> pluginList = new ArrayList<IProductPlugin>();
     for (int i = 0; i < workingSets.length; i++) {
       IAdaptable[] elements = workingSets[i].getElements();
       for (int j = 0; j < elements.length; j++) {
         IPluginModelBase model = findModel(elements[j]);
         if (model != null) {
           IProductPlugin plugin = factory.createPlugin();
           IPluginBase base = model.getPluginBase();
           plugin.setId(base.getId());
           pluginList.add(plugin);
         }
       }
     }
     product.addPlugins(pluginList.toArray(new IProductPlugin[pluginList.size()]));
   }
 }
  @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;
  }
Exemplo n.º 8
0
 public static void setHelp(Control control, String pluginId, String helpContextID) {
   PlatformUI.getWorkbench()
       .getHelpSystem()
       .setHelp(control, pluginId + "." + helpContextID); // $NON-NLS-1$
 }
Exemplo n.º 9
0
 @Nullable
 public static Shell getActiveShell() {
   IWorkbench workbench = PlatformUI.getWorkbench();
   return workbench == null ? null : getShell(workbench.getActiveWorkbenchWindow());
 }
  /* (non-Javadoc)
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    setControl(composite);

    Label label = new Label(composite, SWT.WRAP);
    label.setText(PDEUIMessages.PluginWorkingSet_setName);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    fWorkingSetName = new Text(composite, SWT.SINGLE | SWT.BORDER);
    fWorkingSetName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fWorkingSetName.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            validatePage();
          }
        });
    fWorkingSetName.setFocus();

    label = new Label(composite, SWT.WRAP);
    label.setText(PDEUIMessages.PluginWorkingSet_setContent);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    fTree = new CheckboxFilteredTree(composite, SWT.BORDER, new PatternFilter());
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 250;
    fTree.getViewer().getControl().setLayoutData(gd);
    final IStructuredContentProvider fTableContentProvider = new ContentProvider();
    fTree.getCheckboxTreeViewer().setContentProvider(fTableContentProvider);
    fTree.getCheckboxTreeViewer().setLabelProvider(new WorkingSetLabelProvider());
    fTree.getCheckboxTreeViewer().setUseHashlookup(true);
    fTree.getCheckboxTreeViewer().setInput(PDECore.getDefault());

    fTree
        .getCheckboxTreeViewer()
        .addCheckStateListener(
            new ICheckStateListener() {
              public void checkStateChanged(CheckStateChangedEvent event) {
                validatePage();
              }
            });

    // Add select / deselect all buttons for bug 46669
    Composite buttonComposite = new Composite(composite, SWT.NONE);
    buttonComposite.setLayout(new GridLayout(2, true));
    buttonComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    Button selectAllButton = new Button(buttonComposite, SWT.PUSH);
    selectAllButton.setText(PDEUIMessages.PluginWorkingSet_selectAll_label);
    selectAllButton.setToolTipText(PDEUIMessages.PluginWorkingSet_selectAll_toolTip);
    selectAllButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent selectionEvent) {
            fTree
                .getCheckboxTreeViewer()
                .setCheckedElements(
                    fTableContentProvider.getElements(fTree.getCheckboxTreeViewer().getInput()));
            validatePage();
          }
        });
    selectAllButton.setLayoutData(new GridData());
    SWTUtil.setButtonDimensionHint(selectAllButton);

    Button deselectAllButton = new Button(buttonComposite, SWT.PUSH);
    deselectAllButton.setText(PDEUIMessages.PluginWorkingSet_deselectAll_label);
    deselectAllButton.setToolTipText(PDEUIMessages.PluginWorkingSet_deselectAll_toolTip);
    deselectAllButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent selectionEvent) {
            fTree.getCheckboxTreeViewer().setCheckedElements(new Object[0]);
            validatePage();
          }
        });
    deselectAllButton.setLayoutData(new GridData());
    SWTUtil.setButtonDimensionHint(deselectAllButton);
    setPageComplete(false);
    setMessage(PDEUIMessages.PluginWorkingSet_message);

    initialize();
    Dialog.applyDialogFont(composite);

    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(composite, IHelpContextIds.PLUGIN_WORKING_SET);
  }