Example usage for org.eclipse.jface.layout GridDataFactory hint

List of usage examples for org.eclipse.jface.layout GridDataFactory hint

Introduction

In this page you can find the example usage for org.eclipse.jface.layout GridDataFactory hint.

Prototype

public GridDataFactory hint(int xHint, int yHint) 

Source Link

Document

Sets the width and height hints.

Usage

From source file:com.aptana.editor.js.validator.JSLintValidatorPreferenceCompositeFactory.java

License:Open Source License

public Composite createPreferenceComposite(Composite parent, final IBuildParticipantWorkingCopy participant) {
    Composite master = new Composite(parent, SWT.NONE);
    master.setLayout(GridLayoutFactory.fillDefaults().create());

    GridDataFactory fillHoriz = GridDataFactory.fillDefaults().grab(true, false);

    // JSON Options
    Group group = new Group(master, SWT.BORDER);
    group.setText(Messages.JSLintValidatorPreferenceCompositeFactory_OptionsTitle);
    group.setLayout(new GridLayout());
    group.setLayoutData(fillHoriz.create());

    Label label = new Label(group, SWT.WRAP);
    label.setText(Messages.JSLintValidatorPreferenceCompositeFactory_OptionsMsg);
    fillHoriz.applyTo(label);//from   w  w w  .  j  av  a  2 s. c  om

    final Text text = new Text(group, SWT.MULTI | SWT.V_SCROLL);

    final ControlDecoration decoration = new ControlDecoration(text, SWT.LEFT | SWT.TOP);
    decoration.setDescriptionText(Messages.JSLintValidatorPreferenceCompositeFactory_OptionsParseError);
    decoration
            .setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEC_FIELD_ERROR));
    decoration.hide();

    text.setText(participant.getPreferenceString(IPreferenceConstants.JS_LINT_OPTIONS));
    fillHoriz.hint(SWT.DEFAULT, 100).applyTo(text);
    text.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            decoration.hide();
            try {
                String optionsAsJSON = text.getText();
                JSON.parse(optionsAsJSON);
                participant.setPreference(IPreferenceConstants.JS_LINT_OPTIONS, text.getText());
            } catch (IllegalStateException e1) {
                decoration.show();
            }
        }
    });

    // Filters
    Composite filtersGroup = new ValidatorFiltersPreferenceComposite(master, participant);
    filtersGroup.setLayoutData(fillHoriz.grab(true, true).hint(SWT.DEFAULT, 150).create());

    return master;
}

From source file:com.nokia.carbide.cpp.internal.pi.button.ui.BupProfileEditDialog.java

License:Open Source License

public Control createDialogArea(Composite parent) {
    getShell().setText(/*from  ww  w.ja  va  2s  . co  m*/
            Messages.getString("BupProfileEditDialog.editingProfile") + profileForThisEdit.getProfileId()); //$NON-NLS-1$
    setTitleImage(ButtonPlugin.getImageDescriptor("icons/PI_Meter_20x20.png").createImage()); //$NON-NLS-1$
    setTitle(Messages.getString("BupProfileEditDialog.profile") + profileForThisEdit.getProfileId()); //$NON-NLS-1$

    GridLayoutFactory layoutExpandBoth = GridLayoutFactory.fillDefaults();
    GridDataFactory gridDataExpandBoth = GridDataFactory.fillDefaults().grab(true, true);

    GridLayoutFactory gridLayoutButton = GridLayoutFactory.swtDefaults();
    GridDataFactory gridDataButton = GridDataFactory.swtDefaults();

    content = new Composite(parent, SWT.NONE);
    layoutExpandBoth.applyTo(content);
    gridDataExpandBoth.applyTo(content);

    PlatformUI.getWorkbench().getHelpSystem().setHelp(content,
            ComNokiaCarbidePiButtonHelpIDs.PI_PROFILE_EDIT_DIALOG);

    localeMappingGroup = new Group(content, SWT.NONE);
    layoutExpandBoth.applyTo(localeMappingGroup);
    gridDataExpandBoth.applyTo(localeMappingGroup);

    mappingComposite = new Composite(localeMappingGroup, SWT.NONE);
    layoutExpandBoth.copy().numColumns(2).applyTo(mappingComposite);
    gridDataExpandBoth.applyTo(mappingComposite);
    mappingTableViewer = new BupMapTableViewer(mappingComposite, true);
    Table mappingTable = mappingTableViewer.getTable();
    // enable the edit button only when a single file filter is selected
    mappingTable.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            handleViewerSelection();
        }
    });

    int maxWidth;
    buttonComposite = new Composite(mappingComposite, SWT.NONE);
    gridLayoutButton.applyTo(buttonComposite);
    gridDataButton.copy().align(SWT.CENTER, SWT.FILL).grab(false, true).applyTo(buttonComposite);
    addButton = new Button(buttonComposite, SWT.NONE);
    addButton.setText(Messages.getString("BupProfileEditDialog.add")); //$NON-NLS-1$
    addButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            handleAdd();
        }
    });
    maxWidth = buttonComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
    editButton = new Button(buttonComposite, SWT.NONE);
    editButton.setText(Messages.getString("BupProfileEditDialog.edit")); //$NON-NLS-1$
    editButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            handleEdit();
        }
    });
    maxWidth = Math.max(maxWidth, editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
    removeButton = new Button(buttonComposite, SWT.NONE);
    removeButton.setText(Messages.getString("BupProfileEditDialog.remove")); //$NON-NLS-1$
    removeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            handleRemove();
        }
    });
    maxWidth = Math.max(maxWidth, removeButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
    //dummy label as divider
    new Label(buttonComposite, SWT.NONE);
    new Label(buttonComposite, SWT.NONE);
    new Label(buttonComposite, SWT.NONE);
    new Label(buttonComposite, SWT.NONE);
    new Label(buttonComposite, SWT.NONE);
    clearButton = new Button(buttonComposite, SWT.NONE);
    clearButton.setText(Messages.getString("BupProfileEditDialog.clearProfile")); //$NON-NLS-1$
    clearButton.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }

        public void widgetSelected(SelectionEvent arg0) {
            if (MessageDialog.openQuestion(getShell(), Messages.getString("BupProfileEditDialog.clearProfile"), //$NON-NLS-1$
                    Messages.getString("BupProfileEditDialog.clearAllConfirm"))) { //$NON-NLS-1$
                Set<Integer> keySet = cachedMap.getKeyCodeSet();
                Integer[] keyCodes = keySet.toArray(new Integer[keySet.size()]);
                for (Integer keyCode : keyCodes) {
                    cachedMap.removeMapping(keyCode);
                }
                refreshTable();
            }
        }
    });
    maxWidth = Math.max(maxWidth, clearButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);

    gridDataButton.hint(maxWidth, addButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y).applyTo(addButton);
    gridDataButton.hint(maxWidth, removeButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y).applyTo(removeButton);
    gridDataButton.hint(maxWidth, editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y).applyTo(editButton);
    gridDataButton.hint(maxWidth, clearButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y).applyTo(clearButton);

    initialize();

    return content;
}

From source file:com.nokia.carbide.cpp.internal.pi.button.ui.ButtonTabPage.java

License:Open Source License

public ButtonTabPage(Composite parent) {
    super(parent, SWT.NONE);

    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
            ComNokiaCarbidePiButtonHelpIDs.PI_BUTTON_MAP_PREF_TAB);

    GridLayoutFactory layoutExpandBoth = GridLayoutFactory.fillDefaults();
    GridDataFactory gridDataExpandBoth = GridDataFactory.fillDefaults().grab(true, true);

    GridLayoutFactory layoutExpandHorizontal = GridLayoutFactory.swtDefaults();
    GridDataFactory gridDataExpandHorizontal = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER)
            .grab(true, false);//w ww.  j ava2 s .  c om

    GridDataFactory gridDataButton = GridDataFactory.swtDefaults();

    layoutExpandBoth.applyTo(this);
    gridDataExpandBoth.applyTo(this);

    content = new Composite(this, SWT.NONE);
    layoutExpandBoth.applyTo(content);
    gridDataExpandBoth.applyTo(content);

    profileGroup = new Group(content, SWT.NONE);
    layoutExpandHorizontal.applyTo(profileGroup);
    gridDataExpandHorizontal.applyTo(profileGroup);
    profileGroup.setText(Messages.getString("ButtonTabPage.manageProfiles")); //$NON-NLS-1$

    profileCombo = new Combo(profileGroup, SWT.READ_ONLY);
    layoutExpandHorizontal.applyTo(profileCombo);
    gridDataExpandHorizontal.applyTo(profileCombo);
    profileCombo.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }

        public void widgetSelected(SelectionEvent arg0) {
            refreshTableToCombo();
        }
    });

    profileButtonComposite = new Composite(profileGroup, SWT.NONE);
    layoutExpandHorizontal.copy().numColumns(3).applyTo(profileButtonComposite);
    gridDataExpandHorizontal.applyTo(profileButtonComposite);

    int maxWidth;
    profileNewButton = new Button(profileButtonComposite, SWT.NONE);
    profileNewButton.setText(Messages.getString("ButtonTabPage.duplicate")); //$NON-NLS-1$
    profileNewButton.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }

        public void widgetSelected(SelectionEvent arg0) {

            BupProfileDuplicateDialog dialog = new BupProfileDuplicateDialog(getShell(),
                    profiles.get(profileCombo.getSelectionIndex()));
            if (dialog.open() == BupProfileDuplicateDialog.OK) {
                refreshCombo();
                profileCombo.select(BupEventMapManager.getInstance().getProfilesFromWorkspacePref().size() - 1); // we cheat a bit by knowing addToWorkspace always append to the end
                refreshTableToCombo(); // current profile had been removed;
            }
        }
    });
    maxWidth = profileNewButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
    profileEditButton = new Button(profileButtonComposite, SWT.NONE);
    profileEditButton.setText(Messages.getString("ButtonTabPage.Edit")); //$NON-NLS-1$
    profileEditButton.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }

        public void widgetSelected(SelectionEvent arg0) {
            IBupEventMapProfile profile = profiles.get(profileCombo.getSelectionIndex());
            if (profile != null) {
                new BupProfileEditDialog(getShell(), profile).open();
                refreshTableToCombo(); // current profile may had changed
            }
        }
    });
    maxWidth = Math.max(maxWidth, profileEditButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
    profileRemoveButton = new Button(profileButtonComposite, SWT.NONE);
    profileRemoveButton.setText(Messages.getString("ButtonTabPage.remove")); //$NON-NLS-1$
    profileRemoveButton.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }

        public void widgetSelected(SelectionEvent arg0) {
            IBupEventMapProfile profile = profiles.get(profileCombo.getSelectionIndex());
            if (profile != null) {
                if (MessageDialog.openQuestion(getShell(),
                        Messages.getString("ButtonTabPage.confirmRemovalHeading"), //$NON-NLS-1$
                        Messages.getString("ButtonTabPage.profile") + profile.getProfileId() //$NON-NLS-1$
                                + Messages.getString("ButtonTabPage.confirmRemoval"))) { //$NON-NLS-1$ //$NON-NLS-3$
                    if (BupEventMapManager.getInstance().canRemoveProfile(profile)) {
                        BupEventMapManager.getInstance().removeFromWorkspace(profile);
                        refreshCombo();
                        refreshTableToCombo(); // current profile had been removed;
                    } else {
                        MessageDialog.openInformation(getShell(),
                                Messages.getString("ButtonTabPage.cannotRemoveProfile"), //$NON-NLS-1$
                                Messages.getString("ButtonTabPage.profile") + profile.getProfileId() //$NON-NLS-1$
                                        + Messages.getString("ButtonTabPage.isStillOpen")); //$NON-NLS-1$ //$NON-NLS-3$
                    }
                }
            }
        }
    });
    maxWidth = Math.max(maxWidth, profileRemoveButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);

    importExportButtonComposite = new Composite(content, SWT.NONE);
    layoutExpandHorizontal.copy().numColumns(2).applyTo(importExportButtonComposite);
    gridDataExpandHorizontal.applyTo(importExportButtonComposite);

    profileImportLink = new Link(importExportButtonComposite, SWT.NONE);
    profileImportLink.setText(Messages.getString("ButtonTabPage.importHref")); //$NON-NLS-1$
    profileImportLink.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent arg0) {
        }

        public void widgetSelected(SelectionEvent arg0) {
            importXML();
        }

    });
    profileExportLink = new Link(importExportButtonComposite, SWT.NONE);
    profileExportLink.setText(Messages.getString("ButtonTabPage.exportHref")); //$NON-NLS-1$
    profileExportLink.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent arg0) {
        }

        public void widgetSelected(SelectionEvent arg0) {
            exportXML();
        }

    });

    gridDataButton.hint(maxWidth, profileNewButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y)
            .applyTo(profileNewButton);
    gridDataButton.hint(maxWidth, profileRemoveButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y)
            .applyTo(profileRemoveButton);
    gridDataButton.hint(maxWidth, profileEditButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y)
            .applyTo(profileEditButton);

    mappingGroup = new Group(content, SWT.NONE);
    layoutExpandBoth.applyTo(mappingGroup);
    gridDataExpandBoth.applyTo(mappingGroup);
    mappingGroup.setText(Messages.getString("ButtonTabPage.keyPressMapping")); //$NON-NLS-1$

    Composite compositeToLookBetter = new Composite(mappingGroup, SWT.NONE);
    layoutExpandHorizontal.applyTo(compositeToLookBetter);
    gridDataExpandHorizontal.applyTo(compositeToLookBetter);

    mappingTableViewer = new BupMapTableViewer(compositeToLookBetter, false);

    refreshCombo();
}

From source file:com.nokia.carbide.cpp.internal.pi.button.ui.SwitchBupMapDialog.java

License:Open Source License

protected void createButtonsForButtonBar(Composite parent) {
    super.createButtonsForButtonBar(parent);
    GridDataFactory gridDataButton = GridDataFactory.swtDefaults();
    int maxWidth = 0;
    for (Integer id : allId) {
        Button button = getButton(id);
        maxWidth = Math.max(maxWidth, button.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
    }/*from w  ww  .  j a v  a 2 s .c o  m*/
    for (Integer id : allId) {
        Button button = getButton(id);
        gridDataButton.hint(maxWidth, button.computeSize(SWT.DEFAULT, SWT.DEFAULT).y).applyTo(button);
    }
    // now buttons are there, we can  disable key
    getButton(IDialogConstants.OK_ID).setEnabled(false);
}

From source file:org.eclipse.ease.discovery.ui.internal.common.OverviewToolTip.java

License:Open Source License

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

    Composite container = new Composite(parent, SWT.NULL);
    container.setBackground(null);//from   ww w .  j a v a 2s . c om

    Image image = null;
    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 fixedImageHeight = 240;
    final int fixedImageWidth = 320;
    final int heightHint = fixedImageHeight + (borderWidth * 2);
    final int widthHint = fixedImageWidth;

    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);
        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(null);
    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);

    StyledText summaryLabel = new StyledText(summaryContainer, SWT.WRAP | SWT.READ_ONLY | SWT.NO_FOCUS);
    summaryLabel.setText(summary);
    Point size = summaryLabel.computeSize(widthHint, SWT.DEFAULT);
    if (size.y > heightHint - 20) {
        summaryLabel.dispose();
        summaryLabel = new StyledText(summaryContainer, SWT.WRAP | SWT.READ_ONLY | SWT.NO_FOCUS | SWT.V_SCROLL);
        summaryLabel.setText(summary);
    }
    summaryLabel.setBackground(null);

    GridDataFactory.fillDefaults().grab(true, true).align(SWT.BEGINNING, SWT.BEGINNING).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, fixedImageHeight).indent(borderWidth, borderWidth)
                .applyTo(imageLabel);
        imageLabel.setImage(image);
        imageLabel.setBackground(null);
        imageLabel.setSize(widthHint, fixedImageHeight);

        // creates a border
        imageContainer.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    }
    if (hasLearnMoreLink) {
        Link link = new Link(summaryContainer, SWT.NULL);
        GridDataFactory.fillDefaults().grab(false, false).align(SWT.BEGINNING, SWT.CENTER).applyTo(link);
        link.setText(Messages.ConnectorDescriptorToolTip_detailsLink);
        link.setBackground(null);
        link.setToolTipText(
                NLS.bind(Messages.ConnectorDescriptorToolTip_detailsLink_tooltip, overview.getUrl()));
        link.addSelectionListener(new SelectionListener() {
            public void widgetSelected(SelectionEvent e) {
                WorkbenchUtil.openUrl(overview.getUrl(), IWorkbenchBrowserSupport.AS_EXTERNAL);
            }

            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.emf.ecp.view.spi.core.swt.renderer.TextControlSWTRenderer.java

License:Open Source License

@Override
protected Control createSWTControl(Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).equalWidth(true).applyTo(composite);
    final Text text = new Text(composite, getTextWidgetStyle());
    text.setData(CUSTOM_VARIANT, getTextVariantID());
    text.setMessage(getTextMessage());// w  w w  .  ja  v  a2s . c o  m
    text.addFocusListener(new FocusListener() {
        @Override
        public void focusLost(FocusEvent e) {
        }

        @Override
        public void focusGained(FocusEvent e) {
            text.selectAll();
        }
    });
    final GridDataFactory gdf = GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, true)
            .span(1, 1);
    final EMFFormsEditSupport editSupport = getEMFFormsEditSupport();
    if (editSupport.isMultiLine(getVElement().getDomainModelReference(),
            getViewModelContext().getDomainModel())) {
        gdf.hint(50, 200);// set x hint to enable wrapping
    }
    gdf.applyTo(text);
    return composite;
}

From source file:org.eclipse.emf.ecp.view.swt.internal.layout.ECPLayoutProvider.java

License:Open Source License

private GridData getControlGridData(int xSpan, VControl vControl, EObject domainModel, Control control) {
    GridDataFactory gdf = GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
            .span(xSpan, 1);/*from w w w .  ja v a  2  s  .c om*/

    if (Text.class.isInstance(control) && vControl.getDomainModelReference() != null) {
        if (isMultiLine(vControl.getDomainModelReference(), domainModel)) {
            gdf = gdf.hint(50, 200); // set x hint to enable wrapping
        }
    }

    return gdf.create();
}

From source file:org.eclipse.emfforms.spi.swt.controlgrid.renderer.ControlGridSWTRenderer.java

License:Open Source License

/**
 * Creates the {@link GridData} which will be set on control which will take a span of 1 column an have no
 * horizontal grab./*  ww w . j av a  2 s  .c  o m*/
 *
 * @param swtGridDescription the {@link SWTGridDescription}
 * @param swtGridCell the current {@link SWTGridCell} of the description
 * @param control the {@link Control}
 * @return the layout data
 * @since 1.8
 */
protected GridData createGridDataForControlWithoutHorizontalGrab(final SWTGridDescription swtGridDescription,
        final SWTGridCell swtGridCell, final Control control) {
    GridData gridData;
    GridDataFactory gridDataFactory = GridDataFactory.fillDefaults().span(1, 1).grab(false, false)
            .align(SWT.FILL, SWT.CENTER);
    if (swtGridDescription.getColumns() == 3 && swtGridCell.getColumn() == 1
            || swtGridDescription.getColumns() == 2 && swtGridCell.getColumn() == 0
                    && !"org_eclipse_emf_ecp_control_label" //$NON-NLS-1$
                            .equals(control.getData("org.eclipse.rap.rwt.customVariant"))) { //$NON-NLS-1$
        // XXX hacky way to make validation labels visible because as stated above min size is
        // not working
        gridDataFactory = gridDataFactory.hint(16, SWT.DEFAULT);
    }
    gridData = gridDataFactory.create();
    return gridData;
}

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;//  w  w  w .jav a2 s .  co m
    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.discovery.wizards.OverviewToolTip.java

License:Open Source License

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

    Composite container = new Composite(parent, SWT.NULL);
    container.setBackground(null);//from w  w w.  jav a2s .c om

    Image image = null;
    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 fixedImageHeight = 240;
    final int fixedImageWidth = 320;
    final int heightHint = fixedImageHeight + (borderWidth * 2);
    final int widthHint = fixedImageWidth;

    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);
        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(null);
    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);

    StyledText summaryLabel = new StyledText(summaryContainer, SWT.WRAP | SWT.READ_ONLY | SWT.NO_FOCUS);
    summaryLabel.setText(summary);
    Point size = summaryLabel.computeSize(widthHint, SWT.DEFAULT);
    if (size.y > heightHint - 20) {
        summaryLabel.dispose();
        summaryLabel = new StyledText(summaryContainer, SWT.WRAP | SWT.READ_ONLY | SWT.NO_FOCUS | SWT.V_SCROLL);
        summaryLabel.setText(summary);
    }
    summaryLabel.setBackground(null);

    GridDataFactory.fillDefaults().grab(true, true).align(SWT.BEGINNING, SWT.BEGINNING).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, fixedImageHeight).indent(borderWidth, borderWidth)
                .applyTo(imageLabel);
        imageLabel.setImage(image);
        imageLabel.setBackground(null);
        imageLabel.setSize(widthHint, fixedImageHeight);

        // creates a border
        imageContainer.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    }
    if (hasLearnMoreLink) {
        Link link = new Link(summaryContainer, SWT.NULL);
        GridDataFactory.fillDefaults().grab(false, false).align(SWT.BEGINNING, SWT.CENTER).applyTo(link);
        link.setText(Messages.ConnectorDescriptorToolTip_detailsLink);
        link.setBackground(null);
        link.setToolTipText(
                NLS.bind(Messages.ConnectorDescriptorToolTip_detailsLink_tooltip, overview.getUrl()));
        link.addSelectionListener(new SelectionListener() {
            public void widgetSelected(SelectionEvent e) {
                WorkbenchUtil.openUrl(overview.getUrl(), IWorkbenchBrowserSupport.AS_EXTERNAL);
            }

            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;
}