Example usage for org.eclipse.jface.dialogs Dialog convertHeightInCharsToPixels

List of usage examples for org.eclipse.jface.dialogs Dialog convertHeightInCharsToPixels

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs Dialog convertHeightInCharsToPixels.

Prototype

public static int convertHeightInCharsToPixels(FontMetrics fontMetrics, int chars) 

Source Link

Document

Returns the number of pixels corresponding to the height of the given number of characters.

Usage

From source file:org.eclipse.m2m.internal.qvt.oml.editor.ui.colorer.QVTColorsConfigurationBlock.java

License:Open Source License

/**
 * Returns the number of pixels corresponding to the height of the given number of characters. <p>This method may only be called after <code>initializeDialogUnits</code> has been called.</p> <p>Clients may call this framework method, but should not override it.</p>
 *//*from   w w  w.j a  va 2 s.  co m*/
private int convertHeightInCharsToPixels(int chars) {
    // test for failure to initialize for backward compatibility
    if (fFontMetrics == null) {
        return 0;
    }
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
}

From source file:org.eclipse.mat.ui.internal.browser.QueryBrowserPopup.java

License:Open Source License

protected Control createTitleControl(Composite parent) {
    filterText = new Text(parent, SWT.NONE);

    GC gc = new GC(parent);
    gc.setFont(parent.getFont());//from  w w  w  .  j a v a 2 s . c om
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
            .hint(SWT.DEFAULT, Dialog.convertHeightInCharsToPixels(fontMetrics, 1)).applyTo(filterText);

    filterText.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 0x0D) {
                if ((e.stateMask & SWT.MOD1) != 0)
                    handleSelection(true);
                else if (filterText.getText().length() == 0)
                    handleSelection(false);
                else
                    executeFilterText((e.stateMask & SWT.MOD2) == 0);

                return;
            } else if (e.keyCode == SWT.ARROW_DOWN) {
                int index = table.getSelectionIndex();
                if (index != -1 && table.getItemCount() > index + 1) {
                    table.setSelection(index + 1);
                    updateHelp();
                }
                table.setFocus();
            } else if (e.keyCode == SWT.ARROW_UP) {
                int index = table.getSelectionIndex();
                if (index != -1 && index >= 1) {
                    table.setSelection(index - 1);
                    updateHelp();
                    table.setFocus();
                }
            } else if (e.character == 0x1B) // ESC
                close();
        }

        public void keyReleased(KeyEvent e) {
        }
    });

    filterText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            String text = ((Text) e.widget).getText().toLowerCase();
            refresh(text);
        }
    });

    return filterText;
}

From source file:org.eclipse.mylyn.internal.sandbox.ui.views.ActiveSearchQuickView.java

License:Open Source License

private Text createFilterText(Composite parent) {
    filterText = new Text(parent, SWT.NONE);

    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    GC gc = new GC(parent);
    gc.setFont(parent.getFont());//from   w  ww .j  av a2 s  .  co m
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1);
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.CENTER;
    filterText.setLayoutData(data);

    filterText.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 0x0D) {
                gotoSelectedElement();
            }
            if (e.keyCode == SWT.ARROW_DOWN) {
                viewer.getTree().setFocus();
            }
            if (e.keyCode == SWT.ARROW_UP) {
                viewer.getTree().setFocus();
            }
            if (e.character == 0x1B) {
                dispose();
            }
        }

        public void keyReleased(KeyEvent e) {
            // do nothing
        }
    });

    return filterText;
}

From source file:org.eclipse.mylyn.internal.tasks.ui.editors.outline.QuickOutlineDialog.java

License:Open Source License

private void createUIWidgetFilterText(Composite parent) {
    // Create the widget
    filterText = new Text(parent, SWT.NONE);
    // Set the font 
    GC gc = new GC(parent);
    gc.setFont(parent.getFont());//from w w  w.  j  a v  a  2 s  .  co  m
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    // Create the layout
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1);
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.CENTER;
    filterText.setLayoutData(data);
}

From source file:org.eclipse.tcf.te.ui.forms.CustomFormToolkit.java

License:Open Source License

/**
 * Returns the number of pixels corresponding to the height of the given
 * number of characters.//  w ww  . j av  a2  s  .  com
 * <p>
 * This methods uses the static {@link Dialog#convertHeightInCharsToPixels(org.eclipse.swt.graphics.FontMetrics, int)}
 * method for calculation.
 * <p>
 * @param chars The number of characters
 * @return The corresponding height in pixels
 */
protected int convertHeightInCharsToPixels(Control control, int chars) {
    int height = 0;
    if (control != null && !control.isDisposed()) {
        GC gc = new GC(control);
        gc.setFont(JFaceResources.getDialogFont());
        height = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), chars);
        gc.dispose();
    }

    return height;
}

From source file:org.eclipse.tcf.te.ui.swt.SWTControlUtil.java

License:Open Source License

/**
 * Returns the number of pixels corresponding to the height of the given
 * number of characters.// w w  w . ja  va  2 s. c  om
 * <p>
 * This methods uses the static {@link Dialog#convertHeightInCharsToPixels(org.eclipse.swt.graphics.FontMetrics, int)}
 * method for calculation.
 * <p>
 * @param chars The number of characters
 * @return The corresponding height in pixels
 */
public static int convertHeightInCharsToPixels(Control control, int chars) {
    int height = 0;
    if (control != null && !control.isDisposed()) {
        GC gc = new GC(control);
        gc.setFont(JFaceResources.getDialogFont());
        height = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), chars);
        gc.dispose();
    }

    return height;
}

From source file:org.eclipse.tm.terminal.view.ui.preferences.PreferencePage.java

License:Open Source License

@Override
protected Control createContents(final Composite parent) {
    final GC gc = new GC(parent);
    gc.setFont(JFaceResources.getDialogFont());

    Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new GridLayout());
    GridData layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    panel.setLayoutData(layoutData);//ww w.j  av a  2 s .co  m

    Label label = new Label(panel, SWT.HORIZONTAL);
    label.setText(Messages.PreferencePage_label);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    if (!Platform.OS_WIN32.equals(Platform.getOS())) {
        Group group = new Group(panel, SWT.NONE);
        group.setText(Messages.PreferencePage_command_label);
        group.setLayout(new GridLayout(2, false));
        group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

        command = new Text(group, SWT.SINGLE | SWT.BORDER);
        command.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        command.addModifyListener(new ModifyListener() {
            @Override
            public void modifyText(ModifyEvent e) {
                boolean valid = true;
                String message = null;

                String text = command.getText();
                if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$
                    IPath p = new Path(text.trim());
                    valid = p.toFile().isFile() && p.toFile().canRead() && p.toFile().canExecute();
                    if (!valid)
                        message = Messages.PreferencePage_command_invalid;
                }

                setValid(valid);
                setErrorMessage(message);
            }
        });

        commandBrowseButton = new Button(group, SWT.PUSH);
        commandBrowseButton.setText(Messages.PreferencePage_command_button_browse);
        layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false);
        layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 14);
        commandBrowseButton.setLayoutData(layoutData);
        commandBrowseButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                FileDialog dialog = new FileDialog(parent.getShell(), SWT.OPEN);

                String text = command.getText();
                if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$
                    IPath p = new Path(text);

                    if (p.toFile().isFile() || !p.toFile().exists()) {
                        dialog.setFilterPath(p.removeLastSegments(1).toOSString());
                        dialog.setFileName(p.lastSegment());
                    } else if (p.toFile().isDirectory()) {
                        dialog.setFilterPath(p.toOSString());
                    }
                }

                String selected = dialog.open();
                if (selected != null) {
                    IPath sp = new Path(selected);
                    command.setText(sp.toOSString());
                }
            }
        });

        String cmd = UIPlugin.getScopedPreferences()
                .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX);
        if (cmd != null && !"".equals(cmd)) { //$NON-NLS-1$
            command.setText(new Path(cmd).toOSString());
        }

        Composite argsPanel = new Composite(group, SWT.NONE);
        GridLayout layout = new GridLayout(2, false);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        argsPanel.setLayout(layout);
        layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
        layoutData.horizontalSpan = 2;
        argsPanel.setLayoutData(layoutData);

        label = new Label(argsPanel, SWT.NONE);
        label.setText(Messages.PreferencePage_command_arguments_label);

        arguments = new Text(argsPanel, SWT.SINGLE | SWT.BORDER);
        arguments.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

        String args = UIPlugin.getScopedPreferences()
                .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS);
        if (args != null && !"".equals(args)) { //$NON-NLS-1$
            arguments.setText(args);
        }

        NoteCompositeHelper.createNoteComposite(group.getFont(), group,
                Messages.PreferencePage_command_note_label, Messages.PreferencePage_command_note_text);
    }

    Group group = new Group(panel, SWT.NONE);
    group.setText(Messages.PreferencePage_workingDir_label);
    group.setLayout(new GridLayout(hasVariablesButton ? 3 : 2, false));
    group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    workingDir = new Combo(group, SWT.DROP_DOWN);
    Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
    if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) {
        workingDir.setItems(new String[] { Messages.PreferencePage_workingDir_userhome_label,
                Messages.PreferencePage_workingDir_eclipsehome_label,
                Messages.PreferencePage_workingDir_eclipsews_label });
    } else {
        workingDir.setItems(new String[] { Messages.PreferencePage_workingDir_userhome_label,
                Messages.PreferencePage_workingDir_eclipsehome_label });
    }
    workingDir.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    workingDir.select(0);
    workingDir.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            boolean valid = true;
            String message = null;

            String text = workingDir.getText();
            if (text != null && !"".equals(text.trim()) //$NON-NLS-1$
                    && !Messages.PreferencePage_workingDir_userhome_label.equals(text)
                    && !Messages.PreferencePage_workingDir_eclipsehome_label.equals(text)
                    && !Messages.PreferencePage_workingDir_eclipsews_label.equals(text)) {
                try {
                    // Resolve possible dynamic variables
                    IStringVariableManager vm = VariablesPlugin.getDefault().getStringVariableManager();
                    String resolved = vm.performStringSubstitution(text.trim());

                    IPath p = new Path(resolved);
                    valid = p.toFile().canRead() && p.toFile().isDirectory();
                    if (!valid)
                        message = Messages.PreferencePage_workingDir_invalid;
                } catch (CoreException ex) {
                    valid = false;
                    message = ex.getLocalizedMessage();
                }
            }

            setValid(valid);
            setErrorMessage(message);
        }
    });

    browseButton = new Button(group, SWT.PUSH);
    browseButton.setText(Messages.PreferencePage_workingDir_button_browse);
    layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false);
    layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 14);
    browseButton.setLayoutData(layoutData);
    browseButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IPath uh = null;
            IPath eh = null;
            IPath ew = null;

            // HOME
            String home = System.getProperty("user.home"); //$NON-NLS-1$
            if (home != null && !"".equals(home)) //$NON-NLS-1$
                uh = new Path(home);

            // ECLIPSE_HOME
            String eclipseHomeLocation = System.getProperty("eclipse.home.location"); //$NON-NLS-1$
            if (eclipseHomeLocation != null) {
                try {
                    URI uri = URIUtil.fromString(eclipseHomeLocation);
                    File f = URIUtil.toFile(uri);
                    eh = new Path(f.getAbsolutePath());
                } catch (URISyntaxException ex) {
                    /* ignored on purpose */ }
            }

            // ECLIPSE_WORKSPACE
            Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
            if (bundle != null && bundle.getState() != Bundle.UNINSTALLED
                    && bundle.getState() != Bundle.STOPPING) {
                if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null
                        && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null
                        && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot()
                                .getLocation() != null) {
                    ew = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation();
                }
            }

            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.OPEN);

            // Determine the filter path
            String text = workingDir.getText();
            if (Messages.PreferencePage_workingDir_userhome_label.equals(text)) {
                dialog.setFilterPath(uh.toOSString());
            } else if (Messages.PreferencePage_workingDir_eclipsehome_label.equals(text)) {
                dialog.setFilterPath(eh.toOSString());
            } else if (Messages.PreferencePage_workingDir_eclipsews_label.equals(text)) {
                dialog.setFilterPath(ew.toOSString());
            } else if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$
                try {
                    // Resolve possible dynamic variables
                    IStringVariableManager vm = VariablesPlugin.getDefault().getStringVariableManager();
                    String resolved = vm.performStringSubstitution(text.trim());
                    dialog.setFilterPath(resolved);
                } catch (CoreException ex) {
                    if (Platform.inDebugMode()) {
                        UIPlugin.getDefault().getLog().log(ex.getStatus());
                    }
                }
            }

            String selected = dialog.open();
            if (selected != null) {
                IPath sp = new Path(selected);

                if (uh.equals(sp)) {
                    workingDir.select(0);
                } else if (eh.equals(sp)) {
                    workingDir.select(1);
                } else if (ew.equals(sp)) {
                    workingDir.select(2);
                } else {
                    workingDir.setText(sp.toOSString());
                }
            }
        }
    });

    if (hasVariablesButton) {
        variablesButton = new Button(group, SWT.PUSH);
        variablesButton.setText(Messages.PreferencePage_workingDir_button_variables);
        layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false);
        layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 14);
        variablesButton.setLayoutData(layoutData);
        variablesButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                org.eclipse.debug.ui.StringVariableSelectionDialog dialog = new org.eclipse.debug.ui.StringVariableSelectionDialog(
                        getShell());
                dialog.open();
                String expression = dialog.getVariableExpression();
                if (expression != null) {
                    if ("${eclipse_home}".equals(expression)) { //$NON-NLS-1$
                        workingDir.select(1);
                    } else if ("${workspace_loc}".equals(expression)) { //$NON-NLS-1$
                        workingDir.select(2);
                    } else {
                        workingDir.setText(expression);
                    }
                }
            }
        });
    }

    String initialCwd = UIPlugin.getScopedPreferences()
            .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD);
    if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd)
            || "".equals(initialCwd.trim())) { //$NON-NLS-1$
        workingDir.select(0);
    } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME.equals(initialCwd)
            || "${eclipse_home}".equals(initialCwd)) { //$NON-NLS-1$
        workingDir.select(1);
    } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS.equals(initialCwd)
            || "${workspace_loc}".equals(initialCwd)) { //$NON-NLS-1$
        workingDir.select(2);
    } else {
        workingDir.setText(new Path(initialCwd).toOSString());
    }

    NoteCompositeHelper.createNoteComposite(group.getFont(), group,
            Messages.PreferencePage_workingDir_note_label, Messages.PreferencePage_workingDir_note_text);

    group = new Group(panel, SWT.NONE);
    group.setText(Messages.PreferencePage_executables_label);
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    viewer = new TableViewer(group, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);

    Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    TableColumn column = new TableColumn(table, SWT.LEFT);
    column.setText(Messages.PreferencePage_executables_column_name_label);
    column = new TableColumn(table, SWT.LEFT);
    column.setText(Messages.PreferencePage_executables_column_path_label);

    ColumnViewerToolTipSupport.enableFor(viewer);

    TableLayout tableLayout = new TableLayout();
    tableLayout.addColumnData(new ColumnWeightData(35));
    tableLayout.addColumnData(new ColumnWeightData(65));
    table.setLayout(tableLayout);

    layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.heightHint = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 10);
    table.setLayoutData(layoutData);

    Composite buttonsPanel = new Composite(group, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttonsPanel.setLayout(layout);
    buttonsPanel.setLayoutData(new GridData(SWT.LEAD, SWT.BEGINNING, false, false));

    addButton = new Button(buttonsPanel, SWT.PUSH);
    addButton.setText(Messages.PreferencePage_executables_button_add_label);
    layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false);
    layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 10);
    addButton.setLayoutData(layoutData);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            ExternalExecutablesDialog dialog = new ExternalExecutablesDialog(PreferencePage.this.getShell(),
                    false);
            if (dialog.open() == Window.OK) {
                // Get the executable properties and add it to the the list
                Map<String, String> executableData = dialog.getExecutableData();
                if (executableData != null && !executables.contains(executableData)) {
                    executables.add(executableData);
                    viewer.refresh();
                }
            }
        }
    });

    editButton = new Button(buttonsPanel, SWT.PUSH);
    editButton.setText(Messages.PreferencePage_executables_button_edit_label);
    layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 10);
    editButton.setLayoutData(layoutData);
    editButton.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection s = viewer.getSelection();
            if (s instanceof IStructuredSelection && !s.isEmpty()) {
                Object element = ((IStructuredSelection) s).getFirstElement();
                if (element instanceof Map) {
                    final Map<String, String> m = (Map<String, String>) element;
                    ExternalExecutablesDialog dialog = new ExternalExecutablesDialog(
                            PreferencePage.this.getShell(), true);
                    dialog.setExecutableData(m);
                    if (dialog.open() == Window.OK) {
                        Map<String, String> executableData = dialog.getExecutableData();
                        if (executableData != null) {
                            m.clear();
                            m.putAll(executableData);
                            viewer.refresh();
                        }
                    }
                }
            }
        }
    });

    removeButton = new Button(buttonsPanel, SWT.PUSH);
    removeButton.setText(Messages.PreferencePage_executables_button_remove_label);
    layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 10);
    removeButton.setLayoutData(layoutData);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection s = viewer.getSelection();
            if (s instanceof IStructuredSelection && !s.isEmpty()) {
                Iterator<?> iterator = ((IStructuredSelection) s).iterator();
                while (iterator.hasNext()) {
                    Object element = iterator.next();
                    if (element instanceof Map) {
                        Map<String, Object> m = (Map<String, Object>) element;
                        executables.remove(m);
                    }
                    viewer.refresh();
                }
            }
        }
    });

    viewer.setContentProvider(new IStructuredContentProvider() {
        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof List && !((List<?>) inputElement).isEmpty()) {
                return ((List<?>) inputElement).toArray();
            }
            return NO_ELEMENTS;
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }
    });

    viewer.setLabelProvider(new ITableLabelProvider() {
        @SuppressWarnings("unchecked")
        @Override
        public String getColumnText(Object element, int columnIndex) {
            if (element instanceof Map) {
                Map<String, Object> m = (Map<String, Object>) element;

                switch (columnIndex) {
                case 0:
                    return (String) m.get(IExternalExecutablesProperties.PROP_NAME);
                case 1:
                    return (String) m.get(IExternalExecutablesProperties.PROP_PATH);
                }
            }
            return null;
        }

        @SuppressWarnings("unchecked")
        @Override
        public Image getColumnImage(Object element, int columnIndex) {
            Image i = null;

            if (element instanceof Map) {
                switch (columnIndex) {
                case 0:
                    Map<String, Object> m = (Map<String, Object>) element;
                    String icon = (String) m.get(IExternalExecutablesProperties.PROP_ICON);
                    if (icon != null) {
                        i = images.get(icon);
                        if (i == null) {
                            ImageData id = ExternalExecutablesManager.loadImage(icon);
                            if (id != null) {
                                ImageDescriptor d = ImageDescriptor.createFromImageData(id);
                                if (d != null)
                                    i = d.createImage();
                                if (i != null)
                                    images.put(icon, i);
                            }
                        }
                    }
                    break;
                case 1:
                    break;
                }
            }

            return i;
        }

        @Override
        public void removeListener(ILabelProviderListener listener) {
        }

        @Override
        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        @Override
        public void dispose() {
        }

        @Override
        public void addListener(ILabelProviderListener listener) {
        }
    });

    List<Map<String, String>> l = ExternalExecutablesManager.load();
    if (l != null)
        executables.addAll(l);

    viewer.setInput(executables);

    viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateButtons();
        }
    });

    updateButtons();

    gc.dispose();

    return panel;
}

From source file:org.eclipse.ui.internal.activities.ws.ActivityEnabler.java

License:Open Source License

/**
 * Create the controls.//from www .j  a va 2 s  . co  m
 * 
 * @param parent
 *            the parent in which to create the controls.
 * @return the composite in which the controls exist.
 */
public Control createControl(Composite parent) {
    GC gc = new GC(parent);
    gc.setFont(JFaceResources.getDialogFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(createGridLayoutWithoutMargins(1, fontMetrics));

    new Label(composite, SWT.NONE).setText(strings.getProperty(ActivitiesPreferencePage.ACTIVITY_NAME,
            ActivityMessages.ActivityEnabler_activities) + ':');

    dualViewer = new CheckboxTreeViewer(composite);
    dualViewer.setComparator(new ViewerComparator());
    dualViewer.setLabelProvider(new ActivityCategoryLabelProvider());
    dualViewer.setContentProvider(provider);
    dualViewer.setInput(activitySupport);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    dualViewer.getControl().setLayoutData(data);

    Composite buttonComposite = new Composite(composite, SWT.NONE);
    buttonComposite.setLayout(createGridLayoutWithoutMargins(2, fontMetrics));

    Button selectAllButton = new Button(buttonComposite, SWT.PUSH);
    selectAllButton.setText(ActivityMessages.ActivityEnabler_selectAll);
    selectAllButton.addSelectionListener(new SelectionAdapter() {
        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public void widgetSelected(SelectionEvent e) {
            toggleTreeEnablement(true);
        }
    });
    setButtonLayoutData(selectAllButton, fontMetrics);

    Button deselectAllButton = new Button(buttonComposite, SWT.PUSH);
    deselectAllButton.setText(ActivityMessages.ActivityEnabler_deselectAll);
    deselectAllButton.addSelectionListener(new SelectionAdapter() {
        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        public void widgetSelected(SelectionEvent e) {
            toggleTreeEnablement(false);
        }
    });
    setButtonLayoutData(deselectAllButton, fontMetrics);

    new Label(composite, SWT.NONE).setText(ActivityMessages.ActivityEnabler_description);

    descriptionText = new Text(composite, SWT.READ_ONLY | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
    data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 5);
    descriptionText.setLayoutData(data);
    setInitialStates();

    dualViewer.addCheckStateListener(checkListener);
    dualViewer.addSelectionChangedListener(selectionListener);

    dualViewer.setSelection(new StructuredSelection());

    Dialog.applyDialogFont(composite);

    return composite;
}

From source file:org.eclipse.ui.internal.dialogs.GlobalizationPreferencePage.java

License:Open Source License

private static void createSpace(Composite parent) {
    Label vfiller = new Label(parent, SWT.LEFT);
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;/* www.  j a  va  2 s .  c  o  m*/

    GC gc = new GC(parent);
    gridData.heightHint = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 1) / 2;
    gc.dispose();

    vfiller.setLayoutData(gridData);
}

From source file:org.eclipse.wst.sse.ui.internal.preferences.ui.TextHoverPreferenceTab.java

License:Open Source License

public Control createContents(Composite tabFolder) {
    Composite hoverComposite = new Composite(tabFolder, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;/*ww  w  . ja va 2s  .co m*/
    hoverComposite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    hoverComposite.setLayoutData(gd);

    // commented out until these preferences are actually handled in some
    // way
    //      String rollOverLabel=
    // ResourceHandler.getString("TextHoverPreferenceTab.annotationRollover");
    // //$NON-NLS-1$
    //      addCheckBox(hoverComposite, rollOverLabel,
    // CommonEditorPreferenceNames.EDITOR_ANNOTATION_ROLL_OVER, 0);
    //
    //      // Affordance checkbox
    //      String showAffordanceLabel =
    // ResourceHandler.getString("TextHoverPreferenceTab.showAffordance");
    // //$NON-NLS-1$
    //      addCheckBox(hoverComposite, showAffordanceLabel,
    // CommonEditorPreferenceNames.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE, 0);

    Label label = new Label(hoverComposite, SWT.NONE);
    label.setText(SSEUIMessages.TextHoverPreferenceTab_hoverPreferences); //$NON-NLS-1$
    gd = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
    gd.horizontalAlignment = GridData.BEGINNING;
    label.setLayoutData(gd);

    fHoverTableViewer = CheckboxTableViewer.newCheckList(hoverComposite,
            SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
    // Hover table
    fHoverTable = fHoverTableViewer.getTable();
    fHoverTable.setHeaderVisible(true);
    fHoverTable.setLinesVisible(true);

    gd = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=104507
    GC gc = new GC(fHoverTable);
    gc.setFont(fHoverTable.getFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    int heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 7);
    gd.heightHint = heightHint;

    fHoverTable.setLayoutData(gd);

    TableLayout tableLayout = new TableLayout();
    tableLayout.addColumnData(new ColumnWeightData(1, 140, true));
    tableLayout.addColumnData(new ColumnWeightData(1, 140, true));
    fHoverTable.setLayout(tableLayout);

    fHoverTable.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            handleHoverListSelection();
        }
    });

    fNameColumn = new TableColumn(fHoverTable, SWT.NONE);
    fNameColumn.setText(SSEUIMessages.TextHoverPreferenceTab_nameColumnTitle); //$NON-NLS-1$
    fNameColumn.setResizable(true);

    fModifierColumn = new TableColumn(fHoverTable, SWT.NONE);
    fModifierColumn.setText(SSEUIMessages.TextHoverPreferenceTab_modifierColumnTitle); //$NON-NLS-1$
    fModifierColumn.setResizable(true);

    fHoverTableViewer.setUseHashlookup(true);
    fHoverTableViewer.setContentProvider(new ArrayContentProvider());
    fHoverTableViewer.setLabelProvider(new InternalTableLabelProvider());
    ((CheckboxTableViewer) fHoverTableViewer).addCheckStateListener(new ICheckStateListener() {
        /*
         * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
         */
        public void checkStateChanged(CheckStateChangedEvent event) {
            String id = ((TextHoverDescriptor) event.getElement()).getId();
            if (id == null)
                return;

            TextHoverManager.TextHoverDescriptor[] descriptors = getTextHoverManager().getTextHovers();
            TextHoverManager.TextHoverDescriptor hoverConfig = null;
            int i = 0, length = fTextHovers.length;
            while (i < length) {
                if (id.equals(descriptors[i].getId())) {
                    hoverConfig = fTextHovers[i];
                    hoverConfig.setEnabled(event.getChecked());
                    fModifierEditor.setEnabled(event.getChecked());
                    fHoverTableViewer.setSelection(new StructuredSelection(descriptors[i]));
                }
                i++;
            }

            handleHoverListSelection();
            updateStatus(hoverConfig);
        }
    });

    // Text field for modifier string
    label = new Label(hoverComposite, SWT.LEFT);
    label.setText(SSEUIMessages.TextHoverPreferenceTab_keyModifier); //$NON-NLS-1$
    fModifierEditor = new Text(hoverComposite, SWT.BORDER);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    fModifierEditor.setLayoutData(gd);

    fModifierEditor.addKeyListener(new KeyListener() {
        private boolean isModifierCandidate;

        public void keyPressed(KeyEvent e) {
            isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
        }

        public void keyReleased(KeyEvent e) {
            if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {// &&
                // e.time
                // -time
                // <
                // 1000)
                // {
                String text = fModifierEditor.getText();
                Point selection = fModifierEditor.getSelection();
                int i = selection.x - 1;
                while (i > -1 && Character.isWhitespace(text.charAt(i))) {
                    i--;
                }
                boolean needsPrefixDelimiter = i > -1 && !String.valueOf(text.charAt(i)).equals(DELIMITER);

                i = selection.y;
                while (i < text.length() && Character.isWhitespace(text.charAt(i))) {
                    i++;
                }
                boolean needsPostfixDelimiter = i < text.length()
                        && !String.valueOf(text.charAt(i)).equals(DELIMITER);

                String insertString;

                if (needsPrefixDelimiter && needsPostfixDelimiter)
                    insertString = NLS.bind(
                            SSEUIMessages.TextHoverPreferenceTab_insertDelimiterAndModifierAndDelimiter,
                            new String[] { Action.findModifierString(e.stateMask) });
                else if (needsPrefixDelimiter)
                    insertString = NLS.bind(SSEUIMessages.TextHoverPreferenceTab_insertDelimiterAndModifier,
                            new String[] { Action.findModifierString(e.stateMask) });
                else if (needsPostfixDelimiter)
                    insertString = NLS.bind(SSEUIMessages.TextHoverPreferenceTab_insertModifierAndDelimiter,
                            new String[] { Action.findModifierString(e.stateMask) });
                else
                    insertString = Action.findModifierString(e.stateMask);

                if (insertString != null)
                    fModifierEditor.insert(insertString);
            }
        }
    });

    fModifierEditor.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            handleModifierModified();
        }
    });

    // Description
    Label descriptionLabel = new Label(hoverComposite, SWT.LEFT);
    descriptionLabel.setText(SSEUIMessages.TextHoverPreferenceTab_description); //$NON-NLS-1$
    gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    gd.horizontalSpan = 2;
    descriptionLabel.setLayoutData(gd);
    fDescription = new Text(hoverComposite, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd.horizontalSpan = 2;
    fDescription.setLayoutData(gd);

    initialize();

    Dialog.applyDialogFont(hoverComposite);

    PlatformUI.getWorkbench().getHelpSystem().setHelp(hoverComposite, IHelpContextIds.PREFSTE_HOVERS_HELPID);
    return hoverComposite;
}