private void handleNewFeature() {
   final Control control = fCategoryViewer.getControl();
   BusyIndicator.showWhile(
       control.getDisplay(),
       new Runnable() {
         public void run() {
           IFeatureModel[] allModels = PDECore.getDefault().getFeatureModelManager().getModels();
           ArrayList<IFeatureModel> newModels = new ArrayList<IFeatureModel>();
           for (int i = 0; i < allModels.length; i++) {
             if (canAdd(allModels[i])) newModels.add(allModels[i]);
           }
           IFeatureModel[] candidateModels =
               newModels.toArray(new IFeatureModel[newModels.size()]);
           FeatureSelectionDialog dialog =
               new FeatureSelectionDialog(
                   fCategoryViewer.getTree().getShell(), candidateModels, true);
           if (dialog.open() == Window.OK) {
             Object[] models = dialog.getResult();
             try {
               doAdd(models);
             } catch (CoreException e) {
               PDEPlugin.log(e);
             }
           }
         }
       });
 }
Example #2
0
 /** Register the context menu for the viewer so that commands may be added to it. */
 private void registerContextMenu() {
   MenuManager contextMenu = new MenuManager();
   contextMenu.setRemoveAllWhenShown(true);
   getSite().registerContextMenu(contextMenu, mViewer);
   Control control = mViewer.getControl();
   Menu menu = contextMenu.createContextMenu(control);
   control.setMenu(menu);
 }
 public Resizer(Control c, int dir) {
   fDirection = dir;
   fControl = c;
   fLiveResize = !(fControl instanceof Sash);
   updateCursor(c, dir);
   fControl.addMouseListener(this);
   fControl.addMouseMoveListener(this);
   fControl.addDisposeListener(
       new DisposeListener() {
         public void widgetDisposed(DisposeEvent e) {
           fControl = null;
         }
       });
 }
 /* (non-Javadoc)
  * @see org.eclipse.pde.internal.core.IPluginModelListener#modelsChanged(org.eclipse.pde.internal.core.PluginModelDelta)
  */
 public void modelsChanged(PluginModelDelta delta) {
   final Control control = fPluginTable.getControl();
   if (!control.isDisposed()) {
     control
         .getDisplay()
         .asyncExec(
             new Runnable() {
               public void run() {
                 if (!control.isDisposed()) {
                   fPluginTable.refresh();
                   updateRemoveButtons(true, true);
                 }
               }
             });
   }
 }
 void updateCursor(Control c, int dir) {
   if (!(c instanceof Sash)) {
     Cursor cursor = null;
     switch (dir) {
       case VERTICAL:
         if (fAncestorVisible) {
           if (fVSashCursor == null) fVSashCursor = new Cursor(c.getDisplay(), SWT.CURSOR_SIZENS);
           cursor = fVSashCursor;
         } else {
           if (fNormalCursor == null) fNormalCursor = new Cursor(c.getDisplay(), SWT.CURSOR_ARROW);
           cursor = fNormalCursor;
         }
         break;
       case HORIZONTAL:
         if (fHSashCursor == null) fHSashCursor = new Cursor(c.getDisplay(), SWT.CURSOR_SIZEWE);
         cursor = fHSashCursor;
         break;
       case VERTICAL + HORIZONTAL:
         if (fAncestorVisible) {
           if (fHVSashCursor == null)
             fHVSashCursor = new Cursor(c.getDisplay(), SWT.CURSOR_SIZEALL);
           cursor = fHVSashCursor;
         } else {
           if (fHSashCursor == null) fHSashCursor = new Cursor(c.getDisplay(), SWT.CURSOR_SIZEWE);
           cursor = fHSashCursor;
         }
         break;
     }
     if (cursor != null) c.setCursor(cursor);
   }
 }
  private void createSourceViewer(Composite parent) {
    sourceFileViewer =
        new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER));
    sourceFileViewer.setContentProvider(new WorkbenchContentProvider());
    sourceFileViewer.setLabelProvider(new WorkbenchLabelProvider());
    sourceFileViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          public void selectionChanged(SelectionChangedEvent event) {
            java.util.List list;
            ISelection selection = event.getSelection();
            boolean newFilesSelected = false;

            if (selection instanceof IStructuredSelection) {
              list = ((IStructuredSelection) selection).toList();
              for (Iterator i = list.iterator(); i.hasNext(); ) {
                IResource resource = (IResource) i.next();
                if (resource instanceof IFile) {
                  if (checkIfFileInTarget((IFile) resource) == false) newFilesSelected = true;
                }
              }
              setAddButtonEnabled(newFilesSelected);
            }
          }
        });
    sourceFileViewer.addDoubleClickListener(
        new IDoubleClickListener() {
          public void doubleClick(DoubleClickEvent event) {
            addSelectedFilesToTargetList();
          }
        });

    Control treeWidget = sourceFileViewer.getTree();
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = SIZING_LISTS_WIDTH;
    gd.heightHint = SIZING_LISTS_HEIGHT;
    treeWidget.setLayoutData(gd);
  }
    public void mouseDown(MouseEvent e) {
      Composite parent = fControl.getParent();

      Point s = parent.getSize();
      Point as = fAncestorLabel.getSize();
      Point ys = fLeftLabel.getSize();
      Point ms = fRightLabel.getSize();

      fWidth1 = ys.x;
      fWidth2 = ms.x;
      fHeight1 = fLeftLabel.getLocation().y - as.y;
      fHeight2 = s.y - (fLeftLabel.getLocation().y + ys.y);

      fX = e.x;
      fY = e.y;
      fIsDown = true;
    }
  /**
   * Builds the SWT controls for the three areas of a compare/merge viewer.
   *
   * <p>Calls the hooks <code>createControls</code> and <code>createToolItems</code> to let
   * subclasses build the specific content areas and to add items to an enclosing toolbar.
   *
   * <p>This method must only be called in the constructor of subclasses.
   *
   * @param parent the parent control
   * @return the new control
   */
  protected final Control buildControl(Composite parent) {

    fComposite =
        new Composite(parent, fStyles | SWT.LEFT_TO_RIGHT) { // we
          // force
          // a
          // specific
          // direction
          public boolean setFocus() {
            return ContentMergeViewer.this.handleSetFocus();
          }
        };
    fComposite.setData(CompareUI.COMPARE_VIEWER_TITLE, getTitle());

    hookControl(fComposite); // hook help & dispose listener

    fComposite.setLayout(new ContentMergeViewerLayout());

    int style = SWT.SHADOW_OUT;
    fAncestorLabel = new CLabel(fComposite, style | Window.getDefaultOrientation());

    fLeftLabel = new CLabel(fComposite, style | Window.getDefaultOrientation());
    new Resizer(fLeftLabel, VERTICAL);

    fDirectionLabel = new CLabel(fComposite, style);
    fDirectionLabel.setAlignment(SWT.CENTER);
    new Resizer(fDirectionLabel, HORIZONTAL | VERTICAL);

    fRightLabel = new CLabel(fComposite, style | Window.getDefaultOrientation());
    new Resizer(fRightLabel, VERTICAL);

    if (fCenter == null || fCenter.isDisposed()) fCenter = createCenterControl(fComposite);

    createControls(fComposite);

    fHandlerService =
        CompareHandlerService.createFor(
            getCompareConfiguration().getContainer(), fComposite.getShell());

    initializeToolbars(parent);

    return fComposite;
  }
    private void resize(MouseEvent e) {
      int dx = e.x - fX;
      int dy = e.y - fY;

      int centerWidth = fCenter.getSize().x;

      if (fWidth1 + dx > centerWidth && fWidth2 - dx > centerWidth) {
        fWidth1 += dx;
        fWidth2 -= dx;
        if ((fDirection & HORIZONTAL) != 0)
          fHSplit = (double) fWidth1 / (double) (fWidth1 + fWidth2);
      }
      if (fHeight1 + dy > centerWidth && fHeight2 - dy > centerWidth) {
        fHeight1 += dy;
        fHeight2 -= dy;
        if ((fDirection & VERTICAL) != 0)
          fVSplit = (double) fHeight1 / (double) (fHeight1 + fHeight2);
      }

      fComposite.layout(true);
      fControl.getDisplay().update();
    }
  @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;
  }