Exemplo n.º 1
0
  /**
   * Create a new instance of the receiver on a status.
   *
   * @param status The status to display.
   */
  SafeRunnableDialog(IStatus status) {

    super(
        null,
        JFaceResources.getString("error"),
        status.getMessage(), // $NON-NLS-1$
        status,
        IStatus.ERROR);

    setShellStyle(
        SWT.DIALOG_TRIM | SWT.MODELESS | SWT.RESIZE | SWT.MIN | SWT.MAX | getDefaultOrientation());

    setStatus(status);
    statuses.add(status);

    setBlockOnOpen(false);

    String reason =
        JFaceResources.getString("SafeRunnableDialog_checkDetailsMessage"); // $NON-NLS-1$
    if (status.getException() != null) {
      reason =
          status.getException().getMessage() == null
              ? status.getException().toString()
              : status.getException().getMessage();
    }
    this.message =
        JFaceResources.format(
            "SafeRunnableDialog_reason",
            new Object[] { // $NON-NLS-1$
              status.getMessage(), reason
            });
  }
 /** Shows the "Page Flipping abort" dialog. */
 void showPageFlippingAbortDialog() {
   MessageDialog.open(
       MessageDialog.ERROR,
       getShell(),
       JFaceResources.getString("AbortPageFlippingDialog.title"), // $NON-NLS-1$
       JFaceResources.getString("AbortPageFlippingDialog.message"),
       SWT.SHEET); //$NON-NLS-1$
 }
Exemplo n.º 3
0
 /**
  * Create the status list if required.
  *
  * @param parent the Control to create it in.
  */
 private void createStatusList(Composite parent) {
   if (isMultipleStatusDialog()) {
     if (statusListViewer == null) {
       // The job list doesn't exist so create it.
       setMessage(
           JFaceResources.getString("SafeRunnableDialog_MultipleErrorsMessage")); // $NON-NLS-1$
       getShell()
           .setText(
               JFaceResources.getString("SafeRunnableDialog_MultipleErrorsTitle")); // $NON-NLS-1$
       createStatusListArea(parent);
       showDetailsArea();
     }
     refreshStatusList();
   }
 }
 /**
  * Save the values specified in the pages.
  *
  * <p>The default implementation of this framework method saves all pages of type <code>
  * PreferencePage</code> (if their store needs saving and is a <code>PreferenceStore</code>).
  *
  * <p>Subclasses may override.
  */
 protected void handleSave() {
   Iterator<IPreferenceNode> nodes =
       preferenceManager.getElements(PreferenceManager.PRE_ORDER).iterator();
   while (nodes.hasNext()) {
     IPreferenceNode node = nodes.next();
     IPreferencePage page = node.getPage();
     if (page instanceof PreferencePage) {
       // Save now in case tbe workbench does not shutdown cleanly
       IPreferenceStore store = ((PreferencePage) page).getPreferenceStore();
       if (store != null && store.needsSaving() && store instanceof IPersistentPreferenceStore) {
         try {
           ((IPersistentPreferenceStore) store).save();
         } catch (IOException e) {
           String message =
               JFaceResources.format(
                   "PreferenceDialog.saveErrorMessage",
                   page.getTitle(), // $NON-NLS-1$
                   e.getMessage());
           Policy.getStatusHandler()
               .show(
                   new Status(IStatus.ERROR, Policy.JFACE, message, e),
                   JFaceResources.getString("PreferenceDialog.saveErrorTitle")); // $NON-NLS-1$
         }
       }
     }
   }
 }
 /** 添加帮助按钮,备注,这里的配置与其他的不一样 robert 2012-09-06 */
 protected Control createHelpToolItem(Composite parent) {
   // ROBERTHELP xml 转换器配置
   String language = CommonFunction.getSystemLanguage();
   final String helpUrl =
       MessageFormat.format(
           "/net.heartsome.cat.ts.ui.help/html/{0}/ch08.html#configure-xml-converter", language);
   Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
   ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
   toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
   final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
   toolBar.setCursor(cursor);
   toolBar.addDisposeListener(
       new DisposeListener() {
         public void widgetDisposed(DisposeEvent e) {
           cursor.dispose();
         }
       });
   ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
   helpItem.setImage(helpImage);
   helpItem.setToolTipText(JFaceResources.getString("helpToolTip")); // $NON-NLS-1$
   helpItem.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
         }
       });
   return toolBar;
 }
  private ToolBar createHelpImageButton(Composite parent, Image image) {
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(
        new DisposeListener() {

          @Override
          public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
          }
        });
    ToolItem item = new ToolItem(toolBar, SWT.NONE);
    item.setImage(image);
    item.setToolTipText(JFaceResources.getString("helpToolTip")); // $NON-NLS-1$
    item.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            helpPressed();
          }
        });
    return toolBar;
  }
Exemplo n.º 7
0
 /**
  * Constructor of PasswordEditor.
  *
  * @param name String
  * @param labelText String
  * @param width int
  * @param strategy int
  * @param parent Composite
  */
 public PasswordEditor(String name, String labelText, int width, int strategy, Composite parent) {
   init(name, labelText);
   widthInChars = width;
   setValidateStrategy(strategy);
   isValid = false;
   errorMessage = JFaceResources.getString("StringFieldEditor.errorMessage"); // $NON-NLS-1$
   createControl(parent);
 }
  private String getAccessibleMessageFor(Image image) {
    if (image.equals(getErrorImage())) {
      return JFaceResources.getString("error"); // $NON-NLS-1$
    }

    if (image.equals(getWarningImage())) {
      return JFaceResources.getString("warning"); // $NON-NLS-1$
    }

    if (image.equals(getInfoImage())) {
      return JFaceResources.getString("info"); // $NON-NLS-1$
    }

    if (image.equals(getQuestionImage())) {
      return JFaceResources.getString("question"); // $NON-NLS-1$
    }

    return null;
  }
 public PVsInfoDialog(Shell parentShell, String dialogTitle, Map<String, IPV> pvMap) {
   super(
       parentShell,
       dialogTitle,
       null,
       "PVs' details on this widget:",
       MessageDialog.INFORMATION,
       new String[] {JFaceResources.getString("ok")},
       0); //$NON-NLS-1$
   this.pvMap = pvMap;
 }
Exemplo n.º 10
0
 /**
  * Helper method to create a push button.
  *
  * @param parent the parent control
  * @param key the resource name used to supply the button's label text
  * @return Button
  */
 private Button createPushButton(Composite parent, String key) {
   Button button = new Button(parent, SWT.PUSH);
   button.setText(JFaceResources.getString(key));
   button.setFont(parent.getFont());
   GridData data = new GridData(GridData.FILL_HORIZONTAL);
   int widthHint = convertHorizontalDLUsToPixels(button, IDialogConstants.BUTTON_WIDTH);
   data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
   button.setLayoutData(data);
   button.addSelectionListener(getSelectionListener());
   return button;
 }
 private Button createButton(Composite parent, String key) {
   Button b = new Button(parent, SWT.PUSH);
   b.setText(JFaceResources.getString(key));
   b.setFont(parent.getFont());
   GridData d = new GridData(GridData.FILL_HORIZONTAL);
   d.heightHint = convertVerticalDLUsToPixels(b, 14 /*IDialogConstants.BUTTON_HEIGHT*/);
   int widthHint = convertHorizontalDLUsToPixels(b, IDialogConstants.BUTTON_WIDTH);
   d.widthHint = Math.max(widthHint, b.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
   b.setLayoutData(d);
   b.addSelectionListener(getSelectionListener());
   return b;
 }
 @Override
 protected void configureShell(Shell newShell) {
   super.configureShell(newShell);
   newShell.setText(JFaceResources.getString("PreferenceDialog.title")); // $NON-NLS-1$
   newShell.addShellListener(
       new ShellAdapter() {
         @Override
         public void shellActivated(ShellEvent e) {
           if (lastShellSize == null) {
             lastShellSize = getShell().getSize();
           }
         }
       });
 }
Exemplo n.º 13
0
 public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
   // Do we need to fire an event.
   if ((oldValue == null || !oldValue.equals(newValue))) {
     final PropertyChangeEvent pe = new PropertyChangeEvent(this, name, oldValue, newValue);
     for (final IPropertyChangeListener l : listeners) {
       SafeRunnable.run(
           new SafeRunnable(
               JFaceResources.getString("PreferenceStore.changeError")) { // $NON-NLS-1$
             public void run() {
               l.propertyChange(pe);
             }
           });
     }
   }
 }
Exemplo n.º 14
0
 @Override
 public boolean performOk() {
   boolean isOk = super.performOk();
   if (isOk && corePreferences.needsSaving()) {
     try {
       corePreferences.save();
     } catch (IOException e) {
       String message =
           JFaceResources.format(
               "PreferenceDialog.saveErrorMessage",
               getTitle(), //$NON-NLS-1$
               e.getMessage());
       Policy.getStatusHandler()
           .show(
               new Status(IStatus.ERROR, Policy.JFACE, message, e),
               JFaceResources.getString("PreferenceDialog.saveErrorTitle")); // $NON-NLS-1$
     }
   }
   return isOk;
 }
  private void createCopyAction(final Composite parent) {
    Menu menu = new Menu(parent.getShell(), SWT.POP_UP);
    MenuItem copyAction = new MenuItem(menu, SWT.PUSH);
    copyAction.setText(JFaceResources.getString("copy")); // $NON-NLS-1$
    copyAction.addSelectionListener(
        new SelectionAdapter() {

          /*
           * (non-Javadoc)
           *
           * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
           */
          public void widgetSelected(SelectionEvent e) {
            clipboard = new Clipboard(parent.getDisplay());
            clipboard.setContents(
                new Object[] {prepareCopyString()}, new Transfer[] {TextTransfer.getInstance()});
            super.widgetSelected(e);
          }
        });
    list.setMenu(menu);
  }
Exemplo n.º 16
0
  /**
   * Creates the progress monitor's UI parts and layouts them according to the given layout. If the
   * layout is <code>null</code> the part's default layout is used.
   *
   * @param layout The layout for the receiver.
   * @param progressIndicatorHeight The suggested height of the indicator
   */
  protected void initialize(Layout layout, int progressIndicatorHeight) {
    if (layout == null) {
      GridLayout l = new GridLayout();
      l.marginWidth = 0;
      l.marginHeight = 0;
      layout = l;
    }
    int numColumns = 1;
    if (fHasStopButton) numColumns++;
    setLayout(layout);

    if (layout instanceof GridLayout) ((GridLayout) layout).numColumns = numColumns;

    fLabel = new Label(this, SWT.LEFT);
    fLabel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, numColumns, 1));

    if (progressIndicatorHeight == SWT.DEFAULT) {
      GC gc = new GC(fLabel);
      FontMetrics fm = gc.getFontMetrics();
      gc.dispose();
      progressIndicatorHeight = fm.getHeight();
    }

    fProgressIndicator = new ProgressIndicator(this);
    GridData gd = new GridData();
    gd.horizontalAlignment = GridData.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = false;
    gd.verticalAlignment = GridData.CENTER;
    gd.heightHint = progressIndicatorHeight;
    fProgressIndicator.setLayoutData(gd);

    if (fHasStopButton) {
      fToolBar = new ToolBar(this, SWT.FLAT);

      gd = new GridData();
      gd.grabExcessHorizontalSpace = false;
      gd.grabExcessVerticalSpace = false;
      gd.verticalAlignment = GridData.CENTER;
      fToolBar.setLayoutData(gd);
      fStopButton = new ToolItem(fToolBar, SWT.PUSH);
      // It would have been nice to use the fCancelListener, but that
      // listener operates on the fCancelComponent which must be a control.
      fStopButton.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
              setCanceled(true);
              if (fStopButton != null) {
                fStopButton.setEnabled(false);
              }
            }
          });
      final Image stopImage =
          ImageDescriptor.createFromFile(ProgressMonitorPart.class, "images/stop.gif")
              .createImage(getDisplay()); // $NON-NLS-1$
      final Cursor arrowCursor = new Cursor(this.getDisplay(), SWT.CURSOR_ARROW);
      fToolBar.setCursor(arrowCursor);
      fStopButton.setImage(stopImage);
      fStopButton.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
              // RAP [rh] images don't support dispose
              //        			stopImage.dispose();
              arrowCursor.dispose();
            }
          });
      fStopButton.setToolTipText(
          JFaceResources.getString("ProgressMonitorPart.cancelToolTip")); // $NON-NLS-1$
    }
  }
Exemplo n.º 17
0
 /**
  * Creates a font field editor with an optional preview area.
  *
  * @param name the name of the preference this field editor works on
  * @param labelText the label text of the field editor
  * @param previewAreaText the text used for the preview window. If it is <code>null</code> there
  *     will be no preview area,
  * @param parent the parent of the field editor's control
  */
 public FontFieldEditor(String name, String labelText, String previewAreaText, Composite parent) {
   init(name, labelText);
   previewText = previewAreaText;
   changeButtonText = JFaceResources.getString("openChange"); // $NON-NLS-1$
   createControl(parent);
 }
  /**
   * Informs the user about the fact that there are no enabled categories in the default content
   * assist set and shows a link to the preferences.
   *
   * @return <code>true</code> if the default should be restored
   * @since 3.3
   */
  private boolean informUserAboutEmptyDefaultCategory() {
    if (OptionalMessageDialog.isDialogEnabled(PREF_WARN_ABOUT_EMPTY_ASSIST_CATEGORY)) {
      final Shell shell = JavaPlugin.getActiveWorkbenchShell();
      String title = JavaTextMessages.ContentAssistProcessor_all_disabled_title;
      String message = JavaTextMessages.ContentAssistProcessor_all_disabled_message;
      // see PreferencePage#createControl for the 'defaults' label
      final String restoreButtonLabel = JFaceResources.getString("defaults"); // $NON-NLS-1$
      final String linkMessage =
          Messages.format(
              JavaTextMessages.ContentAssistProcessor_all_disabled_preference_link,
              LegacyActionTools.removeMnemonics(restoreButtonLabel));
      final int restoreId = IDialogConstants.CLIENT_ID + 10;
      final int settingsId = IDialogConstants.CLIENT_ID + 11;
      final OptionalMessageDialog dialog =
          new OptionalMessageDialog(
              PREF_WARN_ABOUT_EMPTY_ASSIST_CATEGORY,
              shell,
              title,
              null /* default image */,
              message,
              MessageDialog.WARNING,
              new String[] {restoreButtonLabel, IDialogConstants.CLOSE_LABEL},
              1) {
            /*
             * @see org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
             */
            @Override
            protected Control createCustomArea(Composite composite) {
              // wrap link and checkbox in one composite without space
              Composite parent = new Composite(composite, SWT.NONE);
              GridLayout layout = new GridLayout();
              layout.marginHeight = 0;
              layout.marginWidth = 0;
              layout.verticalSpacing = 0;
              parent.setLayout(layout);

              Composite linkComposite = new Composite(parent, SWT.NONE);
              layout = new GridLayout();
              layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
              layout.marginWidth =
                  convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
              layout.horizontalSpacing =
                  convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
              linkComposite.setLayout(layout);

              Link link = new Link(linkComposite, SWT.NONE);
              link.setText(linkMessage);
              link.addSelectionListener(
                  new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                      setReturnCode(settingsId);
                      close();
                    }
                  });
              GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
              gridData.widthHint = this.getMinimumMessageWidth();
              link.setLayoutData(gridData);

              // create checkbox and "don't show this message" prompt
              super.createCustomArea(parent);

              return parent;
            }

            /*
             * @see org.eclipse.jface.dialogs.MessageDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
             */
            @Override
            protected void createButtonsForButtonBar(Composite parent) {
              Button[] buttons = new Button[2];
              buttons[0] = createButton(parent, restoreId, restoreButtonLabel, false);
              buttons[1] =
                  createButton(
                      parent, IDialogConstants.CLOSE_ID, IDialogConstants.CLOSE_LABEL, true);
              setButtons(buttons);
            }
          };
      int returnValue = dialog.open();
      if (restoreId == returnValue || settingsId == returnValue) {
        if (restoreId == returnValue) {
          IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore();
          store.setToDefault(PreferenceConstants.CODEASSIST_CATEGORY_ORDER);
          store.setToDefault(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES);
        }
        if (settingsId == returnValue)
          PreferencesUtil.createPreferenceDialogOn(
                  shell, "org.eclipse.jdt.ui.preferences.CodeAssistPreferenceAdvanced", null, null)
              .open(); //$NON-NLS-1$
        fComputerRegistry.reload();
        return true;
      }
    }
    return false;
  }