Example usage for org.eclipse.jface.resource JFaceResources getDialogFont

List of usage examples for org.eclipse.jface.resource JFaceResources getDialogFont

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources getDialogFont.

Prototype

public static Font getDialogFont() 

Source Link

Document

Returns the JFace's dialog font.

Usage

From source file:org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog.java

License:Open Source License

 @Override
protected void createButtonsForButtonBar(Composite parent) {
   newButton = new Button(parent, SWT.PUSH);
   newButton.setFont(JFaceResources.getDialogFont());
   newButton.setText(UIText.BranchSelectionDialog_NewBranch);
   setButtonLayoutData(newButton);//from  ww w  .ja v  a  2s.  c om
   ((GridLayout) parent.getLayout()).numColumns++;

   renameButton = new Button(parent, SWT.PUSH);
   renameButton.setFont(JFaceResources.getDialogFont());
   renameButton.setText(UIText.BranchSelectionDialog_Rename);
   setButtonLayoutData(renameButton);
   ((GridLayout) parent.getLayout()).numColumns++;

   renameButton.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {

         String refName = refNameFromDialog();
         String refPrefix;

         if (refName.startsWith(Constants.R_HEADS))
            refPrefix = Constants.R_HEADS;
         else if (refName.startsWith(Constants.R_REMOTES))
            refPrefix = Constants.R_REMOTES;
         else if (refName.startsWith(Constants.R_TAGS))
            refPrefix = Constants.R_TAGS;
         else {
            // the button should be disabled anyway, but we check again
            return;
         }

         String branchName = refName.substring(refPrefix.length());

         InputDialog labelDialog = getRefNameInputDialog(
               NLS
                     .bind(
                           UIText.BranchSelectionDialog_QuestionNewBranchNameMessage,
                           branchName, refPrefix), refPrefix,
               branchName);
         if (labelDialog.open() == Window.OK) {
            String newRefName = refPrefix + labelDialog.getValue();
            try {
               new Git(repo).branchRename().setOldName(refName)
                     .setNewName(labelDialog.getValue()).call();
               branchTree.refresh();
               markRef(newRefName);
            } catch (Throwable e1) {
               reportError(
                     e1,
                     UIText.BranchSelectionDialog_ErrorCouldNotRenameRef,
                     refName, newRefName, e1.getMessage());
            }
         }
      }
   });
   newButton.addSelectionListener(new SelectionAdapter() {

      public void widgetSelected(SelectionEvent e) {
         // check what Ref the user selected if any
         Ref ref = refFromDialog();

         InputDialog labelDialog = getRefNameInputDialog(NLS.bind(
               UIText.BranchSelectionDialog_QuestionNewBranchMessage,
               ref.getName(), Constants.R_HEADS), Constants.R_HEADS,
               null);

         if (labelDialog.open() == Window.OK) {
            String newRefName = labelDialog.getValue();
            CreateLocalBranchOperation cbop = new CreateLocalBranchOperation(
                  repo, newRefName, ref);
            try {
               cbop.execute(null);
               branchTree.refresh();
               markRef(Constants.R_HEADS + newRefName);
            } catch (Throwable e1) {
               reportError(
                     e1,
                     UIText.BranchSelectionDialog_ErrorCouldNotCreateNewRef,
                     newRefName);
            }
         }
      }
   });

   super.createButtonsForButtonBar(parent);
   getButton(Window.OK).setText(UIText.BranchSelectionDialog_OkCheckout);
   // createButton(parent, IDialogConstants.OK_ID,
   // UIText.BranchSelectionDialog_OkCheckout, true);
   // createButton(parent, IDialogConstants.CANCEL_ID,
   // IDialogConstants.CANCEL_LABEL, false);

   // can't advance without a selection
   getButton(Window.OK).setEnabled(!branchTree.getSelection().isEmpty());
}

From source file:org.eclipse.egit.ui.internal.dialogs.CheckoutDialog.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(Composite parent) {
    newButton = new Button(parent, SWT.PUSH);
    newButton.setFont(JFaceResources.getDialogFont());
    newButton.setText(UIText.CheckoutDialog_NewBranch);
    setButtonLayoutData(newButton);// w w w .j a v  a 2  s. co m
    ((GridLayout) parent.getLayout()).numColumns++;

    renameButton = new Button(parent, SWT.PUSH);
    renameButton.setFont(JFaceResources.getDialogFont());
    renameButton.setText(UIText.CheckoutDialog_Rename);
    setButtonLayoutData(renameButton);
    ((GridLayout) parent.getLayout()).numColumns++;

    deleteteButton = new Button(parent, SWT.PUSH);
    deleteteButton.setFont(JFaceResources.getDialogFont());
    deleteteButton.setText(UIText.CheckoutDialog_Delete);
    setButtonLayoutData(deleteteButton);
    ((GridLayout) parent.getLayout()).numColumns++;

    renameButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {

            String refName = refNameFromDialog();
            String refPrefix;

            if (refName.startsWith(Constants.R_HEADS))
                refPrefix = Constants.R_HEADS;
            else if (refName.startsWith(Constants.R_REMOTES))
                refPrefix = Constants.R_REMOTES;
            else if (refName.startsWith(Constants.R_TAGS))
                refPrefix = Constants.R_TAGS;
            else {
                // the button should be disabled anyway, but we check again
                return;
            }

            String branchName = refName.substring(refPrefix.length());

            InputDialog labelDialog = getRefNameInputDialog(
                    NLS.bind(UIText.CheckoutDialog_QuestionNewBranchNameMessage, branchName, refPrefix),
                    refPrefix, branchName);
            if (labelDialog.open() == Window.OK) {
                String newRefName = refPrefix + labelDialog.getValue();
                try {
                    new Git(repo).branchRename().setOldName(refName).setNewName(labelDialog.getValue()).call();
                    branchTree.refresh();
                    markRef(newRefName);
                } catch (Throwable e1) {
                    reportError(e1, UIText.CheckoutDialog_ErrorCouldNotRenameRef, refName, newRefName,
                            e1.getMessage());
                }
            }
        }
    });
    newButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            CreateBranchWizard wiz = new CreateBranchWizard(repo, refNameFromDialog());
            if (new WizardDialog(getShell(), wiz).open() == Window.OK) {
                String newRefName = wiz.getNewBranchName();
                try {
                    branchTree.refresh();
                    markRef(Constants.R_HEADS + newRefName);
                    if (repo.getBranch().equals(newRefName))
                        // close branch selection dialog when new branch was
                        // already checked out from new branch wizard
                        CheckoutDialog.this.okPressed();
                } catch (Throwable e1) {
                    reportError(e1, UIText.CheckoutDialog_ErrorCouldNotCreateNewRef, newRefName);
                }
            }
        }
    });

    deleteteButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent selectionEvent) {
            try {
                CommonUtils.runCommand(IWorkbenchCommandConstants.EDIT_DELETE,
                        (IStructuredSelection) branchTree.getSelection());
                branchTree.refresh();
            } catch (Throwable e) {
                reportError(e, UIText.CheckoutDialog_ErrorCouldNotDeleteRef, refNameFromDialog());
            }
        }
    });

    super.createButtonsForButtonBar(parent);

    getButton(Window.OK).setText(UIText.CheckoutDialog_OkCheckout);

    // can't advance without a selection
    getButton(Window.OK).setEnabled(!branchTree.getSelection().isEmpty());
}

From source file:org.eclipse.egit.ui.internal.preferences.ConfigurationEditorComponent.java

License:Open Source License

/**
 * @return the control being created// w  w w  .  j  a  v  a  2s  .  c  o  m
 */
public Control createContents() {
    final Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(1, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(main);

    if (editableConfig instanceof FileBasedConfig) {
        Composite locationPanel = new Composite(main, SWT.NONE);
        locationPanel.setLayout(new GridLayout(3, false));
        GridDataFactory.fillDefaults().grab(true, false).applyTo(locationPanel);
        Label locationLabel = new Label(locationPanel, SWT.NONE);
        locationLabel.setText(UIText.ConfigurationEditorComponent_ConfigLocationLabel);
        // GridDataFactory.fillDefaults().applyTo(locationLabel);
        location = new Text(locationPanel, SWT.BORDER);
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(location);
        location.setEditable(false);
        Button openEditor = new Button(locationPanel, SWT.PUSH);
        // GridDataFactory.fillDefaults().applyTo(openEditor);
        openEditor.setText(UIText.ConfigurationEditorComponent_OpenEditorButton);
        openEditor.setToolTipText(UIText.ConfigurationEditorComponent_OpenEditorTooltip);
        openEditor.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                IFileStore store = EFS.getLocalFileSystem()
                        .getStore(new Path(((FileBasedConfig) editableConfig).getFile().getAbsolutePath()));
                try {
                    IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
                            new FileStoreEditorInput(store), EditorsUI.DEFAULT_TEXT_EDITOR_ID);
                } catch (PartInitException ex) {
                    Activator.handleError(ex.getMessage(), ex, true);
                }
            }
        });
    }
    tv = new TreeViewer(main, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    Tree tree = tv.getTree();
    GridDataFactory.fillDefaults().hint(100, 60).grab(true, true).applyTo(tree);
    TreeColumn key = new TreeColumn(tree, SWT.NONE);
    key.setText(UIText.ConfigurationEditorComponent_KeyColumnHeader);
    key.setWidth(150);

    TreeColumn value = new TreeColumn(tree, SWT.NONE);
    value.setText(UIText.ConfigurationEditorComponent_ValueColumnHeader);
    value.setWidth(250);

    tv.setContentProvider(new ConfigEditorContentProvider());
    Font defaultFont;
    if (useDialogFont)
        defaultFont = JFaceResources.getDialogFont();
    else
        defaultFont = JFaceResources.getDefaultFont();
    tv.setLabelProvider(new ConfigEditorLabelProvider(defaultFont));

    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);

    // if section or subsection is selected, we show the remove button
    Composite buttonPanel = new Composite(main, SWT.NONE);
    buttonPanel.setLayout(new GridLayout(2, false));
    GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
    final Button newEntry = new Button(buttonPanel, SWT.PUSH);
    GridDataFactory.fillDefaults().applyTo(newEntry);
    newEntry.setText(UIText.ConfigurationEditorComponent_NewValueButton);
    newEntry.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            String suggestedKey;
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            Object first = sel.getFirstElement();
            if (first instanceof Section)
                suggestedKey = ((Section) first).name + DOT;
            else if (first instanceof SubSection) {
                SubSection sub = (SubSection) first;
                suggestedKey = sub.parent.name + DOT + sub.name + DOT;
            } else if (first instanceof Entry) {
                Entry entry = (Entry) first;
                if (entry.sectionparent != null)
                    suggestedKey = entry.sectionparent.name + DOT;
                else
                    suggestedKey = entry.subsectionparent.parent.name + DOT + entry.subsectionparent.name + DOT;
            } else
                suggestedKey = null;

            AddConfigEntryDialog dlg = new AddConfigEntryDialog(getShell(), editableConfig, suggestedKey);
            if (dlg.open() == Window.OK) {
                StringTokenizer st = new StringTokenizer(dlg.getKey(), DOT);
                if (st.countTokens() == 2) {
                    editableConfig.setString(st.nextToken(), null, st.nextToken(), dlg.getValue());
                    markDirty();
                } else if (st.countTokens() == 3) {
                    editableConfig.setString(st.nextToken(), st.nextToken(), st.nextToken(), dlg.getValue());
                    markDirty();
                } else
                    Activator.handleError(UIText.ConfigurationEditorComponent_WrongNumberOfTokensMessage, null,
                            true);
            }
        }

    });
    remove = new Button(buttonPanel, SWT.PUSH);
    GridDataFactory.fillDefaults().applyTo(remove);
    remove.setText(UIText.ConfigurationEditorComponent_RemoveAllButton);
    remove.setToolTipText(UIText.ConfigurationEditorComponent_RemoveAllTooltip);
    remove.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            Object first = sel.getFirstElement();
            if (first instanceof Section) {
                Section section = (Section) first;
                if (MessageDialog.openConfirm(getShell(),
                        UIText.ConfigurationEditorComponent_RemoveSectionTitle,
                        NLS.bind(UIText.ConfigurationEditorComponent_RemoveSectionMessage, section.name))) {
                    editableConfig.unsetSection(section.name, null);
                    markDirty();
                }
            } else if (first instanceof SubSection) {
                SubSection section = (SubSection) first;
                if (MessageDialog.openConfirm(getShell(),
                        UIText.ConfigurationEditorComponent_RemoveSubsectionTitle,
                        NLS.bind(UIText.ConfigurationEditorComponent_RemoveSubsectionMessage,
                                section.parent.name + DOT + section.name))) {
                    editableConfig.unsetSection(section.parent.name, section.name);
                    markDirty();
                }
            } else {
                Activator.handleError(UIText.ConfigurationEditorComponent_NoSectionSubsectionMessage, null,
                        true);
            }

            super.widgetSelected(e);
        }
    });

    // if an entry is selected, then we show the value plus change button
    Composite valuePanel = new Composite(main, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(valuePanel);
    valuePanel.setLayout(new GridLayout(3, false));
    new Label(valuePanel, SWT.NONE).setText(UIText.ConfigurationEditorComponent_ValueLabel);
    valueText = new Text(valuePanel, SWT.BORDER);
    valueText.setText(UIText.ConfigurationEditorComponent_NoEntrySelectedMessage);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(valueText);
    // make the buttons equal width
    Composite buttonContainer = new Composite(valuePanel, SWT.NONE);
    buttonContainer.setLayout(new GridLayout(3, true));
    changeValue = new Button(buttonContainer, SWT.PUSH);
    GridDataFactory.fillDefaults().applyTo(changeValue);
    changeValue.setText(UIText.ConfigurationEditorComponent_ChangeButton);
    changeValue.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            Object first = sel.getFirstElement();
            if (first instanceof Entry) {
                Entry entry = (Entry) first;
                entry.changeValue(valueText.getText());
                markDirty();
            }
        }
    });
    deleteValue = new Button(buttonContainer, SWT.PUSH);
    GridDataFactory.fillDefaults().applyTo(deleteValue);
    deleteValue.setText(UIText.ConfigurationEditorComponent_DeleteButton);
    deleteValue.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            Object first = sel.getFirstElement();
            if (first instanceof Entry) {
                Entry entry = (Entry) first;
                entry.removeValue();
                markDirty();
            }

        }
    });
    addValue = new Button(buttonContainer, SWT.PUSH);
    GridDataFactory.fillDefaults().applyTo(addValue);
    addValue.setText(UIText.ConfigurationEditorComponent_AddButton);
    addValue.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            Object first = sel.getFirstElement();
            if (first instanceof Entry) {
                Entry entry = (Entry) first;
                entry.addValue(valueText.getText());
                markDirty();
            }

        }
    });

    tv.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateEnablement();
        }
    });

    valueText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (valueText.getText().length() == 0) {
                setErrorMessage(UIText.ConfigurationEditorComponent_EmptyStringNotAllowed);
                changeValue.setEnabled(false);
            } else {
                setErrorMessage(null);
                changeValue.setEnabled(true);
            }
        }
    });

    initControlsFromConfig();
    return main;
}

From source file:org.eclipse.egit.ui.internal.preferences.GitProjectPropertyPage.java

License:Open Source License

private void createHeadLink(final Repository repository, Composite composite) throws IOException {
    final ObjectId objectId = repository.resolve(repository.getFullBranch());
    if (objectId == null) {
        Text headLabel = createLabeledReadOnlyText(composite, UIText.GitProjectPropertyPage_LabelId);
        if (repository.getAllRefs().size() == 0)
            headLabel.setText(UIText.GitProjectPropertyPage_ValueEmptyRepository);
        else/*from  w w w  .  java  2  s .co  m*/
            headLabel.setText(UIText.GitProjectPropertyPage_ValueUnbornBranch);
    } else {
        Hyperlink headLink = createHeadHyperLink(composite, UIText.GitProjectPropertyPage_LabelId);
        headLink.setText(objectId.name());
        headLink.setUnderlined(true);
        headLink.setFont(JFaceResources.getDialogFont());
        headLink.setForeground(JFaceColors.getHyperlinkText(headLink.getDisplay()));
        headLink.addHyperlinkListener(new HyperlinkAdapter() {
            @Override
            public void linkActivated(HyperlinkEvent e) {
                RepositoryCommit commit = getCommit(repository, objectId);
                if (commit != null)
                    CommitEditor.openQuiet(commit);
            }
        });
    }
}

From source file:org.eclipse.emf.texo.eclipse.properties.DialogUnits.java

License:Open Source License

public DialogUnits(Control control) {
    final GC gc = new GC(control);
    gc.setFont(JFaceResources.getDialogFont());
    fontMetrics = gc.getFontMetrics();
    gc.dispose();
}

From source file:org.eclipse.epp.internal.logging.aeri.ui.ConfigurationDialog.java

License:Open Source License

private void calibrateTooltip(DefaultToolTip toolTip, String toolTipText) {
    toolTip.setText(toolTipText);/*from www . j a va2s .  c o  m*/
    toolTip.setFont(JFaceResources.getDialogFont());
    toolTip.setShift(TOOLTIP_DISPLACEMENT);
    toolTip.setHideDelay(TOOLTIP_MS_HIDE_DELAY);
}

From source file:org.eclipse.epp.internal.mpc.ui.wizards.OverviewToolTip.java

License:Open Source License

@Override
protected Composite createToolTipContentArea(Event event, final Composite parent) {
    GridLayoutFactory.fillDefaults().applyTo(parent);

    Color backgroundColor = parent.getDisplay().getSystemColor(SWT.COLOR_WHITE);
    final Composite container = new Composite(parent, SWT.NULL);
    container.setBackground(backgroundColor);

    Image image = null;/*from   w  w  w. j a  v a  2s  .c om*/
    if (overview.getScreenshot() != null) {
        image = computeImage(source, overview.getScreenshot());
        if (image != null) {
            final Image fimage = image;
            container.addDisposeListener(new DisposeListener() {
                public void widgetDisposed(DisposeEvent e) {
                    fimage.dispose();
                }
            });
        }
    }
    final boolean hasLearnMoreLink = overview.getUrl() != null && overview.getUrl().length() > 0;

    final int borderWidth = 1;
    final int heightHint = SCREENSHOT_HEIGHT + (borderWidth * 2);
    final int widthHint = SCREENSHOT_WIDTH;

    final int containerWidthHintWithImage = 650;
    final int containerWidthHintWithoutImage = 500;

    GridDataFactory.fillDefaults().grab(true, true)
            .hint(image == null ? containerWidthHintWithoutImage : containerWidthHintWithImage, SWT.DEFAULT)
            .applyTo(container);

    GridLayoutFactory.fillDefaults().numColumns((leftImage != null) ? 3 : 2).margins(5, 5).spacing(3, 0)
            .applyTo(container);

    if (leftImage != null) {
        Label imageLabel = new Label(container, SWT.NONE);
        imageLabel.setImage(leftImage);
        imageLabel.setBackground(backgroundColor);
        int imageWidthHint = leftImage.getBounds().width + 5;
        GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).hint(imageWidthHint, SWT.DEFAULT)
                .applyTo(imageLabel);
    }

    String summary = overview.getSummary();

    Composite summaryContainer = new Composite(container, SWT.NULL);
    summaryContainer.setBackground(backgroundColor);
    GridLayoutFactory.fillDefaults().applyTo(summaryContainer);

    GridDataFactory gridDataFactory = GridDataFactory.fillDefaults().grab(true, true)
            .span(image == null ? 2 : 1, 1);
    if (image != null) {
        gridDataFactory.hint(widthHint, heightHint);
    }
    gridDataFactory.applyTo(summaryContainer);

    Browser summaryLabel = new Browser(summaryContainer, SWT.NULL);

    Font dialogFont = JFaceResources.getDialogFont();
    FontData[] fontData = dialogFont.getFontData();
    String attr = ""; //$NON-NLS-1$
    String fontSizeUnitOfMeasure = "pt"; //$NON-NLS-1$
    if (Platform.OS_MACOSX.equals(Platform.getOS())) {
        fontSizeUnitOfMeasure = "px"; //$NON-NLS-1$
    } else if (Platform.OS_WIN32.equals(Platform.getOS())) {
        attr = "overflow: auto; "; //$NON-NLS-1$
    }
    String cssStyle = "body, p, div, *  {" + attr + "font-family:\"" + fontData[0].getName() //$NON-NLS-1$ //$NON-NLS-2$
            + "\",Arial,sans-serif !important;font-size:" + fontData[0].getHeight() + fontSizeUnitOfMeasure //$NON-NLS-1$
            + " !important;" //$NON-NLS-1$
            + "} body { margin: 0px; background-color: white;}"; //$NON-NLS-1$
    summaryLabel.setFont(dialogFont);
    String html = "<html><style>" + cssStyle + "</style><body>" + TextUtil.cleanInformalHtmlMarkup(summary) //$NON-NLS-1$//$NON-NLS-2$
            + "</body></html>"; //$NON-NLS-1$
    summaryLabel.setText(html);
    summaryLabel.setBackground(backgroundColor);
    // instead of opening links in the tooltip, open a new browser window
    summaryLabel.addLocationListener(new LocationListener() {
        public void changing(LocationEvent event) {
            if (event.location.equals("about:blank")) { //$NON-NLS-1$
                return;
            }
            event.doit = false;
            OverviewToolTip.this.hide();
            WorkbenchUtil.openUrl(event.location, IWorkbenchBrowserSupport.AS_EXTERNAL);
        }

        public void changed(LocationEvent event) {
        }
    });

    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true)
            .hint(SWT.DEFAULT, image == null ? SCREENSHOT_HEIGHT : SWT.DEFAULT).applyTo(summaryLabel);

    if (image != null) {
        final Composite imageContainer = new Composite(container, SWT.BORDER);
        GridLayoutFactory.fillDefaults().applyTo(imageContainer);

        GridDataFactory.fillDefaults().grab(false, false).align(SWT.CENTER, SWT.BEGINNING)
                .hint(widthHint + (borderWidth * 2), heightHint).applyTo(imageContainer);

        Label imageLabel = new Label(imageContainer, SWT.NULL);
        GridDataFactory.fillDefaults().hint(widthHint, SCREENSHOT_HEIGHT).indent(borderWidth, borderWidth)
                .applyTo(imageLabel);
        imageLabel.setImage(image);
        imageLabel.setBackground(backgroundColor);
        imageLabel.setSize(widthHint, SCREENSHOT_HEIGHT);

        final Cursor handCursor = new Cursor(image.getDevice(), SWT.CURSOR_HAND);
        imageLabel.setCursor(handCursor);
        imageLabel.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
                handCursor.dispose();
            }
        });
        imageLabel.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                OverviewToolTip.this.hide();
                WorkbenchUtil.openUrl(overview.getScreenshot(), IWorkbenchBrowserSupport.AS_EXTERNAL);
            }
        });

        // creates a border
        imageContainer.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
    }
    if (hasLearnMoreLink) {
        Link link = new Link(summaryContainer, SWT.NULL);
        GridDataFactory.fillDefaults().grab(false, false).align(SWT.BEGINNING, SWT.CENTER).applyTo(link);
        link.setText(Messages.OverviewToolTip_learnMoreLink);
        link.setBackground(backgroundColor);
        link.setToolTipText(NLS.bind(Messages.OverviewToolTip_openUrlInBrowser, overview.getUrl()));
        link.addSelectionListener(new SelectionListener() {
            public void widgetSelected(SelectionEvent e) {
                OverviewToolTip.this.hide();
                browser.openUrl(overview.getUrl());
            }

            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
    }
    if (image == null) {
        // prevent overviews with no image from providing unlimited text.
        Point optimalSize = summaryContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
        if (optimalSize.y > (heightHint + 10)) {
            ((GridData) summaryContainer.getLayoutData()).heightHint = heightHint;
            container.layout(true);
        }
    }
    // hack: cause the tooltip to gain focus so that we can capture the escape key
    //       this must be done async since the tooltip is not yet visible.
    Display.getCurrent().asyncExec(new Runnable() {
        public void run() {
            if (!parent.isDisposed()) {
                parent.setFocus();
            }
        }
    });
    return container;
}

From source file:org.eclipse.equinox.internal.p2.ui.admin.dialogs.IUImplementationGroup.java

License:Open Source License

protected Composite createGroupComposite(Composite parent, ModifyListener listener) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;/*  w  ww  .jav a2 s  . c  om*/
    composite.setLayout(layout);
    GridData data = new GridData();
    data.widthHint = 350;
    composite.setLayoutData(data);

    // Grid data for text controls
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);

    // Grid data for controls spanning both columns
    GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
    gd2.horizontalSpan = 2;

    // Grid data for lists grabbing vertical space
    GridData gdList = new GridData(GridData.FILL_HORIZONTAL);
    GC gc = new GC(parent);
    gc.setFont(JFaceResources.getDialogFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    gdList.horizontalSpan = 2;
    gdList.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 5);

    boolean editable = iuElement == null && listener != null;

    Label label = new Label(composite, SWT.NONE);
    label.setText(ProvAdminUIMessages.IUGroup_ID);
    id = new Text(composite, SWT.BORDER);
    id.setLayoutData(gd);
    if (editable) {
        id.addModifyListener(listener);
    } else {
        id.setEditable(false);
    }

    label = new Label(composite, SWT.NONE);
    label.setText(ProvAdminUIMessages.IUGroup_Version);
    version = new Text(composite, SWT.BORDER);
    version.setLayoutData(gd);

    label = new Label(composite, SWT.NONE);
    label.setText(ProvAdminUIMessages.IUGroup_Namespace);
    namespace = new Text(composite, SWT.BORDER);
    namespace.setLayoutData(gd);

    label = new Label(composite, SWT.NONE);
    label.setText(ProvAdminUIMessages.IUGroup_TouchpointType);
    touchpointType = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
    touchpointType.setLayoutData(gd);

    label = new Label(composite, SWT.NONE);
    label.setText(ProvAdminUIMessages.IUGroup_TouchpointData);
    label.setLayoutData(gd2);
    touchpointData = new List(composite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    touchpointData.setLayoutData(gdList);
    createCopyMenu(touchpointData);

    label = new Label(composite, SWT.NONE);
    label.setText(ProvAdminUIMessages.IUGroup_RequiredCapabilities);
    label.setLayoutData(gd2);
    requiredCapabilities = new List(composite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    requiredCapabilities.setLayoutData(gdList);
    createCopyMenu(requiredCapabilities);

    label = new Label(composite, SWT.NONE);
    label.setText(ProvAdminUIMessages.IUGroup_ProvidedCapabilities);
    label.setLayoutData(gd2);
    providedCapabilities = new List(composite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    providedCapabilities.setLayoutData(gdList);
    createCopyMenu(providedCapabilities);

    if (editable) {
        id.addModifyListener(listener);
        version.addModifyListener(listener);
        namespace.addModifyListener(listener);
        touchpointType.addModifyListener(listener);
    } else {
        id.setEditable(false);
        version.setEditable(false);
        namespace.setEditable(false);
        touchpointType.setEditable(false);
    }
    initializeFields();
    return composite;
}

From source file:org.eclipse.equinox.internal.p2.ui.dialogs.AvailableIUsPage.java

License:Open Source License

public void createControl(Composite parent) {
    initializeDialogUnits(parent);//from  w  ww.ja v a2  s  .  c  o  m
    this.display = parent.getDisplay();

    Composite composite = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    composite.setLayoutData(gd);
    setDropTarget(composite);

    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;

    composite.setLayout(layout);
    // Repo manipulation 
    createRepoArea(composite);

    sashForm = new SashForm(composite, SWT.VERTICAL);
    FillLayout fill = new FillLayout();
    sashForm.setLayout(fill);
    GridData data = new GridData(GridData.FILL_BOTH);
    sashForm.setLayoutData(data);

    Composite aboveSash = new Composite(sashForm, SWT.NONE);
    GridLayout grid = new GridLayout();
    grid.marginWidth = 0;
    grid.marginHeight = 0;
    aboveSash.setLayout(grid);

    // Now the available group 
    // If repositories are visible, we want to default to showing no repos.  Otherwise all.
    int filterConstant = AvailableIUGroup.AVAILABLE_NONE;
    if (!getPolicy().getRepositoriesVisible())
        filterConstant = AvailableIUGroup.AVAILABLE_ALL;
    nameColumn = new IUColumnConfig(ProvUIMessages.ProvUI_NameColumnTitle, IUColumnConfig.COLUMN_NAME,
            ILayoutConstants.DEFAULT_PRIMARY_COLUMN_WIDTH + 15);
    versionColumn = new IUColumnConfig(ProvUIMessages.ProvUI_VersionColumnTitle, IUColumnConfig.COLUMN_VERSION,
            ILayoutConstants.DEFAULT_COLUMN_WIDTH);

    getColumnWidthsFromSettings();
    availableIUGroup = new AvailableIUGroup(getProvisioningUI(), aboveSash, JFaceResources.getDialogFont(),
            queryContext, new IUColumnConfig[] { nameColumn, versionColumn }, filterConstant);

    // Selection listeners must be registered on both the normal selection
    // events and the check mark events.  Must be done after buttons 
    // are created so that the buttons can register and receive their selection notifications before us.
    availableIUGroup.getStructuredViewer().addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateDetails();
            iuDetailsGroup.enablePropertyLink(availableIUGroup.getSelectedIUElements().length == 1);
        }
    });

    availableIUGroup.getCheckboxTreeViewer().addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            updateSelection();
        }
    });

    addViewerProvisioningListeners();

    availableIUGroup.setUseBoldFontForFilteredItems(
            queryContext.getViewType() != IUViewQueryContext.AVAILABLE_VIEW_FLAT);
    setDropTarget(availableIUGroup.getStructuredViewer().getControl());
    activateCopy(availableIUGroup.getStructuredViewer().getControl());

    // select buttons
    createSelectButtons(aboveSash);

    // Details area
    iuDetailsGroup = new IUDetailsGroup(sashForm, availableIUGroup.getStructuredViewer(), SWT.DEFAULT, true);

    sashForm.setWeights(getSashWeights());

    // Controls for filtering/presentation/site selection
    Composite controlsComposite = new Composite(composite, SWT.NONE);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    controlsComposite.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    controlsComposite.setLayoutData(gd);

    createViewControlsArea(controlsComposite);

    initializeWidgetState();
    setControl(composite);
    composite.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            removeProvisioningListeners();
        }

    });
    Dialog.applyDialogFont(composite);
}

From source file:org.eclipse.equinox.internal.p2.ui.dialogs.IUDetailsGroup.java

License:Open Source License

/**
 * Creates the group composite that holds the details area
 * @param parent The parent composite//from w  w  w. j ava2 s  . c o m
 */
void createGroupComposite(Composite parent) {
    Group detailsComposite = new Group(parent, SWT.NONE);
    GC gc = new GC(parent);
    gc.setFont(JFaceResources.getDialogFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    detailsComposite.setText(ProvUIMessages.ProfileModificationWizardPage_DetailsLabel);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    detailsComposite.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    detailsComposite.setLayoutData(gd);

    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.verticalIndent = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);
    gd.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics,
            ILayoutConstants.DEFAULT_DESCRIPTION_HEIGHT);
    gd.minimumHeight = Dialog.convertHeightInCharsToPixels(fontMetrics,
            ILayoutConstants.MINIMUM_DESCRIPTION_HEIGHT);
    gd.widthHint = widthHint;
    if (scrollable)
        detailsArea = new Text(detailsComposite, SWT.WRAP | SWT.READ_ONLY | SWT.V_SCROLL);
    else
        detailsArea = new Text(detailsComposite, SWT.WRAP | SWT.READ_ONLY);
    detailsArea.setLayoutData(gd);

    gd = new GridData(SWT.END, SWT.BOTTOM, true, false);
    gd.horizontalIndent = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN);
    propLink = createLink(detailsComposite,
            new PropertyDialogAction(new SameShellProvider(parent.getShell()), selectionProvider),
            ProvUIMessages.AvailableIUsPage_GotoProperties);
    propLink.setLayoutData(gd);

    // set the initial state based on selection
    propLink.setVisible(!selectionProvider.getSelection().isEmpty());

}