コード例 #1
0
  protected void installEditors(TreeItem treeItem, final Object parentPackage) {
    Object currentDataItem = treeItem.getData();
    if (currentDataItem instanceof ProfileApplication) {

      ProfileApplication profileApplication = (ProfileApplication) currentDataItem;

      Tree tree = treeItem.getParent();

      final Button checkbox = new Button(tree, SWT.CHECK);

      checkbox.setSelection(true);

      IProfileApplicationDelegate delegate = getDelegate(profileApplication);
      final Package applyingPackage = delegate.getApplyingPackage(profileApplication);
      final Profile appliedProfile = delegate.getAppliedProfile(profileApplication);
      getProfilesToReapply(applyingPackage).add(appliedProfile);

      checkbox.addSelectionListener(
          new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
              if (checkbox.getSelection()) {
                getProfilesToReapply(applyingPackage).add(appliedProfile);
              } else {
                getProfilesToReapply(applyingPackage).remove(appliedProfile);
              }
            }

            public void widgetDefaultSelected(SelectionEvent e) {
              // Nothing
            }
          });

      TreeEditor editor = new TreeEditor(tree);
      editor.horizontalAlignment = SWT.CENTER;
      editor.grabHorizontal = true;

      editor.setEditor(checkbox, treeItem, 4);
    }

    for (TreeItem subitem : treeItem.getItems()) {
      installEditors(subitem, currentDataItem);
    }
  }
コード例 #2
0
 public void refresh(TreeEditor editor) {
   Button button = (Button) editor.getEditor();
   Item item = editor.getItem();
   Boolean value = (Boolean) getValue(item.getData());
   button.setSelection(value.booleanValue());
 }
コード例 #3
0
  @Override
  public void createPartControl(final Composite parent) {
    final GridData gridData1 = new GridData();
    gridData1.horizontalAlignment = FILL;
    gridData1.verticalAlignment = GridData.CENTER;
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    final GridData gridData = new GridData();
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = FILL;
    gridData.verticalAlignment = FILL;
    gridData.grabExcessHorizontalSpace = true;
    final Composite top = new Composite(parent, SWT.NONE);
    top.setLayout(gridLayout);
    labelTitre = new Label(top, SWT.NONE);
    labelTitre.setText("Navigateur");
    labelTitre.setLayoutData(gridData1);
    tree = new Tree(top, SWT.MULTI);
    tree.setLayoutData(gridData);
    treeViewer = new TreeViewer(tree);
    getSite().setSelectionProvider(treeViewer);
    final Image fondImage = ImageReg.getImg(IMG_VIEW_BG);
    tree.setBackgroundImage(fondImage);
    tree.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent element) {
            labelTitre.setText(tree.getSelection()[0].getText());
            try {
              getViewSite().getPage().showView(NAVIGATOR_VIEW_ID);
            } catch (PartInitException e) {
              e.printStackTrace();
            }
          }
        });

    applyNavigatorDoubleClick(tree, getSite().getWorkbenchWindow());

    treeViewer.setLabelProvider(new NavigatorLabelProvider());
    treeViewer.setContentProvider(createContentProvider());

    final ProjectManager manager = getProjectManager();
    manager.addProjectManagerListener(this);
    treeViewer.setInput(manager);
    defineWorkbenchPopupMenu(getSite(), treeViewer);
    initDragAndDrop();

    applyTooltipNavigator(tree);

    final TreeEditor editor = new TreeEditor(tree);
    editor.horizontalAlignment = SWT.CENTER;
    editor.grabHorizontal = true;
    editor.grabVertical = true;

    tree.addKeyListener(new TreeEditing(tree, editor));

    final Clipboard clipboard = new Clipboard(getSite().getShell().getDisplay());
    final IActionBars bars = getViewSite().getActionBars();
    bars.setGlobalActionHandler(CUT.getId(), new CutStepAction(treeViewer, clipboard));
    bars.setGlobalActionHandler(COPY.getId(), new CopyStepAction(treeViewer, clipboard));
    bars.setGlobalActionHandler(PASTE.getId(), new PasteTreeGadgetAction(treeViewer, clipboard));
  }
コード例 #4
0
  /** @see InstanceViewer#createControls(Composite, SchemaSpaceID) */
  @Override
  public void createControls(final Composite parent, SchemaSpaceID schemaSpace) {
    main = new Composite(parent, SWT.NONE);
    main.setLayout(new TreeColumnLayout());

    treeViewer = new TreeViewer(main, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);

    treeViewer.setContentProvider(new TypeMetaPairContentProvider(treeViewer, schemaSpace));

    treeViewer.setLabelProvider(new DefinitionMetaCompareLabelProvider(treeViewer));

    // Add an editor for selecting specific paths.
    editor = new TreeEditor(treeViewer.getTree());
    editor.horizontalAlignment = SWT.RIGHT;
    treeViewer
        .getTree()
        .addMouseMoveListener(
            new MouseMoveListener() {

              @Override
              public void mouseMove(MouseEvent e) {
                final ViewerCell cell = treeViewer.getCell(new Point(e.x, e.y));

                // Selected cell changed?
                if (cell == null
                    || editor.getItem() != cell.getItem()
                    || editor.getColumn() != cell.getColumnIndex()) {
                  // Clean up any previous editor control
                  Control oldEditor = editor.getEditor();
                  if (oldEditor != null) {
                    oldEditor.dispose();
                    editor.setEditor(null, null, 0);
                  }
                }

                // No valid selected cell
                if (cell == null || cell.getColumnIndex() == 0) {
                  return;
                }

                // cell didn't change
                if ((editor.getItem() == cell.getItem()
                    && editor.getColumn() == cell.getColumnIndex())) {
                  return;
                }

                Composite editorControl = new Composite(treeViewer.getTree(), SWT.NONE);
                GridLayoutFactory.fillDefaults()
                    .margins(0, 0)
                    .spacing(0, 0)
                    .numColumns(2)
                    .applyTo(editorControl);

                boolean hideCopy = false;

                // multi value selector

                // Quote the format first. Pattern.quote does the same, except,
                // that it checks the input for \Es.
                // Since we know that there will be no \Es in this case
                // do it ourselves to be safe from changes to Pattern.quote.

                String pattern =
                    "\\Q" + DefinitionInstanceLabelProvider.MULTIPLE_VALUE_FORMAT + "\\E$";
                pattern = pattern.replace("{0}", "\\E(\\d+)\\Q").replace("{1}", "\\E(\\d+)\\Q");

                Matcher m = Pattern.compile(pattern).matcher(cell.getText());
                if (m.find()) {
                  // multi value element

                  int current = Integer.parseInt(m.group(1));
                  int total = Integer.parseInt(m.group(2));

                  // Create the selection control.
                  ComboViewer combo = new ComboViewer(editorControl);
                  Integer[] values = new Integer[total];
                  for (int i = 1; i <= total; i++) values[i - 1] = i;
                  combo.setContentProvider(ArrayContentProvider.getInstance());
                  combo.setInput(values);
                  combo.setSelection(new StructuredSelection(current));
                  combo.addSelectionChangedListener(
                      new ISelectionChangedListener() {

                        @Override
                        public void selectionChanged(SelectionChangedEvent event) {
                          if (event.getSelection() instanceof IStructuredSelection) {
                            // Update label provider and refresh viewer.

                            labelProviders
                                .get(cell.getColumnIndex())
                                .selectPath(
                                    cell.getViewerRow().getTreePath(),
                                    (Integer)
                                        (((IStructuredSelection) event.getSelection())
                                            .getFirstElement()));

                            treeViewer.refresh(cell.getElement(), true);
                          }
                        }
                      });
                } else {
                  /*
                   * only one value - so we can safely determine if the copy
                   * button should be shown
                   */
                  Object value =
                      labelProviders
                          .get(cell.getColumnIndex())
                          .findInstanceEntry(cell.getViewerRow().getTreePath())
                          .getValue();
                  if (value instanceof Instance) {
                    value = ((Instance) value).getValue();
                  }

                  hideCopy = value == null || value.toString().isEmpty();
                }

                // copy button
                if (!hideCopy) {
                  Button button = new Button(editorControl, SWT.PUSH | SWT.FLAT);
                  button.setImage(
                      PlatformUI.getWorkbench()
                          .getSharedImages()
                          .getImage(ISharedImages.IMG_TOOL_COPY));
                  button.setToolTipText("Copy string value");
                  button.addSelectionListener(
                      new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                          // determine text value
                          Object value =
                              labelProviders
                                  .get(cell.getColumnIndex())
                                  .findInstanceEntry(cell.getViewerRow().getTreePath())
                                  .getValue();
                          if (value instanceof Instance) {
                            value = ((Instance) value).getValue();
                          }

                          if (value != null) {
                            final String textValue = value.toString();

                            if (!textValue.isEmpty()) { // empty string is
                              // invalid
                              // copy content to clipboard
                              Clipboard clipBoard = new Clipboard(Display.getCurrent());
                              clipBoard.setContents(
                                  new Object[] {textValue},
                                  new Transfer[] {TextTransfer.getInstance()});
                              clipBoard.dispose();
                            }
                          }
                        }
                      });
                }

                // calculate editor size
                Point size = editorControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                editor.minimumHeight = size.y;
                editor.minimumWidth = size.x;

                editor.setEditor(editorControl, (TreeItem) cell.getItem(), cell.getColumnIndex());
              }
            });

    maep = new MetadataCompareActionProvider(treeViewer);
    maep.setup();

    treeViewer.setComparator(new DefinitionComparator());

    treeViewer.getTree().setHeaderVisible(true);
    treeViewer.getTree().setLinesVisible(true);

    ColumnViewerToolTipSupport.enableFor(treeViewer);

    setInput(null, null);
  }