예제 #1
0
 private void add(Action action, String imageName) {
   action.setId(action.getText());
   action.setImageDescriptor(
       PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(imageName));
   IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager();
   mgr.add(action);
 }
예제 #2
0
  @Override
  public void init(IViewSite site, IMemento memento) throws PartInitException {
    init(site);
    String storedExtensions = "";
    if (memento != null) { // Open dir path
      this.dirPath = memento.getString("DIR");
      storedExtensions = memento.getString("FILTERS");
      if (storedExtensions == null) storedExtensions = "";
    }
    // Filter Extensions
    imgExtensions = new Action[ImageExplorerDirectoryChooseAction.LISTOFSUFFIX.length];
    MenuManager filterMenu = new MenuManager("File Filters");
    for (int i = 0; i < ImageExplorerDirectoryChooseAction.LISTOFSUFFIX.length; i++) {
      final int number = i;
      imgExtensions[i] =
          new Action("", IAction.AS_CHECK_BOX) {
            @Override
            public void run() {
              if (this.isChecked()) {
                filter.remove(ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[number]);
              } else {
                filter.add(ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[number]);
              }
              // reload the directory
              updateDirectory.setUser(true);
              updateDirectory.setPriority(Job.DECORATE);
              updateDirectory.schedule(1000);
            }
          };
      imgExtensions[i].setText(ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[i]);
      imgExtensions[i].setDescription(
          "Filter " + ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[i] + " on/off");
      if (storedExtensions.contains(ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[i])) {
        imgExtensions[i].setChecked(false);
        filter.add(ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[i]);
      } else imgExtensions[i].setChecked(true);
      filterMenu.add(imgExtensions[i]);
    }

    site.getActionBars().getMenuManager().add(filterMenu);

    // color submenus actions
    final IPaletteService pservice = PlatformUI.getWorkbench().getService(IPaletteService.class);
    final Collection<String> names = pservice.getColorSchemes();
    String schemeName = getPreferenceColourMapChoice();

    colorMenu = new MenuAction("Color");
    colorMenu.setId(getClass().getName() + colorMenu.getText());
    colorMenu.setImageDescriptor(AnalysisRCPActivator.getImageDescriptor("icons/color_wheel.png"));

    final Map<String, IAction> paletteActions = new HashMap<String, IAction>(11);
    CheckableActionGroup group = new CheckableActionGroup();
    for (final String paletteName : names) {
      final Action action =
          new Action(paletteName, IAction.AS_CHECK_BOX) {
            @Override
            public void run() {
              try {
                setPreferenceColourMapChoice(paletteName);

                IPlottingSystem<Composite> system =
                    PlottingFactory.getPlottingSystem(getPreferencePlaybackView());
                if (system != null) {
                  final Collection<ITrace> traces = system.getTraces();
                  if (traces != null)
                    for (ITrace trace : traces) {
                      if (trace instanceof IPaletteTrace) {
                        IPaletteTrace paletteTrace = (IPaletteTrace) trace;
                        paletteTrace.setPalette(paletteName);
                      }
                    }
                }

              } catch (Exception ne) {
                logger.error("Cannot create palette data!", ne);
              }
            }
          };
      action.setId(paletteName);
      group.add(action);
      colorMenu.add(action);
      action.setChecked(paletteName.equals(schemeName));
      paletteActions.put(paletteName, action);
    }
    colorMenu.setToolTipText("Histogram");
    site.getActionBars().getMenuManager().add(colorMenu);

    // ImageExplorer preferences
    final Action openPreferences =
        new Action("Image Explorer Preferences...") {
          @Override
          public void run() {
            PreferenceDialog pref =
                PreferencesUtil.createPreferenceDialogOn(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    ImageExplorerPreferencePage.ID,
                    null,
                    null);
            if (pref != null) pref.open();
          }
        };
    site.getActionBars().getMenuManager().add(openPreferences);
  }
예제 #3
0
  protected void createActions() {
    ISharedImages sharedImages =
        getViewSite().getWorkbenchWindow().getWorkbench().getSharedImages();

    zoomInAction =
        new Action(Messages.ChartViewPart_ZoomInAction) {

          @Override
          public void run() {
            int factor = viewer.getZoomFactor();
            viewer.setZoomFactor(factor + 1);
            zoomOutAction.setEnabled(true);
            zoomResetAction.setEnabled(true);
          }
        };
    zoomInAction.setId("zoomIn"); // $NON-NLS-1$
    zoomInAction.setActionDefinitionId("org.eclipsetrader.ui.charts.zoomIn"); // $NON-NLS-1$

    zoomOutAction =
        new Action(Messages.ChartViewPart_ZoomOutAction) {

          @Override
          public void run() {
            int factor = viewer.getZoomFactor();
            if (factor > 0) {
              viewer.setZoomFactor(factor - 1);
            }
            zoomOutAction.setEnabled(factor != 1);
            zoomResetAction.setEnabled(factor != 1);
          }
        };
    zoomOutAction.setId("zoomOut"); // $NON-NLS-1$
    zoomOutAction.setActionDefinitionId("org.eclipsetrader.ui.charts.zoomOut"); // $NON-NLS-1$

    zoomResetAction =
        new Action(Messages.ChartViewPart_NormalSizeAction) {

          @Override
          public void run() {
            viewer.setZoomFactor(0);
            zoomOutAction.setEnabled(false);
            zoomResetAction.setEnabled(false);
          }
        };
    zoomResetAction.setId("zoomReset"); // $NON-NLS-1$
    zoomResetAction.setActionDefinitionId("org.eclipsetrader.ui.charts.zoomReset"); // $NON-NLS-1$

    zoomOutAction.setEnabled(false);
    zoomResetAction.setEnabled(false);

    periodAllAction =
        new Action(Messages.ChartViewPart_AllPeriodAction, IAction.AS_RADIO_BUTTON) {

          @Override
          public void run() {
            setPeriod(null, TimeSpan.days(1));
          }
        };

    cutAction =
        new Action(Messages.ChartViewPart_CutAction) {

          @Override
          public void run() {}
        };
    cutAction.setId("cut"); // $NON-NLS-1$
    cutAction.setActionDefinitionId("org.eclipse.ui.edit.cut"); // $NON-NLS-1$
    cutAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
    cutAction.setDisabledImageDescriptor(
        sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED));
    cutAction.setEnabled(false);

    copyAction =
        new Action(Messages.ChartViewPart_CopyAction) {

          @Override
          public void run() {}
        };
    copyAction.setId("copy"); // $NON-NLS-1$
    copyAction.setActionDefinitionId("org.eclipse.ui.edit.copy"); // $NON-NLS-1$
    copyAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
    copyAction.setDisabledImageDescriptor(
        sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
    copyAction.setEnabled(false);

    pasteAction =
        new Action(Messages.ChartViewPart_PasteAction) {

          @Override
          public void run() {}
        };
    pasteAction.setId("copy"); // $NON-NLS-1$
    pasteAction.setActionDefinitionId("org.eclipse.ui.edit.paste"); // $NON-NLS-1$
    pasteAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
    pasteAction.setDisabledImageDescriptor(
        sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
    pasteAction.setEnabled(false);

    deleteAction =
        new Action(Messages.ChartViewPart_DeleteAction) {

          @Override
          public void run() {
            IStructuredSelection selection =
                (IStructuredSelection) getViewSite().getSelectionProvider().getSelection();
            if (!selection.isEmpty()) {
              if (MessageDialog.openConfirm(
                  getViewSite().getShell(),
                  getPartName(),
                  Messages.ChartViewPart_DeleteConfirmMessage)) {
                ChartViewItem viewItem = (ChartViewItem) selection.getFirstElement();
                ChartRowViewItem rowViewItem = (ChartRowViewItem) viewItem.getParent();
                if (rowViewItem.getItemCount() == 1) {
                  rowViewItem.getParentView().removeRow(rowViewItem);
                } else {
                  rowViewItem.removeChildItem(viewItem);
                }
              }
            }
          }
        };
    deleteAction.setId("delete"); // $NON-NLS-1$
    deleteAction.setActionDefinitionId("org.eclipse.ui.edit.delete"); // $NON-NLS-1$
    deleteAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
    deleteAction.setDisabledImageDescriptor(
        sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
    deleteAction.setEnabled(false);

    updateAction =
        new Action(Messages.ChartViewPart_UpdateAction) {

          @Override
          public void run() {
            doUpdate();
          }
        };
    updateAction.setId("update"); // $NON-NLS-1$
    updateAction.setImageDescriptor(
        UIActivator.getImageDescriptor("icons/etool16/refresh.gif")); // $NON-NLS-1$
    updateAction.setEnabled(true);

    propertiesAction =
        new PropertyDialogAction(
            new SameShellProvider(getViewSite().getShell()), getSite().getSelectionProvider()) {

          @Override
          public void run() {
            PreferenceDialog dialog = createDialog();
            if (dialog != null) {
              if (dialog.open() == Window.OK) {
                IStructuredSelection selection =
                    (IStructuredSelection) getSite().getSelectionProvider().getSelection();

                ChartViewItem viewItem = (ChartViewItem) selection.getFirstElement();
                ((ChartRowViewItem) viewItem.getParent()).refresh();

                refreshChart();
                setDirty();
              }
            }
          }
        };
    propertiesAction.setId(ActionFactory.PROPERTIES.getId());
    propertiesAction.setActionDefinitionId("org.eclipse.ui.file.properties"); // $NON-NLS-1$
    propertiesAction.setEnabled(false);

    currentPriceLineAction =
        new Action(Messages.ChartViewPart_ShowCurrentPriceAction, IAction.AS_CHECK_BOX) {

          @Override
          public void run() {
            currentPriceLineFactory.setEnable(isChecked());
            dialogSettings.put(K_SHOW_CURRENT_PRICE, isChecked());
          }
        };

    currentBookAction =
        new Action(Messages.ChartViewPart_ShowBookAction, IAction.AS_CHECK_BOX) {

          @Override
          public void run() {
            currentBookFactory.setEnable(isChecked());
            dialogSettings.put(K_SHOW_CURRENT_BOOK, isChecked());
          }
        };
  }