Exemplo n.º 1
0
 private void doNewButtonPressed() {
   Object newElement = fCreateTargetQuery.getCreatedTarget(fDestination);
   if (newElement != null) {
     TreeViewer viewer = getTreeViewer();
     ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
     viewer.refresh(contentProvider.getParent(newElement));
     viewer.setSelection(new StructuredSelection(newElement), true);
     viewer.getTree().setFocus();
   }
 }
Exemplo n.º 2
0
    @Override
    protected Control addLabel(Composite parent) {
      if (fCreateTargetQuery != null) {
        Composite firstLine = new Composite(parent, SWT.NONE);
        GridLayout layout = new GridLayout(2, false);
        layout.marginHeight = layout.marginWidth = 0;
        firstLine.setLayout(layout);
        firstLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        Control label = super.addLabel(firstLine);
        label.addTraverseListener(
            new TraverseListener() {
              @Override
              public void keyTraversed(TraverseEvent e) {
                if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) {
                  e.detail = SWT.TRAVERSE_NONE;
                  getTreeViewer().getTree().setFocus();
                }
              }
            });

        Button newButton = new Button(firstLine, SWT.PUSH);
        newButton.setText(fCreateTargetQuery.getNewButtonLabel());
        GridData gd =
            new GridData(
                GridData.HORIZONTAL_ALIGN_END
                    | GridData.GRAB_HORIZONTAL
                    | GridData.VERTICAL_ALIGN_BEGINNING);
        gd.widthHint = SWTUtil.getButtonWidthHint(newButton);
        newButton.setLayoutData(gd);
        newButton.addSelectionListener(
            new SelectionAdapter() {
              @Override
              public void widgetSelected(SelectionEvent e) {
                doNewButtonPressed();
              }
            });

        return firstLine;

      } else {
        return super.addLabel(parent);
      }
    }