public void handleEvent(Event event) {
          // Ensure that this event is for a MMenuItem
          if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) return;

          MToolBarElement itemModel =
              (MToolBarElement) event.getProperty(UIEvents.EventTags.ELEMENT);
          String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);
          if (UIEvents.UIElement.TOBERENDERED.equals(attName)) {
            Object obj = itemModel.getParent();
            if (!(obj instanceof MToolBar)) {
              return;
            }
            ToolBarManager parent = getManager((MToolBar) obj);
            if (itemModel.isToBeRendered()) {
              if (parent != null) {
                modelProcessSwitch(parent, itemModel);
                parent.update(true);
                ToolBar tb = parent.getControl();
                if (tb != null && !tb.isDisposed()) {
                  tb.pack(true);
                  tb.getShell().layout(new Control[] {tb}, SWT.DEFER);
                }
              }
            } else {
              IContributionItem ici = modelToContribution.remove(itemModel);
              if (ici != null && parent != null) {
                parent.remove(ici);
              }
              if (ici != null) {
                ici.dispose();
              }
            }
          } else if (UIEvents.UIElement.VISIBLE.equals(attName)) {
            IContributionItem ici = getContribution(itemModel);
            if (ici == null) {
              return;
            }
            ici.setVisible(itemModel.isVisible());
            ToolBarManager parent = (ToolBarManager) ((ContributionItem) ici).getParent();
            if (parent != null) {
              parent.markDirty();
              parent.update(true);
              // MUIElement tbModel = itemModel.getParent();
              // disposeToolbarIfNecessary((MToolBar) tbModel);
              ToolBar tb = parent.getControl();
              if (tb != null && !tb.isDisposed()) {
                tb.pack(true);
                tb.getShell().layout(new Control[] {tb}, SWT.DEFER);
              }
            }
          }
        }
Ejemplo n.º 2
0
 public void addActions(IAction[] actions) {
   if (actions == null) return;
   for (int i = 0; i < actions.length; i++) {
     toolBarManager.add(createActionContributionItem(actions[i]));
   }
   toolBarManager.update(true);
 }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents
   * (org.eclipse.e4.ui.model.application.ui.MElementContainer)
   */
  @Override
  public void processContents(MElementContainer<MUIElement> container) {
    // I can either simply stop processing, or we can walk the model
    // ourselves like the "old" days
    // EMF gives us null lists if empty
    if (container == null) return;

    Object obj = container;
    ToolBarManager parentManager = getManager((MToolBar) obj);
    if (parentManager == null) {
      return;
    }
    // Process any contents of the newly created ME
    List<MUIElement> parts = container.getChildren();
    if (parts != null) {
      MUIElement[] plist = parts.toArray(new MUIElement[parts.size()]);
      for (int i = 0; i < plist.length; i++) {
        MUIElement childME = plist[i];
        modelProcessSwitch(parentManager, (MToolBarElement) childME);
      }
    }
    parentManager.update(true);

    ToolBar tb = getToolbarFrom(container.getWidget());
    if (tb != null) {
      tb.pack(true);
      tb.getShell().layout(new Control[] {tb}, SWT.DEFER);
    }
  }
Ejemplo n.º 4
0
  private void createFeaturesToolbar(FormToolkit toolkit, Section section) {
    Composite headerComposite = toolkit.createComposite(section, SWT.NONE);
    RowLayout rowLayout = new RowLayout();
    rowLayout.marginTop = 0;
    rowLayout.marginBottom = 0;
    headerComposite.setLayout(rowLayout);
    headerComposite.setBackground(null);

    toolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
    toolBarManager.createControl(headerComposite);

    installAction = new InstallAction();
    installAction.setEnabled(false);
    toolBarManager.add(installAction);

    toolBarManager.add(new CheckForUpdatesAction());

    CommandContributionItem item =
        JBossCentralActivator.createContributionItem(
            getSite(), "org.jboss.tools.central.refreshDiscovery");
    toolBarManager.add(item);

    toolBarManager.update(true);

    section.setTextClient(headerComposite);
  }
Ejemplo n.º 5
0
  @Override
  public void createPartControl(final Composite parent) {
    resizeAction =
        new Action("Resize", SWT.TOGGLE) {
          @Override
          public void run() {
            updatePreview(true);
          }
        };
    resizeAction.setImageDescriptor(
        Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "/icons/resize.png"));

    GridLayoutFactory.fillDefaults().numColumns(2).spacing(0, 0).applyTo(parent);
    ToolBar toolbar = new ToolBar(parent, SWT.VERTICAL | SWT.FLAT);
    toolbar.setBackground(toolbar.getDisplay().getSystemColor(SWT.COLOR_GRAY));
    ToolBarManager toolbarManager = new ToolBarManager(toolbar);
    toolbarManager.add(resizeAction);
    GridDataFactory.fillDefaults()
        .grab(false, true)
        .align(SWT.BEGINNING, SWT.FILL)
        .applyTo(toolbar);
    toolbarManager.update(true);

    container = new Composite(parent, SWT.NONE);
    container.setLayout(new FillLayout());
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(container);

    getSite().getPage().addPartListener(trackRelevantEditorsPartListener);
    tryConnectTo(getSite().getPage().getActiveEditor());
  }
 @Override
 public IInformationControl createInformationControl(Shell parent) {
   if (BrowserInformationControl.isAvailable(parent)) {
     if (!enriched) {
       return new SpringPropertiesInformationControl(
           parent, PreferenceConstants.APPEARANCE_JAVADOC_FONT, statusText) {
         @Override
         public IInformationControlCreator getInformationPresenterControlCreator() {
           return new SpringPropertiesInformationControlCreator(true, null);
         }
       };
     } else {
       ToolBarManager toolbar = new ToolBarManager(SWT.FLAT);
       BrowserInformationControl control =
           new SpringPropertiesInformationControl(
               parent, PreferenceConstants.APPEARANCE_JAVADOC_FONT, toolbar) {
             @Override
             public IInformationControlCreator getInformationPresenterControlCreator() {
               return new SpringPropertiesInformationControlCreator(true, null);
             }
           };
       fillToolbar(toolbar, control);
       toolbar.update(true);
       return control;
     }
   }
   return new DefaultInformationControl(parent, true);
 }
 /** Updates the history controls. */
 private void updateHistoryControls() {
   historyToolbar.update(false);
   IContributionItem[] items = historyToolbar.getItems();
   for (int i = 0; i < items.length; i++) {
     items[i].update(IAction.ENABLED);
     items[i].update(IAction.TOOL_TIP_TEXT);
   }
 }
Ejemplo n.º 8
0
  private void initializeToolbars(Composite parent) {
    ToolBarManager tbm = CompareViewerPane.getToolBarManager(parent);
    if (tbm != null) {
      tbm.removeAll();

      // define groups
      tbm.add(new Separator("modes")); // $NON-NLS-1$
      tbm.add(new Separator("merge")); // $NON-NLS-1$
      tbm.add(new Separator("navigation")); // $NON-NLS-1$

      CompareConfiguration cc = getCompareConfiguration();

      if (cc.isRightEditable()) {
        fCopyLeftToRightAction =
            new Action() {
              public void run() {
                copy(true);
              }
            };
        Utilities.initAction(
            fCopyLeftToRightAction, getResourceBundle(), "action.CopyLeftToRight."); // $NON-NLS-1$
        tbm.appendToGroup("merge", fCopyLeftToRightAction); // $NON-NLS-1$
        fHandlerService.registerAction(
            fCopyLeftToRightAction, "org.eclipse.compare.copyAllLeftToRight"); // $NON-NLS-1$
      }

      if (cc.isLeftEditable()) {
        fCopyRightToLeftAction =
            new Action() {
              public void run() {
                copy(false);
              }
            };
        Utilities.initAction(
            fCopyRightToLeftAction, getResourceBundle(), "action.CopyRightToLeft."); // $NON-NLS-1$
        tbm.appendToGroup("merge", fCopyRightToLeftAction); // $NON-NLS-1$
        fHandlerService.registerAction(
            fCopyRightToLeftAction, "org.eclipse.compare.copyAllRightToLeft"); // $NON-NLS-1$
      }

      final ChangePropertyAction a =
          new ChangePropertyAction(
              fBundle,
              getCompareConfiguration(),
              "action.EnableAncestor.",
              ICompareUIConstants.PROP_ANCESTOR_VISIBLE); // $NON-NLS-1$
      a.setChecked(fAncestorVisible);
      fAncestorItem = new ActionContributionItem(a);
      fAncestorItem.setVisible(false);
      tbm.appendToGroup("modes", fAncestorItem); // $NON-NLS-1$
      tbm.getControl().addDisposeListener(a);

      createToolItems(tbm);
      updateToolItems();

      tbm.update(true);
    }
  }
Ejemplo n.º 9
0
  /**
   * Create the filter controls. By default, a text and corresponding tool bar button that clears
   * the contents of the text is created. Subclasses may override.
   *
   * @param parent parent <code>Composite</code> of the filter controls
   * @return the <code>Composite</code> that contains the filter controls
   */
  protected Composite createFilterControls(Composite parent) {
    createFilterText(parent);
    createClearText(parent);

    filterToolBar.update(false);
    // initially there is no text to clear
    filterToolBar.getControl().setVisible(false);
    return parent;
  }
Ejemplo n.º 10
0
  /**
   * Sets the child viewer. This method should only be called once, after the viewer has been
   * created.
   *
   * @param aViewer the new child viewer
   */
  public void setChildTree(TreeViewer aViewer) {
    // Save viewer.
    fChildTree = aViewer;

    // Create adapter.
    adapter = new DrillDownAdapter(fChildTree);
    adapter.addNavigationActions(toolBarMgr);
    toolBarMgr.update(true);

    // Set tree layout.
    fChildTree.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    layout();
  }
 /**
  * Create the composite.
  *
  * @param parent a widget which will be the parent of the new instance (cannot be null)
  * @param style the style of widget to construct
  */
 public VisualisationDiffToolBar(Composite parent, int style) {
   super(parent, style);
   createActions();
   setLayout(new FormLayout());
   /** Left Tool Bar */
   Composite leftToolBarComposite = new Composite(this, SWT.NONE);
   leftToolBarComposite.setLayout(new FormLayout());
   FormData fdleftToolBarComposite = new FormData();
   fdleftToolBarComposite.top = new FormAttachment(0);
   fdleftToolBarComposite.left = new FormAttachment(0);
   leftToolBarComposite.setLayoutData(fdleftToolBarComposite);
   ToolBar leftToolBar = new ToolBar(leftToolBarComposite, SWT.FLAT | SWT.RIGHT);
   FormData fdleftToolBar = new FormData();
   fdleftToolBar.top = new FormAttachment(0);
   leftToolBar.setLayoutData(fdleftToolBar);
   visualizationType = new ToolItem(leftToolBar, SWT.NONE);
   visualizationType.setImage(
       ResourceManager.getPluginImage(
           "org.eclipse.emf.compare.ui.2", "iconsMainTBar/differencesIcon.gif"));
   visualizationType.setText("Visualizatin of Structural Differences");
   // lblNewLabel.setImage(ResourceManager.getPluginImage("org.eclipse.emf.compare.ui.2",
   // "icons/next_nav_into.gif"));
   leftToolBar.update();
   /** RighToolBar */
   ToolBar righToolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
   FormData fdRighToolBar = new FormData();
   fdRighToolBar.top = new FormAttachment(0);
   fdRighToolBar.right = new FormAttachment(100);
   righToolBar.setLayoutData(fdRighToolBar);
   ToolBarManager righToolBarManager = new ToolBarManager(righToolBar);
   createAncestorPaneManagerAction(righToolBarManager, EMFCompareConfiguration.fThreeWay);
   righToolBarManager.add(copyAlltoRight);
   righToolBarManager.add(copyAlltoLeft);
   righToolBarManager.add(copyLeftTorRight);
   righToolBarManager.add(copyRightToLeft);
   righToolBarManager.add(new Separator());
   righToolBarManager.add(nextChange);
   righToolBarManager.add(previousChange);
   righToolBar.update();
   righToolBarManager.update(true);
 }
  private void createSectionToolbar(Section section, FormToolkit toolkit) {
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolbar = toolBarManager.createControl(section);
    final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
    toolbar.setCursor(handCursor);
    // Cursor needs to be explicitly disposed
    toolbar.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            if (handCursor.isDisposed() == false) {
              handCursor.dispose();
            }
          }
        });
    fNewPluginAction = new NewPluginAction();
    fNewFragmentAction = new NewFragmentAction();
    toolBarManager.add(fNewPluginAction);
    toolBarManager.add(fNewFragmentAction);

    toolBarManager.update(true);
    section.setTextClient(toolbar);
  }
Ejemplo n.º 13
0
  private void internalRefresh(Object input) {

    IMergeViewerContentProvider content = getMergeContentProvider();
    if (content == null) {
      return;
    }
    Object ancestor = content.getAncestorContent(input);
    boolean oldFlag = fIsThreeWay;
    if (Utilities.isHunk(input)) {
      fIsThreeWay = true;
    } else if (input instanceof ICompareInput)
      fIsThreeWay = (((ICompareInput) input).getKind() & Differencer.DIRECTION_MASK) != 0;
    else fIsThreeWay = ancestor != null;

    if (fAncestorItem != null) fAncestorItem.setVisible(fIsThreeWay);

    if (fAncestorVisible && oldFlag != fIsThreeWay) fComposite.layout(true);

    Object left = content.getLeftContent(input);
    Object right = content.getRightContent(input);
    updateContent(ancestor, left, right);

    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=453799
    // Content provider may be disposed after call to updateContent()
    content = getMergeContentProvider();
    if (content == null) {
      return;
    }

    updateHeader();
    ToolBarManager tbm = CompareViewerPane.getToolBarManager(fComposite.getParent());
    if (tbm != null) {
      updateToolItems();
      tbm.update(true);
      tbm.getControl().getParent().layout(true);
    }
  }
Ejemplo n.º 14
0
  protected void createSectionToolbar(Section section, FormToolkit toolkit) {
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolbar = toolBarManager.createControl(section);
    final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
    toolbar.setCursor(handCursor);
    // Cursor needs to be explicitly disposed
    toolbar.addDisposeListener(
        new DisposeListener() {
          @Override
          public void widgetDisposed(DisposeEvent e) {
            if ((handCursor != null) && (handCursor.isDisposed() == false)) {
              handCursor.dispose();
            }
          }
        });

    // save
    ActionContributionItem saveMenuAction =
        new ActionContributionItem(ActionFactory.SAVE.create(getEditorSite().getWorkbenchWindow()));
    toolBarManager.add(saveMenuAction);
    toolBarManager.update(true);

    section.setTextClient(toolbar);
  }
Ejemplo n.º 15
0
  /**
   * Adds the header to a parent composite.
   *
   * @param parent the parent
   */
  protected void createHeader(Composite parent) {
    final Composite headerComposite = new Composite(parent, SWT.NONE);
    final GridLayout headerLayout = GridLayoutFactory.fillDefaults().create();
    headerComposite.setLayout(headerLayout);
    GridDataFactory.fillDefaults()
        .align(SWT.FILL, SWT.FILL)
        .grab(true, false)
        .applyTo(headerComposite);
    headerBgColor = new Color(parent.getDisplay(), new RGB(220, 240, 247));
    headerComposite.setBackground(headerBgColor);

    final EObject modelElement = getViewModelContext().getDomainModel();
    final EditingDomain editingDomain =
        AdapterFactoryEditingDomain.getEditingDomainFor(modelElement);

    /* The header of the composite */
    if (modelElement.eContainer() == null && !DynamicEObjectImpl.class.isInstance(modelElement)) {

      final Composite header = getPageHeader(headerComposite);
      final List<Action> actions = readToolbarActions(modelElement, editingDomain);

      final ToolBar toolBar = new ToolBar(header, SWT.FLAT | SWT.RIGHT);
      final FormData formData = new FormData();
      formData.right = new FormAttachment(100, 0);
      toolBar.setLayoutData(formData);
      toolBar.layout();
      final ToolBarManager toolBarManager = new ToolBarManager(toolBar);

      /* Add actions to header */
      for (final Action action : actions) {
        toolBarManager.add(action);
      }
      toolBarManager.update(true);
      header.layout();
    }
  }
Ejemplo n.º 16
0
  private void createDialogUI(Composite parent) {
    GridLayoutFactory.fillDefaults().margins(12, 6).applyTo(parent);

    SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL);
    GridDataFactory.fillDefaults()
        .grab(true, true)
        .align(SWT.FILL, SWT.FILL)
        .hint(725, 360)
        .applyTo(sashForm);

    Composite leftComposite = new Composite(sashForm, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(leftComposite);
    GridDataFactory.swtDefaults()
        .grab(false, true)
        .align(SWT.FILL, SWT.FILL)
        .applyTo(leftComposite);

    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = toolBarManager.createControl(leftComposite);
    toolBar.setBackground(parent.getBackground());
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.BEGINNING, SWT.FILL).applyTo(toolBar);

    launchesViewer = new TableViewer(leftComposite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
    launchesViewer.setLabelProvider(
        new DelegatingStyledCellLabelProvider(new LaunchConfigLabelProvider()));
    launchesViewer.setComparator(new ViewerComparator(String.CASE_INSENSITIVE_ORDER));
    launchesViewer.setContentProvider(new LaunchConfigContentProvider());
    launchesViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
    launchesViewer.getTable().setFocus();
    launchesViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            handleSelectedConfigChanged();
          }
        });

    GridDataFactory.swtDefaults()
        .grab(false, true)
        .align(SWT.FILL, SWT.FILL)
        .hint(50, 50)
        .applyTo(launchesViewer.getControl());

    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();

    for (final ILaunchConfigurationType configType : manager.getLaunchConfigurationTypes()) {
      CreateLaunchAction action = new CreateLaunchAction(this, configType);

      toolBarManager.add(action);
    }

    // toolBarManager.add(new Separator());
    toolBarManager.add(getDeleteAction());

    toolBarManager.update(true);

    configUI = new Composite(sashForm, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(configUI);
    GridDataFactory.swtDefaults()
        .grab(true, false)
        .align(SWT.FILL, SWT.BEGINNING)
        .applyTo(configUI);

    toolBar.pack();
    Label toolbarSpacer = new Label(configUI, SWT.NONE);
    GridDataFactory.swtDefaults().hint(SWT.NONE, toolBar.getSize().y).applyTo(toolbarSpacer);

    Composite nameComposite = new Composite(configUI, SWT.NONE);
    GridDataFactory.swtDefaults()
        .grab(true, false)
        .align(SWT.FILL, SWT.FILL)
        .applyTo(nameComposite);
    GridLayoutFactory.swtDefaults().margins(6, 0).applyTo(nameComposite);

    configNameText = new Text(nameComposite, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.swtDefaults()
        .grab(true, false)
        .align(SWT.FILL, SWT.CENTER)
        .applyTo(configNameText);
    configNameText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            if (workingCopy != null) {
              workingCopy.rename(configNameText.getText());
            }
          }
        });

    launchConfigArea = new ScrolledComposite(configUI, SWT.V_SCROLL);
    GridDataFactory.swtDefaults()
        .grab(true, true)
        .align(SWT.FILL, SWT.FILL)
        .applyTo(launchConfigArea);
    launchConfigArea.setExpandVertical(false);
    launchConfigArea.setExpandHorizontal(true);

    configNameText.setVisible(false);

    sashForm.setWeights(new int[] {33, 67});

    selectLaunchConfigFromPage();
  }
Ejemplo n.º 17
0
  /* (non-Javadoc)
   * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
   */
  @Override
  protected void createFormContent(IManagedForm managedForm) {
    this.mForm = managedForm;
    // form
    ScrolledForm form = managedForm.getForm();
    this.toolkit = OpenDartsFormsToolkit.getToolkit();
    form.setText(this.game.getName());
    this.toolkit.decorateFormHeading(form.getForm());

    GridDataFactory playerData;
    GridDataFactory scoreData;
    scoreData = GridDataFactory.fillDefaults().grab(true, false).span(2, 1);

    List<IPlayer> players = this.game.getPlayers();
    boolean twoPlayer = (players.size() == 2);
    // body
    int nbCol;
    int tableSpan;
    if (twoPlayer) {
      nbCol = 4;
      tableSpan = 2;
      playerData = GridDataFactory.fillDefaults().grab(false, true);
      scoreData = GridDataFactory.fillDefaults().grab(true, false).span(2, 1);
    } else {
      nbCol = players.size();
      tableSpan = nbCol;
      playerData = GridDataFactory.fillDefaults().grab(false, true);
      scoreData = GridDataFactory.fillDefaults().grab(true, false);
    }
    this.body = form.getBody();
    GridLayoutFactory.fillDefaults()
        .margins(5, 5)
        .numColumns(nbCol)
        .equalWidth(true)
        .applyTo(this.body);

    if (twoPlayer) {
      // First Player Status
      Composite cmpPlayerOne = this.createPlayerComposite(this.body, this.game.getFirstPlayer());
      playerData.copy().applyTo(cmpPlayerOne);
    } else {
      // create multi player stats
    }

    // Score
    Composite cmpScore = this.createScoreTableComposite(this.body);
    GridDataFactory.fillDefaults().grab(true, true).span(tableSpan, 1).applyTo(cmpScore);

    if (twoPlayer) {
      // Second Player Status
      Composite cmpPlayerTwo = this.createPlayerComposite(this.body, this.game.getSecondPlayer());
      playerData.copy().applyTo(cmpPlayerTwo);
    }

    // Left score
    Composite leftScoreMain = this.createLeftScoreComposite(nbCol, scoreData);
    GridDataFactory.fillDefaults().grab(true, false).span(nbCol, 1).applyTo(leftScoreMain);

    // Toolbar
    ToolBarManager manager = (ToolBarManager) form.getToolBarManager();
    IMenuService menuService = (IMenuService) this.getSite().getService(IMenuService.class);
    menuService.populateContributionManager(manager, "toolbar:openwis.editor.game.toolbar");
    manager.add(
        new ControlContribution("openwis.editor.game.toolbar.help") {
          @Override
          protected Control createControl(Composite parent) {
            Label helpLabel = new Label(parent, SWT.NONE);
            helpLabel.setImage(ProtoPlugin.getImage("/icons/actions/help.png"));
            ToolTip toolTip = new ShortcutsTooltip(helpLabel);
            toolTip.setPopupDelay(0);
            return helpLabel;
          }
        });
    manager.update(true);

    // Register listener
    this.game.addListener(this);

    // initialize game
    for (TableViewer viewer : this.scoreViewers.values()) {
      viewer.setInput(this.game);
    }
    this.handlePlayer(this.game.getCurrentPlayer(), this.game.getCurrentEntry());
  }
  /**
   * Get the toolbar for the container
   *
   * @return Control
   */
  Control getContainerToolBar(Composite composite) {

    final ToolBarManager historyManager = new ToolBarManager(SWT.HORIZONTAL | SWT.FLAT);
    historyManager.createControl(composite);

    history.createHistoryControls(historyManager.getControl(), historyManager);

    Action popupMenuAction =
        new Action() {
          @Override
          public ImageDescriptor getImageDescriptor() {
            return WorkbenchImages.getImageDescriptor(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
          }

          @Override
          public void run() {
            MenuManager manager = new MenuManager();
            manager.add(
                new Action() {
                  @Override
                  public void run() {

                    sash.addFocusListener(
                        new FocusAdapter() {
                          @Override
                          public void focusGained(FocusEvent e) {
                            sash.setBackground(
                                sash.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
                          }

                          @Override
                          public void focusLost(FocusEvent e) {
                            sash.setBackground(
                                sash.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
                          }
                        });
                    sash.setFocus();
                  }

                  @Override
                  public String getText() {
                    return WorkbenchMessages.FilteredPreferenceDialog_Resize;
                  }
                });
            manager.add(
                new Action() {
                  @Override
                  public void run() {
                    activeKeyScrolling();
                  }

                  @Override
                  public String getText() {
                    return WorkbenchMessages.FilteredPreferenceDialog_Key_Scrolling;
                  }
                });
            Menu menu = manager.createContextMenu(getShell());
            Rectangle bounds = historyManager.getControl().getBounds();
            Point topLeft = new Point(bounds.x + bounds.width, bounds.y + bounds.height);
            topLeft = historyManager.getControl().toDisplay(topLeft);
            menu.setLocation(topLeft.x, topLeft.y);
            menu.setVisible(true);
          }
        };
    popupMenuAction.setToolTipText(WorkbenchMessages.FilteredPreferenceDialog_FilterToolTip);
    historyManager.add(popupMenuAction);
    IHandlerService service = PlatformUI.getWorkbench().getService(IHandlerService.class);
    showViewHandler =
        service.activateHandler(
            IWorkbenchCommandConstants.WINDOW_SHOW_VIEW_MENU,
            new ActionHandler(popupMenuAction),
            new ActiveShellExpression(getShell()));

    historyManager.update(false);

    return historyManager.getControl();
  }
Ejemplo n.º 19
0
  /**
   * Add a new (SQL) Execution Tab
   *
   * @param AbstractSQLExecution
   */
  public void addSQLExecution(AbstractSQLExecution sqlExecution) {

    if (_tabFolder == null || _tabFolder.isDisposed()) {

      clearParent();

      // create tab folder for different sessions
      _tabFolder = new TabFolder(_parent, SWT.NULL);

      _parent.layout();
      _parent.redraw();
    }

    // create tab
    _lastTabNumber = _lastTabNumber + 1;
    final TabItem tabItem = new TabItem(_tabFolder, SWT.NULL);

    // set tab text & tooltip
    String labelText = "" + _lastTabNumber;
    tabItem.setText(labelText);
    tabItem.setData("tabLabel", labelText);
    tabItem.setToolTipText(TextUtil.getWrappedText(sqlExecution.getSqlStatement()));

    // create composite for our result
    Composite composite = new Composite(_tabFolder, SWT.NULL);

    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginLeft = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 2;
    layout.marginWidth = 0;
    layout.marginHeight = 0;

    composite.setLayout(layout);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    tabItem.setControl(composite);
    tabItem.setData(sqlExecution);

    tabItem.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(final DisposeEvent e) {

            BusyIndicator.showWhile(
                Display.getCurrent(),
                new Runnable() {

                  public void run() {

                    // stop all sql execution if still running
                    TabItem tabItem = (TabItem) e.getSource();
                    AbstractSQLExecution sqlExecution = (AbstractSQLExecution) tabItem.getData();
                    sqlExecution.stop();
                    tabItem.setData(null);

                    if (_tabFolder != null && !_tabFolder.isDisposed()) {

                      if (_tabFolder.getItemCount() == 0) {
                        // this is last tab..
                        clearParent();
                        setDefaultMessage();
                      }

                    } else if (_tabFolder.isDisposed()) {
                      clearParent();
                      setDefaultMessage();
                    }
                  }
                });
          }
        });

    // add sql statement, first create temp label to calculate correct size

    String sqlStatement = sqlExecution.getSqlStatement();

    int labelHeight = 60;
    int labelStyle = SWT.WRAP | SWT.MULTI;

    Text tmpLabel = new Text(composite, labelStyle);
    tmpLabel.setText(TextUtil.removeLineBreaks(sqlExecution.getSqlStatement()));
    tmpLabel.setLayoutData(new FillLayout());
    int parentWidth = _parent.getClientArea().width;
    Point idealSize = tmpLabel.computeSize(parentWidth - 30, SWT.DEFAULT);

    if (idealSize.y <= 60) {
      // we don't need a scroll bar. minimize
      labelHeight = idealSize.y;
    } else {
      // we need a scroll bar
      labelStyle = SWT.WRAP | SWT.MULTI | SWT.V_SCROLL;
    }

    tmpLabel.dispose();

    // now create real label
    // create spanned cell for table data

    Composite headerComposite = new Composite(composite, SWT.FILL);
    headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    GridLayout hLayout = new GridLayout();
    hLayout.numColumns = 2;
    hLayout.marginLeft = 0;
    hLayout.horizontalSpacing = 0;
    hLayout.verticalSpacing = 0;
    hLayout.marginWidth = 0;
    hLayout.marginHeight = 0;

    headerComposite.setLayout(hLayout);

    Text label = new Text(headerComposite, labelStyle);
    label.setEditable(false);
    label.setBackground(_parent.getBackground());
    label.setText(TextUtil.removeLineBreaks(sqlStatement));
    label.setToolTipText(TextUtil.getWrappedText(sqlStatement));

    GridData labelGridData = new GridData(SWT.FILL, SWT.TOP, true, false);
    labelGridData.heightHint = labelHeight;
    label.setLayoutData(labelGridData);

    // add action bar

    ToolBarManager toolBarMgr = new ToolBarManager(SWT.FLAT);
    toolBarMgr.createControl(headerComposite);
    toolBarMgr.add(new CloseSQLResultTab(tabItem));
    toolBarMgr.update(true);
    GridData gid = new GridData();
    gid.horizontalAlignment = SWT.RIGHT;
    gid.verticalAlignment = SWT.TOP;
    toolBarMgr.getControl().setLayoutData(gid);

    // add detail composite to show progress bar and results
    Composite detailComposite = new Composite(composite, SWT.FILL);
    detailComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    sqlExecution.setComposite(detailComposite);
    sqlExecution.setParentTab(tabItem);
    sqlExecution.startExecution();

    // set new tab as the active one
    _tabFolder.setSelection(_tabFolder.getItemCount() - 1);

    // refresh view
    composite.layout();
    _tabFolder.layout();
    _tabFolder.redraw();

    // bring this view to top of the view stack
    getSite().getPage().bringToTop(this);
  }
Ejemplo n.º 20
0
  private void updateLeftHeaderToolBar() {
    leftToolBarManager.removeAll();

    leftToolBarManager.add(new Separator("activation")); // $NON-NLS-1$
    leftToolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));

    //		initialLeftToolbarSize = leftToolBarManager.getSize();

    leftToolBarManager.add(activateAction);

    //		for (IFormPage page : getPages()) {
    //			if (page instanceof AbstractTaskEditorPage) {
    //				AbstractTaskEditorPage taskEditorPage = (AbstractTaskEditorPage) page;
    //				taskEditorPage.fillLeftHeaderToolBar(leftToolBarManager);
    //			} else if (page instanceof TaskPlanningEditor) {
    //				TaskPlanningEditor taskEditorPage = (TaskPlanningEditor) page;
    //				taskEditorPage.fillLeftHeaderToolBar(leftToolBarManager);
    //			}
    //		}

    // add external contributions
    menuService = (IMenuService) getSite().getService(IMenuService.class);
    if (menuService != null && leftToolBarManager instanceof ContributionManager) {
      TaskRepository outgoingNewRepository = TasksUiUtil.getOutgoingNewTaskRepository(task);
      TaskRepository taskRepository =
          (outgoingNewRepository != null)
              ? outgoingNewRepository
              : taskEditorInput.getTaskRepository();
      menuService.populateContributionManager(
          leftToolBarManager,
          "toolbar:"
              + ID_LEFT_TOOLBAR_HEADER
              + "." //$NON-NLS-1$ //$NON-NLS-2$
              + taskRepository.getConnectorKind());
    }

    leftToolBarManager.update(true);

    if (hasLeftToolBar()) {
      // XXX work around a bug in Gtk that causes the toolbar size to be incorrect if no
      // tool bar buttons are contributed
      //			if (leftToolBar != null) {
      //				Point size = leftToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
      //				boolean changed = false;
      //				for (Control control : leftToolBar.getChildren()) {
      //					final Point childSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
      //					if (childSize.y > size.y) {
      //						size.y = childSize.y;
      //						changed = true;
      //					}
      //				}
      //				if (changed) {
      //					leftToolBar.setSize(size);
      //				}
      //			}
      //
      //			if (PlatformUtil.isToolBarHeightBroken(leftToolBar)) {
      //				ToolItem item = new ToolItem(leftToolBar, SWT.NONE);
      //				item.setEnabled(false);
      //				item.setImage(CommonImages.getImage(CommonImages.BLANK));
      //				item.setWidth(1);
      //				noExtraPadding = true;
      //			} else if (PlatformUtil.needsToolItemToForceToolBarHeight()) {
      //				ToolItem item = new ToolItem(leftToolBar, SWT.NONE);
      //				item.setEnabled(false);
      //				int scaleHeight = 22;
      //				if (PlatformUtil.needsCarbonToolBarFix()) {
      //					scaleHeight = 32;
      //				}
      //				final Image image = new Image(item.getDisplay(),
      // CommonImages.getImage(CommonImages.BLANK)
      //						.getImageData()
      //						.scaledTo(1, scaleHeight));
      //				item.setImage(image);
      //				item.addDisposeListener(new DisposeListener() {
      //					public void widgetDisposed(DisposeEvent e) {
      //						image.dispose();
      //					}
      //				});
      //				item.setWidth(1);
      //				noExtraPadding = true;
      //			}

      // fix size of toolbar on Gtk with Eclipse 3.3
      Point size = leftToolBar.getSize();
      if (size.x == 0 && size.y == 0) {
        size = leftToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
        leftToolBar.setSize(size);
      }
    }
  }
  @Override
  public void createPartControl(Composite parent) {

    final Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout());
    GridUtils.removeMargins(main);

    final Composite tools = new Composite(main, SWT.RIGHT);
    tools.setLayout(new GridLayout(2, false));
    GridUtils.removeMargins(tools);
    tools.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    this.messageLabel = new CLabel(tools, SWT.NONE);
    final GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    gridData.widthHint = 230;
    messageLabel.setLayoutData(gridData);
    messageLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY));
    messageLabel.setToolTipText(
        "Insert variables to the template xml on the right,\nthis will be replaced and sent to EDNA when the workflow is run.");

    ToolBarManager toolMan = new ToolBarManager(SWT.FLAT | SWT.LEFT);
    final ToolBar toolBar = toolMan.createControl(tools);
    toolBar.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
    EdnaActorActions.createInputActions(toolMan);

    final SashForm sash = new SashForm(main, SWT.HORIZONTAL);
    sash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    this.viewer =
        new TableViewer(
            sash, SWT.FULL_SELECTION | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    createColumns(viewer);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);

    final Composite right = new Composite(sash, SWT.NONE);
    right.setLayout(new FillLayout());
    super.createPartControl(right);

    sash.setWeights(new int[] {20, 80});

    // Attached a painter to highlight the replacements
    final VariableCharacterMatcher matcher =
        new VariableCharacterMatcher(((SourceViewer) getSourceViewer()));
    final VariablePainter painter = new VariablePainter(getSourceViewer(), matcher);
    ((SourceViewer) getSourceViewer()).addPainter(painter);
    viewer.addSelectionChangedListener(matcher);
    viewer.addDoubleClickListener(
        new IDoubleClickListener() {
          @Override
          public void doubleClick(DoubleClickEvent event) {
            doInsert();
          }
        });
    ((SourceViewer) getSourceViewer())
        .addSelectionChangedListener(
            new ISelectionChangedListener() {
              @Override
              public void selectionChanged(SelectionChangedEvent event) {
                final ISelection sel = event.getSelection();
                if (sel instanceof TextSelection) {
                  XMLSubstitutionEditor.this.currentSelectedText = (TextSelection) sel;
                  updateMessageLabel();
                  return;
                }
                XMLSubstitutionEditor.this.currentSelectedText = null;
                updateMessageLabel();
              }
            });

    toolMan.update(true);
    setWritable(true);
    getSite().setSelectionProvider(viewer);
    createUndoRedoActions();
    createRightClickMenu();
  }
  private void createComp(Composite group) {

    GridLayout layout = new GridLayout(1, false);
    layout.verticalSpacing = 10;
    group.setLayout(layout);

    // TableViewer是通过Table来布局的
    // 制作表格   MULTI可多选  H_SCROLL有水平 滚动条、V_SCROLL有垂直滚动条、BORDER有边框、FULL_SELECTION整行选择
    table = new Table(group, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL); // 注意此处的设置
    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);

    // 指定Table单元格的宽度和高度
    table.addListener(
        SWT.MeasureItem,
        new Listener() { // 向表格增加一个SWT.MeasureItem监听器,每当需要单元内容的大小的时候就会被调用。
          public void handleEvent(Event event) {
            event.width = table.getGridLineWidth(); // 设置宽度
            event.height =
                (int) Math.floor(event.gc.getFontMetrics().getHeight() * 1.5); // 设置高度为字体高度的1.5倍
          }
        });

    // 表格的视图
    tableViewer = new TableViewer(table);
    // 标题和网格线可见
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.getTable().setHeaderVisible(true);
    // 设置填充
    // GridData data = new GridData(SWT.LEFT,SWT.CENTER, true, false);//SWT.FILL, SWT.FILL, true,
    // false  xbm
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 350;
    data.heightHint = 295;
    data.grabExcessHorizontalSpace = true;
    tableViewer.getTable().setLayoutData(data); // 表格的布局

    // 创建表格列的标题
    int width = 1;
    for (int i = 0; i < stationData.getColumnCount(); i++) {
      width = stationData.getColumnWidth(i);
      TableColumn column = new TableColumn(table, SWT.NONE);
      column.setWidth((int) (width * 8));
      column.setText(stationData.getColumnHeads()[i]); // 设置表头
      column.setAlignment(SWT.LEFT); // 对齐方式SWT.LEFT
      if (i == 0) // 站名
      {
        // 列的选择事件  实现排序
        column.addSelectionListener(
            new SelectionAdapter() {
              boolean sortType = true; // sortType记录上一次的排序方式,默认为升序

              public void widgetSelected(SelectionEvent e) {
                sortType = !sortType; // 取反。下一次排序方式要和这一次的相反
                tableViewer.setSorter(new StationSorter(sortType, stationData.columnHeads[0]));
              }
            });
      }
    }

    /*tableLayout.addColumnData(new ColumnWeightData(8, 8, false));//设置列宽为8像素
     TableColumn column_one = new TableColumn(table, SWT.NONE);//SWT.LEFT
     column_one.setText(stationData.COLUMN_HEADINGS[0]);//设置表头
     column_one.setAlignment(SWT.LEFT);//对齐方式SWT.LEFT
     column.setWidth(10);//宽度
    */

    // 设置标题的提供者
    tableViewer.setLabelProvider(new TableLabelProvider());

    // 设置表格视图的内容提供者
    tableViewer.setContentProvider(new TableContentProvider());

    // 设置列的属性.
    tableViewer.setColumnProperties(stationData.columnHeads);

    // 定义每一列的别名
    tableViewer.setColumnProperties(new String[] {"name", "down", "up", "map"});

    // 设置每一列的单元格编辑组件CellEditor
    CellEditor[] celleditors = new CellEditor[5];
    // 文本编辑框
    celleditors[0] = null;
    celleditors[1] = new TextCellEditor(table);
    celleditors[2] = new TextCellEditor(table);
    // CheckboxCellEditor(table) 复选框
    celleditors[3] = new ComboBoxCellEditor(table, StationData.MAPS, SWT.READ_ONLY); // 下拉框

    Text text = (Text) celleditors[1].getControl(); // 设置第down列只能输入数值
    text.addVerifyListener(
        new VerifyListener() {
          public void verifyText(VerifyEvent e) {
            // 输入控制键,输入中文,输入字符,输入数字 正整数验证
            Pattern pattern = Pattern.compile("[0-9]\\d*"); // 正则表达式
            Matcher matcher = pattern.matcher(e.text);
            if (matcher.matches()) // 处理数字
            {
              /*if(Integer.parseInt(e.text) != 0)//确保输入的数字不是0
              			e.doit = true;
              		else
              			e.doit = false;
              */
              e.doit = true;
            } else if (e.text.length() > 0) // 字符: 包含中文、空格
            e.doit = false;
            else // 控制键
            e.doit = true;
          }
        });

    Text text1 = (Text) celleditors[2].getControl(); // 设置第up列只能输入数值
    text1.addVerifyListener(
        new VerifyListener() {
          public void verifyText(VerifyEvent e) {
            String inStr = e.text;
            if (inStr.length() > 0) {
              e.doit = NumberUtils.isDigits(inStr);
            }
          }
        });

    table.addMouseMoveListener(
        new MouseMoveListener() {
          public void mouseMove(MouseEvent e) {
            if (StationData.reloadFlag) {
              getStationInfo();
              openCurrentTable(row);
              StationData.reloadFlag = false;
              // System.out.println("entry");
            }
          }
        });
    /*table.addFocusListener(new FocusListener(){
    public void focusGained(FocusEvent e) {
    	getStationInfo();
    	openCurrentTable(row);
    }
    @Override
    public void focusLost(FocusEvent e) {
    }
      });
         */
    tableViewer.setCellEditors(celleditors);

    // 设置单元的更改器
    tableViewer.setCellModifier(new TableCellModifier());

    tableViewer.addFilter(new TableViewerFilter()); // 过滤器

    // 构造工具条
    Composite buttonComposite = new Composite(group, SWT.NONE);
    buttonComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); // 使工具条居中
    Action actionModify =
        new Action("更新") {
          public void run() {
            // 取得用户所选择的第一行, 若没有选择则为null
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            // 获取选中的第一行数据
            Station station = (Station) selection.getFirstElement();
            if (station != null) {
              if (updateStationInfo(
                  station.getStation_downnumber(),
                  station.getStation_upnumber(),
                  station.getStation_graph(),
                  station.getStation_name())) {
                showMsg("成功更新!");
                // 表格的刷新方法,界面会重新读取数据并显示

                pushCommand();

                tableViewer.refresh(); // false
              } else {
                showMsg("更新失败!");
                // tableViewer.refresh();//false
              }
            } else {
              showMsg("请选取进行更新的行!");
            }
          }
        };

    Action actionDelete =
        new Action("删除") {
          public void run() {
            // 取得用户所选择的第一行, 若没有选择则为null
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            // 获取选中的第一个数据
            Station station = (Station) selection.getFirstElement();
            if (station != null) {
              // 先预先移动到下一行
              Table table = tableViewer.getTable();

              // int i = table.getSelectionIndex(); //取得当前所选行的序号,如没有则返回-1
              // table.setSelection(i + 1); //当前选择行移下一行
              // 确认删除
              MessageBox messageBox =
                  new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_INFORMATION);
              messageBox.setText("提示信息");
              messageBox.setMessage("确定要删除此记录吗?");
              // SWT.YES 是  // SWT.NO 否 // SWT.CANCEL 取消 // SWT.RETRY 重试// SWT.ABORT 放弃// SWT.IGNORE
              // 忽略
              if (messageBox.open() == SWT.YES) {
                if (deleteStationInfo(station.getStation_name())) // 从数据库中删除记录
                {
                  // showMsg("成功删除!");
                  ((List) tableViewer.getInput()).remove(station); // 数据模型的List容器中删除
                  stationData.remove(station.getStation_name());
                  openCurrentTable(row);
                  tableViewer.remove(station); // 从表格界面上删除

                  pushCommand();
                } else showMsg("删除失败!");
              }
            } else {
              showMsg("请选取要删除的纪录!");
            }
          }
        };

    Action actionClear = new Action("清空") { // 清除所显示内容,点击保存后更新库
          public void run() {
            if (clearStationInfo()) {
              showMsg("清空操作成功!");
              stationData.removeAll();
              openCurrentTable(row);

              pushCommand();
            } else showMsg("清空操作失败!");
          }
        };
    Action actionHelp =
        new Action("帮助") {
          public void run() {
            String str = "更新:\n\r" + "先对某行内容进行修改,然后点击更新进行保存\n\r" + "清空:\n\r" + "从库中物理删除所有记录";
            showMsg(str);
          }
        };

    Action nextPage =
        new Action("下一页") {
          public void run() {
            row++;
            if (row > stationData.getTotalPageNum()) {
              row--;
              return;
            }
            openCurrentTable(row);
          }
        };
    Action prevPage =
        new Action("上一页") {
          public void run() {
            row--;
            if (row < 1) {
              row++;
              return;
            }
            openCurrentTable(row);
          }
        };

    Action refresh =
        new Action("刷新") {
          public void run() {
            getStationInfo();
            openCurrentTable(row);
          }
        };

    // 工具条
    ToolBar toolBar = new ToolBar(buttonComposite, SWT.FLAT | SWT.RIGHT); // |SWT.BORDER

    // 工具条管理器
    ToolBarManager manager = new ToolBarManager(toolBar);

    // manager.add(refresh);
    // manager.add(new Separator());

    manager.add(nextPage);
    manager.add(prevPage);

    manager.add(new Separator());

    manager.add(actionModify);
    manager.add(actionDelete);
    manager.add(actionClear);
    manager.add(new Separator());
    manager.add(actionHelp);
    manager.update(true);

    // 选中某行时,改变行的颜色
    table.addListener(
        SWT.EraseItem,
        new Listener() {
          public void handleEvent(Event event) {
            event.detail &= ~SWT.HOT;
            if ((event.detail & SWT.SELECTED) == 0) return;
            int clientWidth = table.getClientArea().width;
            GC gc = event.gc;
            Color oldForeground = gc.getForeground();
            Color oldBackground = gc.getBackground();
            gc.setForeground(red);
            // gc.setBackground(yellow);
            gc.fillGradientRectangle(0, event.y, clientWidth, event.height, false);
            gc.setForeground(oldForeground);
            gc.setBackground(oldBackground);
            event.detail &= ~SWT.SELECTED;
          }
        });

    // 在tableviewer内部为数据记录和tableItem之间的映射创建一个hash表,这样可以加快tableItem的和记录间的查找速度
    // 必须保证存在要显示的数据,否则程序出错。所以这里不能用下面的语句
    // tableViewer.setUseHashlookup(true);//必须在setInput之前加入才有效
    // 从服务器获取数据
    getStationInfo();
    // 通过setInput为table添加了一个list后,只要对这个list里的元素进行添加和删除,
    // table中的数据就会自动添加和删除,当然每次操作后需要调用refresh方法对tableviewer进行刷新。
    // 打开界面所显示的内容
    tableViewer.setInput(stationData.getData()); // 自动输入数据   即将数据显示在表格中
    tableViewer.setItemCount(stationData.PAGE_SIZE); // 设置显示的Item数
  } //// createComp
Ejemplo n.º 23
0
  protected void createDefaultActions() {
    toolBarManager.removeAll();
    if ((gridStyle & IGridViewer.NoToolBar) == 0) {
      if ((gridStyle & IGridViewer.fullEditable) != 0) {
        Element element = null;
        try {
          // element =
          // LoadSchemaManager.getSchemaManager().getElement(
          // data);
          element = CompositeMapUtil.getElement(data);
        } catch (Exception e) {
          // do nothing
        }
        if (element != null && element.isArray()) {
          final QualifiedName qName = element.getElementType().getQName();
          Action addAction = new AddElementAction(this, data, qName, ActionListener.NONE);
          addAction.setText("");
          addAction.setHoverImageDescriptor(
              AuroraPlugin.getImageDescriptor(LocaleMessage.getString("add.icon")));

          Action removeAction = new RemoveElementAction(this, ActionListener.DefaultImage);
          Action refreshAction = new RefreshAction(this, ActionListener.DefaultImage);
          toolBarManager.add(createActionContributionItem(addAction));
          toolBarManager.add(createActionContributionItem(refreshAction));
          toolBarManager.add(createActionContributionItem(removeAction));
          toolBarManager.update(true);
          tableViewer
              .getTable()
              .addKeyListener(
                  new KeyListener() {
                    public void keyPressed(KeyEvent e) {
                      if (e.keyCode == SWT.DEL) {
                        removeElement();
                      }
                    }

                    public void keyReleased(KeyEvent e) {}
                  });
        }
      }
    }
    if ((gridStyle & IGridViewer.isMulti) != 0) {

      Action allCheckAction =
          new Action(
              LocaleMessage.getString("all.checed"),
              AuroraPlugin.getImageDescriptor(LocaleMessage.getString("checked.icon"))) {
            public void run() {
              setAllChecked(tableViewer.getTable(), true);
            }
          };
      Action unAllCheckAction =
          new Action(
              LocaleMessage.getString("non.checed"),
              AuroraPlugin.getImageDescriptor(LocaleMessage.getString("unchecked.icon"))) {
            public void run() {
              setAllChecked(tableViewer.getTable(), false);
            }
          };
      toolBarManager.add(createActionContributionItem(allCheckAction));
      toolBarManager.add(createActionContributionItem(unAllCheckAction));
      toolBarManager.update(true);
    }
  }
Ejemplo n.º 24
0
  @Override
  protected IInformationControl doCreateInformationControl(final Shell parent) {
    if (BrowserInformationControl.isAvailable(parent)) {
      final ToolBarManager tbm = new ToolBarManager(SWT.FLAT);

      final String font = JFaceResources.DIALOG_FONT;
      final BrowserInformationControl control = new BrowserInformationControl(parent, font, tbm);

      final PresenterControlCreator.BackAction backAction =
          new PresenterControlCreator.BackAction(control);
      backAction.setEnabled(false);
      tbm.add(backAction);
      final PresenterControlCreator.ForwardAction forwardAction =
          new PresenterControlCreator.ForwardAction(control);
      tbm.add(forwardAction);
      forwardAction.setEnabled(false);

      final PresenterControlCreator.ShowInEdocViewAction showInEdocViewAction =
          new PresenterControlCreator.ShowInEdocViewAction(control);
      tbm.add(showInEdocViewAction);
      final OpenDeclarationAction openDeclarationAction =
          new OpenDeclarationAction(control, editor);
      tbm.add(openDeclarationAction);

      final SimpleSelectionProvider selectionProvider = new SimpleSelectionProvider();
      final OpenEdocInExternalBrowserAction openEdocInExternalBrowserAction =
          new OpenEdocInExternalBrowserAction(editor.getSite(), null);
      openEdocInExternalBrowserAction.setSpecialSelectionProvider(selectionProvider);
      selectionProvider.addSelectionChangedListener(openEdocInExternalBrowserAction);
      final ImageDescriptor descriptor = ErlideImage.OBJS_EXTERNALBROWSER.getDescriptor();
      openEdocInExternalBrowserAction.setImageDescriptor(descriptor);
      openEdocInExternalBrowserAction.setDisabledImageDescriptor(descriptor);
      selectionProvider.setSelection(new StructuredSelection());
      tbm.add(openEdocInExternalBrowserAction);

      // OpenExternalBrowserAction openExternalJavadocAction = new
      // OpenExternalBrowserAction(
      // parent.getDisplay(), selectionProvider);
      // selectionProvider
      // .addSelectionChangedListener(openExternalJavadocAction);
      // selectionProvider.setSelection(new
      // StructuredSelection());
      // tbm.add(openExternalJavadocAction);

      final IInputChangedListener inputChangeListener =
          new IInputChangedListener() {
            @Override
            public void inputChanged(final Object newInput) {
              backAction.update();
              forwardAction.update();
              if (newInput == null) {
                selectionProvider.setSelection(new StructuredSelection());
              } else if (newInput instanceof BrowserInformationControlInput) {
                final BrowserInformationControlInput input =
                    (BrowserInformationControlInput) newInput;
                final Object inputElement = input.getInputElement();
                selectionProvider.setSelection(new StructuredSelection(inputElement));
                final boolean hasInputElement = inputElement != null;
                showInEdocViewAction.setEnabled(hasInputElement);
                openDeclarationAction.setEnabled(hasInputElement);
                openEdocInExternalBrowserAction.setInput(newInput);
                openEdocInExternalBrowserAction.setEnabled(hasInputElement);
              }
            }
          };
      control.addInputChangeListener(inputChangeListener);

      tbm.update(true);

      control.addLocationListener(new HandleEdocLinksLocationListener(control));

      return control;
    }
    return new DefaultInformationControl(
        parent, EditorsUI.getTooltipAffordanceString(), new ErlInformationPresenter(true));
  }