Esempio n. 1
0
  /*
   * Creates a button with a help image. This is only used if there
   * is an image available.
   */
  private ToolBar createLocalizationImageButton(Composite parent, Image image) {
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
          }
        });

    final ToolItem item = new ToolItem(toolBar, SWT.NONE);
    item.setImage(image);

    languageSet.associate(
        "localizationToolTip", //$NON-NLS-1$
        new TranslatableTextInput(
            Activator.getLocalizableText(
                "LocalizableTrayDialog.localizationToolTip")) { //$NON-NLS-1$
          @Override
          public void updateControl(String text) {
            item.setToolTipText(text);
          }
        });

    item.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            localizationPressed();
          }
        });
    return toolBar;
  }
Esempio n. 2
0
 /*
  * Called when the user selects the action to localize this dialog.
  * This will bring up a dialog that can be used to localize this dialog.
  */
 protected void localizationPressed() {
   Dialog dialog =
       new LocalizeDialog(
           getShell(),
           TranslatableNLS.bind(Messages.LocalizeDialog_Title_DialogPart, getShell().getText()),
           languageSet,
           Activator.getDefault().getMenuTextSet());
   dialog.open();
 }
Esempio n. 3
0
public class LocalizableTrayDialog extends TrayDialog {

  private static ImageDescriptor localizationImageDescriptor =
      Activator.createImageDescriptor("icons/babel.gif"); // $NON-NLS-1$
  protected TranslatableSet languageSet = new TranslatableSet();

  /**
   * Creates a tray dialog instance. Note that the window will have no visual representation (no
   * widgets) until it is told to open.
   *
   * @param shell the parent shell, or <code>null</code> to create a top-level shell
   */
  protected LocalizableTrayDialog(Shell shell) {
    super(shell);
  }

  /**
   * Creates a tray dialog with the given parent.
   *
   * @param parentShell the object that returns the current parent shell
   */
  protected LocalizableTrayDialog(IShellProvider parentShell) {
    super(parentShell);
  }

  /* (non-Javadoc)
   * @see org.eclipse.jface.dialogs.Dialog#createButtonBar(org.eclipse.swt.widgets.Composite)
   */
  @Override
  protected Control createButtonBar(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.horizontalSpacing = 0;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    composite.setFont(parent.getFont());

    // create the localization button
    Control localizationControl = createLocalizationControl(composite);
    ((GridData) localizationControl.getLayoutData()).horizontalIndent =
        convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);

    Control buttonSection = super.createButtonBar(composite);
    ((GridData) buttonSection.getLayoutData()).grabExcessHorizontalSpace = true;
    return composite;
  }

  /**
   * Creates a new help control that provides access to context help.
   *
   * <p>The <code>TrayDialog</code> implementation of this method creates the control, registers it
   * for selection events including selection, Note that the parent's layout is assumed to be a
   * <code>GridLayout</code> and the number of columns in this layout is incremented. Subclasses may
   * override.
   *
   * @param parent the parent composite
   * @return the help control
   */
  protected Control createLocalizationControl(Composite parent) {
    Image image = localizationImageDescriptor.createImage();
    if (image != null) {
      return createLocalizationImageButton(parent, image);
    }
    return createLocalizationLink(parent);
  }

  /*
   * Creates a button with a help image. This is only used if there
   * is an image available.
   */
  private ToolBar createLocalizationImageButton(Composite parent, Image image) {
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
          }
        });

    final ToolItem item = new ToolItem(toolBar, SWT.NONE);
    item.setImage(image);

    languageSet.associate(
        "localizationToolTip", //$NON-NLS-1$
        new TranslatableTextInput(
            Activator.getLocalizableText(
                "LocalizableTrayDialog.localizationToolTip")) { //$NON-NLS-1$
          @Override
          public void updateControl(String text) {
            item.setToolTipText(text);
          }
        });

    item.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            localizationPressed();
          }
        });
    return toolBar;
  }

  /*
   * Creates a help link. This is used when there is no help image
   * available.
   */
  private Link createLocalizationLink(Composite parent) {
    Link link = new Link(parent, SWT.WRAP | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    link.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false));
    link.setText("<a>" + IDialogConstants.HELP_LABEL + "</a>"); // $NON-NLS-1$ //$NON-NLS-2$
    link.setToolTipText(IDialogConstants.HELP_LABEL);
    link.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            localizationPressed();
          }
        });
    return link;
  }

  /*
   * Called when the user selects the action to localize this dialog.
   * This will bring up a dialog that can be used to localize this dialog.
   */
  protected void localizationPressed() {
    Dialog dialog =
        new LocalizeDialog(
            getShell(),
            TranslatableNLS.bind(Messages.LocalizeDialog_Title_DialogPart, getShell().getText()),
            languageSet,
            Activator.getDefault().getMenuTextSet());
    dialog.open();
  }
}