Example usage for org.eclipse.jface.dialogs IDialogConstants BUTTON_WIDTH

List of usage examples for org.eclipse.jface.dialogs IDialogConstants BUTTON_WIDTH

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IDialogConstants BUTTON_WIDTH.

Prototype

int BUTTON_WIDTH

To view the source code for org.eclipse.jface.dialogs IDialogConstants BUTTON_WIDTH.

Click Source Link

Document

Button width in dialog units (value 61).

Usage

From source file:org.eclipse.common_prefs.exportWizard.CommonPrefsExportPage.java

License:Open Source License

public void createControl(Composite parent) {
    // ======================================
    // Create new composite

    // Set F1 help
    // PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.IMPORT_PROJECT_SET_PAGE);

    Composite inner = new Composite(/*composite*/parent, SWT.NULL);
    inner.setLayoutData(new GridData(SWT.FILL));
    GridLayout layoutInner = new GridLayout(3, false);
    layoutInner.marginHeight = 0;//  w  w w. ja  v a 2 s  . c o  m
    layoutInner.marginWidth = 0;
    inner.setLayout(layoutInner);

    initializeDialogUnits(parent); // Not needed if including composite above
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);

    // ======================================
    // Pref tree group

    Group treeGroup = new Group(inner, SWT.NULL);
    treeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    GridLayout layoutTreeComp = new GridLayout(3, false);
    treeGroup.setLayout(layoutTreeComp);

    // ======================================
    // Filter common preferences

    imFilterCommonButton = new Button(treeGroup, SWT.CHECK);
    imFilterCommonButton.setText("Filter out preferences with value same as in Common Preferences files");
    imFilterCommonButton.setSelection(true);
    GridData gdfcb = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gdfcb.horizontalSpan = 3;
    imFilterCommonButton.setLayoutData(gdfcb);
    imFilterCommonButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            updatePrefTree();
        }
    });

    imFilterDefaultButton = new Button(treeGroup, SWT.CHECK);
    imFilterDefaultButton.setText("Filter out preferences with value same as default value");
    imFilterDefaultButton.setSelection(true);
    GridData gdfdb = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gdfdb.horizontalSpan = 3;
    imFilterDefaultButton.setLayoutData(gdfdb);
    imFilterDefaultButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            updatePrefTree();
        }
    });

    imPrefTree = new Tree(treeGroup, SWT.MULTI | SWT.BORDER | SWT.CHECK);
    GridData gdibst = new GridData(SWT.FILL, SWT.FILL, true, true);
    gdibst.horizontalSpan = 3;
    imPrefTree.setLayoutData(gdibst);
    imPrefTree.setHeaderVisible(true);
    imPrefTree.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            TreeItem item = (TreeItem) event.item;
            boolean isChecked = item.getChecked();

            TreeItem projectNode = CommonPrefsHelper.getPluginNode(item);
            projectNode.setChecked(isChecked);
            updateCheckAllState(isChecked, projectNode);
        }
    });
    imPrefTree.addControlListener(new ControlAdapter() {
        public void controlResized(ControlEvent e) {
            updateTreeSize();
        }
    });

    TreeColumn tc = new TreeColumn(imPrefTree, SWT.LEFT);
    tc.setText("Preference");
    String toolTip = "The preference key. A green icon indicates that value is same as default value or as\n";
    toolTip += "defined in an existing preference file, a red icon indicates the value is different.";
    tc.setToolTipText(toolTip);
    tc.setResizable(true);

    tc = new TreeColumn(imPrefTree, SWT.LEFT);
    tc.setText("Value");
    tc.setToolTipText("The value for the preference.");
    tc.setResizable(true);

    imSelectAllButton = new Button(treeGroup, SWT.PUSH);
    imSelectAllButton.setText("Select All");
    GridData gdsab = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    gdsab.widthHint = Math.max(widthHint, imSelectAllButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    imSelectAllButton.setLayoutData(gdsab);
    imSelectAllButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            updateCheckAllState(true, null);
        }
    });

    imDeselectAllButton = new Button(treeGroup, SWT.PUSH);
    imDeselectAllButton.setText("Deselect All");
    GridData gddsab = new GridData(SWT.LEFT, SWT.CENTER, true, false);
    gddsab.horizontalSpan = 2;
    gddsab.widthHint = Math.max(widthHint, imDeselectAllButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    imDeselectAllButton.setLayoutData(gddsab);
    imDeselectAllButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            updateCheckAllState(false, null);
        }
    });

    // ======================================
    // Browse for save location   

    prefFileLabel = new Label(inner, SWT.LEFT);
    prefFileLabel.setText("To preference file:");
    prefFileLabel.setToolTipText("Specify a file where the selected preferences will be saved.");
    GridData gdpfl = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    prefFileLabel.setLayoutData(gdpfl);

    prefFileCombo = new Combo(inner, SWT.DROP_DOWN);
    GridData gdfc = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gdfc.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
    prefFileCombo.setLayoutData(gdfc);
    prefFileCombo.setItems(CommonPrefsFileHistory.getHistory());
    prefFileCombo.setText(CommonPrefsFileHistory.getSuggestedDefault());
    prefFileCombo.addListener(SWT.Modify, new Listener() {
        public void handleEvent(Event event) {
            updateFinishEnablement();
        }
    });

    prefBrowseButton = new Button(inner, SWT.PUSH);
    prefBrowseButton.setText("Browse..." /*TeamUIMessages.ImportProjectSetMainPage_Browse_3*/);
    GridData gdbb = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    gdbb.widthHint = Math.max(widthHint, prefBrowseButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    prefBrowseButton.setLayoutData(gdbb);
    prefBrowseButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {

            FileDialog fd = new FileDialog(getShell(), SWT.SAVE);
            fd.setText("Please provide a filename for saving the preferences");
            fd.setFilterExtensions(new String[] { "*.epf", "*" }); //$NON-NLS-1$
            fd.setFilterNames(new String[] { "Preference Files (*.epf)", "All Files (*.*)" });

            String fileName = prefFileCombo.getText();
            if (fileName != null && fileName.length() > 0) {
                int separator = fileName.lastIndexOf(File.separatorChar); //$NON-NLS-1$
                if (separator != -1) {
                    fileName = fileName.substring(0, separator);
                }
            } else {
                fileName = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
            }
            fd.setFilterPath(fileName);

            String f = fd.open();
            if (f != null) {
                // Add suffix if missing
                if (!f.endsWith(".epf"))
                    f += ".epf";

                prefFileCombo.setText(f);
                updateFinishEnablement();
            }
        }
    });

    addToCommonPrefsButton = new Button(inner, SWT.CHECK);
    addToCommonPrefsButton.setText("Include the preference file in the Common Preferences list");
    String cpToolTip = "Add the preference file to the list of preferences read at startup.\n";
    cpToolTip += "See also dialog in Windows:Preferences...:General:Common Preferences.";
    addToCommonPrefsButton.setToolTipText(cpToolTip);
    addToCommonPrefsButton.setSelection(false);
    GridData gdfb = new GridData(SWT.LEFT, SWT.CENTER, true, false);
    gdfb.horizontalSpan = 3;
    addToCommonPrefsButton.setLayoutData(gdfb);

    setControl(inner);

    // Initialize the page
    updatePreferencePage();

    Dialog.applyDialogFont(parent);
}

From source file:org.eclipse.common_prefs.preferences.CommonPrefPreferencePage.java

License:Open Source License

protected Control createGeneralPage(Composite parent) {

    // Create the main composite
    Composite prefPage = new Composite(parent, SWT.NONE);
    GridData gdpp = new GridData(SWT.LEFT, SWT.TOP, false, false);
    prefPage.setLayoutData(gdpp);//ww w  .ja  v  a  2  s .c  o m
    GridLayout layout = new GridLayout();
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = 0;
    layout.numColumns = 1;
    prefPage.setLayout(layout);

    initializeDialogUnits(prefPage);

    // Add a label text describing the purpose of the Common Prefs      
    prefGenInfoText = new Label(prefPage, SWT.WRAP);
    prefGenInfoText.setText(getGenInfoText());
    GridData gdcpl = new GridData(SWT.LEFT, SWT.TOP, false, false);
    prefGenInfoText.setLayoutData(gdcpl);

    prefLoadButton = new Button(prefPage, SWT.CHECK);
    prefLoadButton.setText("Enable reading of preference files");
    prefLoadButton.setSelection(getEnbleRead());
    GridData gdlb = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
    gdlb.verticalIndent = 16;
    prefLoadButton.setLayoutData(gdlb);
    prefLoadButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            updateImportEnablement();
        }
    });

    /*      
          // Add a text input for setting timeout for http input
          // TODO: Not completed - need add of column. and property
          Label prefTimeoutLbl = new Label(prefPage, 0);
          prefTimeoutLbl.setText("Timeout for getting http files");
          GridData ptlpl = new GridData(SWT.LEFT, SWT.TOP, false, false);
          prefTimeoutLbl.setLayoutData(ptlpl);
                  
          Text prefTimeoutText = new Text(prefPage, SWT.SINGLE | SWT.LEFT);
          // prefTimeoutText.setText("Enable reading of preference files");
          GridData ptlb = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
          ptlb.verticalIndent = 16;
          prefTimeoutText.setLayoutData(ptlb);
    */

    // ======================================
    // Add a table for editing the pref files      

    // New composite for handling the controls
    Composite inner = new Composite(prefPage, SWT.NULL);
    inner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    GridLayout layoutInner = new GridLayout(3, false);
    layoutInner.marginHeight = 0;
    layoutInner.marginWidth = 0;
    inner.setLayout(layoutInner);

    prefPathTable = new Table(inner, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER /*| SWT.CHECK*/);
    prefPathTable.setHeaderVisible(true);
    GridData gdpt = new GridData(SWT.FILL, SWT.FILL, true, true);
    gdpt.horizontalSpan = 2;
    gdpt.verticalSpan = 6;
    prefPathTable.setLayoutData(gdpt);
    prefPathTable.addControlListener(new ControlAdapter() {
        public void controlResized(ControlEvent e) {
            updateTableSize(prefPathTable);
        }
    });

    prefPathTable.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            /*            
                        Display d = getShell().getDisplay();
                        Point pGlobal = d.getCursorLocation();
                        Point p = d.map(null, prefPathTable, pGlobal);
                                
                        // TODO: Check which column the user clicked in and if in the Type
                        // column, create an editor for that item. Find example in Eclipse.
                        // Now using a separate combobox instead. Not as elegant, but working
            */
            updateImportEnablement();
        }
    });

    new TableColumn(prefPathTable, SWT.NULL);
    new TableColumn(prefPathTable, SWT.NULL);
    TableColumn[] columns = prefPathTable.getColumns();

    columns[0].setResizable(true);
    columns[1].setResizable(true);
    columns[0].setText("Preference files");
    columns[1].setText("Type");

    // ======================================
    // Add buttons   

    prefFileUpButton = new Button(inner, SWT.PUSH);
    prefFileUpButton.setText("Move Up");
    GridData gdub = new GridData(SWT.LEFT, SWT.TOP, false, false);
    int btnWidthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    gdub.widthHint = Math.max(btnWidthHint, prefFileUpButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    prefFileUpButton.setLayoutData(gdub);
    prefFileUpButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            TableItem[] selItems = prefPathTable.getSelection();
            if (selItems == null || selItems.length != 1)
                return;
            CommonPrefEPFResource pfMov = (CommonPrefEPFResource) selItems[0].getData();
            CommonPrefEPFResources prefFiles = StartupPlugin.getDefault().getCommonPrefFiles(null);
            if (prefFiles.movePrefFile(pfMov, false))
                updatePrefFileTable(pfMov);
        }
    });

    prefFileDownButton = new Button(inner, SWT.PUSH);
    prefFileDownButton.setText("Move Down");
    GridData gddb = new GridData(SWT.LEFT, SWT.TOP, false, false);
    gddb.widthHint = Math.max(btnWidthHint, prefFileDownButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    prefFileDownButton.setLayoutData(gddb);
    prefFileDownButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            TableItem[] selItems = prefPathTable.getSelection();
            if (selItems == null || selItems.length != 1)
                return;
            CommonPrefEPFResource pfMov = (CommonPrefEPFResource) selItems[0].getData();
            CommonPrefEPFResources prefFiles = StartupPlugin.getDefault().getCommonPrefFiles(null);
            if (prefFiles.movePrefFile(pfMov, true))
                updatePrefFileTable(pfMov);
        }
    });

    prefFileAddButton = new Button(inner, SWT.PUSH);
    prefFileAddButton.setText("Add...");
    GridData gdab = new GridData(SWT.LEFT, SWT.TOP, false, false);
    gdab.widthHint = Math.max(btnWidthHint, prefFileAddButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    prefFileAddButton.setLayoutData(gdab);
    prefFileAddButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {

            // Get selection
            CommonPrefEPFResource selectedPrefFile = null;
            TableItem[] selItems = prefPathTable.getSelection();
            if (selItems != null && selItems.length == 1)
                selectedPrefFile = (CommonPrefEPFResource) selItems[0].getData();

            // Create and open dialog
            PrefFileDialog pfd = new PrefFileDialog(getShell(), PrefFileDialogType.PREF_FILE_ADD,
                    selectedPrefFile);

            int res = pfd.open();
            if (res != Dialog.OK)
                return;
            CommonPrefEPFResource pf = pfd.getValue();
            updatePrefFileTable(pf);
        }
    });

    prefFileEditButton = new Button(inner, SWT.PUSH);
    prefFileEditButton.setText("Edit...");
    GridData gdeb = new GridData(SWT.LEFT, SWT.TOP, false, false);
    gdeb.widthHint = Math.max(btnWidthHint, prefFileEditButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    prefFileEditButton.setLayoutData(gdeb);
    prefFileEditButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {

            // Get selection
            CommonPrefEPFResource selectedPrefFile = null;
            TableItem[] selItems = prefPathTable.getSelection();
            if (selItems != null && selItems.length == 1)
                selectedPrefFile = (CommonPrefEPFResource) selItems[0].getData();
            if (selectedPrefFile == null)
                return;

            // Create and open dialog
            PrefFileDialog pfd = new PrefFileDialog(getShell(), PrefFileDialogType.PREF_FILE_EDIT,
                    selectedPrefFile);

            int res = pfd.open();
            if (res != Dialog.OK)
                return;
            CommonPrefEPFResource pf = pfd.getValue();
            updatePrefFileTable(pf);
        }
    });

    prefFileRemoveButton = new Button(inner, SWT.PUSH);
    prefFileRemoveButton.setText("Remove");
    GridData gdrb = new GridData(SWT.LEFT, SWT.TOP, false, false);
    gdrb.widthHint = Math.max(btnWidthHint, prefFileRemoveButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    prefFileRemoveButton.setLayoutData(gdrb);
    prefFileRemoveButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {

            TableItem[] selItems = prefPathTable.getSelection();
            if (selItems == null || selItems.length == 0)
                return;

            boolean needUpdate = false;
            CommonPrefEPFResources prefFiles = StartupPlugin.getDefault().getCommonPrefFiles(null);
            for (TableItem item : selItems) {
                CommonPrefEPFResource pf = (CommonPrefEPFResource) item.getData();

                boolean okToRemove = true;
                if (okToRemove && prefFiles.removePrefFile(pf))
                    needUpdate = true;
            }
            if (needUpdate)
                updatePrefFileTable(null);
        }
    });

    prefFileLoadButton = new Button(inner, SWT.PUSH);
    prefFileLoadButton.setText("Load...");
    GridData gdflb = new GridData(SWT.LEFT, SWT.TOP, false, false);
    gdflb.verticalIndent = 16;
    gdflb.widthHint = Math.max(btnWidthHint, prefFileLoadButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    prefFileLoadButton.setLayoutData(gdflb);
    prefFileLoadButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {

            boolean ok = MessageDialog.openQuestion(getShell(), "Load selected preferences?",
                    "This will load the preferences in the selected file.\n\n"
                            + "NOTE: To see changed preferences you might need to reopen\n"
                            + "the preferences dialog.\n\n" + "OK to proceed?");
            if (!ok)
                return;

            TableItem[] selItems = prefPathTable.getSelection();
            if (selItems == null || selItems.length != 1)
                return;

            CommonPrefEPFResource pf = (CommonPrefEPFResource) selItems[0].getData();
            IStatus s = CommonPrefsHelper.loadPreferenceFile(pf, null);
            if (!(s.getSeverity() == IStatus.INFO || s.isOK())) {
                ErrorDialog.openError(getShell(), "Preference Load failed",
                        "One or more errors ocurred when trying to import the selected preferences.", s);
            }
        }
    });

    // ======================================
    // Add combo to set init/force value   

    Label createFileTypeLabel = new Label(inner, SWT.LEFT);
    createFileTypeLabel.setText("Preference File Type: ");
    GridData gdftl = new GridData(SWT.LEFT, SWT.TOP, false, true);
    gdftl.verticalIndent = 2;
    createFileTypeLabel.setLayoutData(gdftl);

    prefFileTypeCombo = new Combo(inner, SWT.DROP_DOWN);
    GridData gdftc = new GridData(SWT.LEFT, SWT.TOP, false, true);
    prefFileTypeCombo.setLayoutData(gdftc);
    prefFileTypeCombo.add("init", INIT_INX);
    prefFileTypeCombo.add("force", FORCE_INX);
    prefFileTypeCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            TableItem[] selItems = prefPathTable.getSelection();
            if (selItems == null || selItems.length != 1)
                return;
            CommonPrefEPFResource pf = (CommonPrefEPFResource) selItems[0].getData();

            // Check if selection is changed
            boolean isForce = (prefFileTypeCombo.getSelectionIndex() == FORCE_INX);
            if (pf.isForce() == isForce)
                return;

            // Update the value of the file
            pf.setIsForce(isForce);
            updatePrefFileTable(pf);
        }
    });

    // Fill in the table
    updatePrefFileTable(null);

    applyDialogFont(prefPage);

    return prefPage;
}

From source file:org.eclipse.compare.examples.xml.SWTUtil.java

License:Open Source License

public static int getButtonWidthHint(Button button) {
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH, button);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}

From source file:org.eclipse.compare.examples.xml.XMLComparePreferencePage.java

License:Open Source License

/**
 * @see PreferencePage#createContents(Composite)
 *///from w w  w  .  ja v a2  s.c o m
protected Control createContents(Composite ancestor) {
    Composite parent = new Composite(ancestor, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);

    //layout the top table & its buttons
    Label label = new Label(parent, SWT.LEFT);
    label.setText(XMLCompareMessages.XMLComparePreference_topTableLabel);
    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    fIdMapsTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    fIdMapsTable.setHeaderVisible(true);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = fIdMapsTable.getItemHeight() * 4;
    fIdMapsTable.setLayoutData(data);
    fIdMapsTable.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            selectionChanged();
        }
    });

    String column2Text = XMLCompareMessages.XMLComparePreference_topTableColumn2;
    String column3Text = XMLCompareMessages.XMLComparePreference_topTableColumn3;
    ColumnLayoutData columnLayouts[] = { new ColumnWeightData(1),
            new ColumnPixelData(convertWidthInCharsToPixels(column2Text.length() + 2), true),
            new ColumnPixelData(convertWidthInCharsToPixels(column3Text.length() + 5), true) };
    TableLayout tablelayout = new TableLayout();
    fIdMapsTable.setLayout(tablelayout);
    for (int i = 0; i < 3; i++)
        tablelayout.addColumnData(columnLayouts[i]);
    TableColumn column = new TableColumn(fIdMapsTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_topTableColumn1);
    column = new TableColumn(fIdMapsTable, SWT.NONE);
    column.setText(column2Text);
    column = new TableColumn(fIdMapsTable, SWT.NONE);
    column.setText(column3Text);

    fillIdMapsTable();

    Composite buttons = new Composite(parent, SWT.NULL);
    buttons.setLayout(new GridLayout());
    data = new GridData();
    data.verticalAlignment = GridData.FILL;
    data.horizontalAlignment = GridData.FILL;
    buttons.setLayoutData(data);

    fAddIdMapButton = new Button(buttons, SWT.PUSH);
    fAddIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topAdd);
    fAddIdMapButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addIdMap(fAddIdMapButton.getShell());
        }
    });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    //data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, fAddIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fAddIdMapButton.setLayoutData(data);

    fRenameIdMapButton = new Button(buttons, SWT.PUSH);
    fRenameIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topRename);
    fRenameIdMapButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            renameIdMap(fRenameIdMapButton.getShell());
        }
    });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    //data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, fAddIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fRenameIdMapButton.setLayoutData(data);

    fRemoveIdMapButton = new Button(buttons, SWT.PUSH);
    fRemoveIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topRemove);
    fRemoveIdMapButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            removeIdMap(fRemoveIdMapButton.getShell());
        }
    });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    //data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, fRemoveIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fRemoveIdMapButton.setLayoutData(data);

    createSpacer(buttons);

    fEditIdMapButton = new Button(buttons, SWT.PUSH);
    fEditIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topEdit);
    fEditIdMapButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            editIdMap(fEditIdMapButton.getShell());
        }
    });
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    //data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, fEditIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    fEditIdMapButton.setLayoutData(data);

    //Spacer
    label = new Label(parent, SWT.LEFT);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    //layout the middle table & its buttons
    label = new Label(parent, SWT.LEFT);
    label.setText(XMLCompareMessages.XMLComparePreference_middleTableLabel);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    fMappingsTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    fMappingsTable.setHeaderVisible(true);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = fMappingsTable.getItemHeight() * 4;
    data.widthHint = convertWidthInCharsToPixels(70);
    fMappingsTable.setLayoutData(data);

    column3Text = XMLCompareMessages.XMLComparePreference_middleTableColumn3;
    String column4Text = XMLCompareMessages.XMLComparePreference_middleTableColumn4;
    columnLayouts = new ColumnLayoutData[] { new ColumnWeightData(10), new ColumnWeightData(18),
            new ColumnPixelData(convertWidthInCharsToPixels(column3Text.length() + 1), true),
            new ColumnPixelData(convertWidthInCharsToPixels(column4Text.length() + 3), true) };
    tablelayout = new TableLayout();
    fMappingsTable.setLayout(tablelayout);
    for (int i = 0; i < 4; i++)
        tablelayout.addColumnData(columnLayouts[i]);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_middleTableColumn1);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_middleTableColumn2);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(column3Text);
    column = new TableColumn(fMappingsTable, SWT.NONE);
    column.setText(column4Text);

    buttons = new Composite(parent, SWT.NULL);
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);

    fNewMappingsButton = new Button(buttons, SWT.PUSH);
    fNewMappingsButton.setLayoutData(getButtonGridData(fNewMappingsButton));
    fNewMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleNew);
    fNewMappingsButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addMapping(fAddIdMapButton.getShell());
        }
    });

    fEditMappingsButton = new Button(buttons, SWT.PUSH);
    fEditMappingsButton.setLayoutData(getButtonGridData(fEditMappingsButton));
    fEditMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleEdit);
    fEditMappingsButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            editMapping(fEditMappingsButton.getShell());
        }
    });

    fRemoveMappingsButton = new Button(buttons, SWT.PUSH);
    fRemoveMappingsButton.setLayoutData(getButtonGridData(fRemoveMappingsButton));
    fRemoveMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleRemove);
    fRemoveMappingsButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            removeMapping(fRemoveMappingsButton.getShell());
        }
    });

    createSpacer(buttons);

    //layout the botton table & its buttons
    label = new Label(parent, SWT.LEFT);
    label.setText(XMLCompareMessages.XMLComparePreference_bottomTableLabel);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    fOrderedTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    fOrderedTable.setHeaderVisible(true);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = fOrderedTable.getItemHeight() * 2;
    data.widthHint = convertWidthInCharsToPixels(70);
    fOrderedTable.setLayoutData(data);

    columnLayouts = new ColumnLayoutData[] { new ColumnWeightData(1), new ColumnWeightData(1) };
    tablelayout = new TableLayout();
    fOrderedTable.setLayout(tablelayout);
    for (int i = 0; i < 2; i++)
        tablelayout.addColumnData(columnLayouts[i]);
    column = new TableColumn(fOrderedTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_bottomTableColumn1);
    column = new TableColumn(fOrderedTable, SWT.NONE);
    column.setText(XMLCompareMessages.XMLComparePreference_bottomTableColumn2);

    buttons = new Composite(parent, SWT.NULL);
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);

    fNewOrderedButton = new Button(buttons, SWT.PUSH);
    fNewOrderedButton.setLayoutData(getButtonGridData(fNewOrderedButton));
    fNewOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomNew);
    fNewOrderedButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addOrdered(fNewOrderedButton.getShell());
        }
    });

    fEditOrderedButton = new Button(buttons, SWT.PUSH);
    fEditOrderedButton.setLayoutData(getButtonGridData(fEditOrderedButton));
    fEditOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomEdit);
    fEditOrderedButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            editOrdered(fEditOrderedButton.getShell());
        }
    });

    fRemoveOrderedButton = new Button(buttons, SWT.PUSH);
    fRemoveOrderedButton.setLayoutData(getButtonGridData(fRemoveOrderedButton));
    fRemoveOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomRemove);
    fRemoveOrderedButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            removeOrdered(fRemoveOrderedButton.getShell());
        }
    });

    createSpacer(buttons);

    fIdMapsTable.setSelection(0);
    fIdMapsTable.setFocus();
    selectionChanged();

    return parent;
}

From source file:org.eclipse.compare.internal.patch.InputPatchPage.java

License:Open Source License

private void buildPatchFileGroup(Composite parent) {

    final Composite composite = new Composite(parent, SWT.NULL);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;/*from   ww w.  j  av  a 2s. co m*/
    composite.setLayout(gridLayout);
    composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // 1st row
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalSpan = 3;
    fUseClipboardButton = new Button(composite, SWT.RADIO);
    fUseClipboardButton.setText(PatchMessages.InputPatchPage_UseClipboardButton_text);
    fUseClipboardButton.setLayoutData(gd);

    // 2nd row
    fUsePatchFileButton = new Button(composite, SWT.RADIO);
    fUsePatchFileButton.setText(PatchMessages.InputPatchPage_FileButton_text);

    fPatchFileNameField = new Combo(composite, SWT.BORDER);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = SIZING_TEXT_FIELD_WIDTH;
    fPatchFileNameField.setLayoutData(gd);

    fPatchFileBrowseButton = new Button(composite, SWT.PUSH);
    fPatchFileBrowseButton.setText(PatchMessages.InputPatchPage_ChooseFileButton_text);
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    Point minSize = fPatchFileBrowseButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    data.widthHint = Math.max(widthHint, minSize.x);
    fPatchFileBrowseButton.setLayoutData(data);

    //3rd row
    fUseURLButton = new Button(composite, SWT.RADIO);
    fUseURLButton.setText(PatchMessages.InputPatchPage_URLButton_text);

    fPatchURLField = new Combo(composite, SWT.BORDER);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fPatchURLField.setLayoutData(gd);

    //4th row
    fUseWorkspaceButton = new Button(composite, SWT.RADIO);
    fUseWorkspaceButton.setText(PatchMessages.InputPatchPage_UseWorkspaceButton_text);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    fUseWorkspaceButton.setLayoutData(gd);

    addWorkspaceControls(parent);

    // Add listeners
    fUseClipboardButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (!fUseClipboardButton.getSelection())
                return;

            clearErrorMessage();
            fShowError = true;
            int state = getInputMethod();
            setEnablePatchFile(state == FILE);
            setEnableURLPatch(state == URL);
            setEnableWorkspacePatch(state == WORKSPACE);
            updateWidgetEnablements();
            fPatchRead = false;
        }
    });

    fUsePatchFileButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (!fUsePatchFileButton.getSelection())
                return;
            //If there is anything typed in at all
            clearErrorMessage();
            fShowError = (fPatchFileNameField.getText() != ""); //$NON-NLS-1$
            int state = getInputMethod();
            setEnablePatchFile(state == FILE);
            setEnableURLPatch(state == URL);
            setEnableWorkspacePatch(state == WORKSPACE);
            updateWidgetEnablements();
            fPatchRead = false;
        }
    });
    fPatchFileNameField.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            updateWidgetEnablements();
        }
    });
    fPatchFileNameField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            clearErrorMessage();
            fShowError = true;
            fPatchRead = false;
            updateWidgetEnablements();
        }
    });
    fPatchFileBrowseButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            clearErrorMessage();
            fShowError = true;
            handlePatchFileBrowseButtonPressed();
            updateWidgetEnablements();
        }
    });
    fUseURLButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            clearErrorMessage();
            fShowError = (fPatchURLField.getText() != ""); //$NON-NLS-1$
            int state = getInputMethod();
            setEnablePatchFile(state == FILE);
            setEnableURLPatch(state == URL);
            setEnableWorkspacePatch(state == WORKSPACE);
            updateWidgetEnablements();
        }
    });
    fPatchURLField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            clearErrorMessage();
            fShowError = true;
            fPatchRead = false;
            updateWidgetEnablements();
        }
    });
    fUseWorkspaceButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (!fUseWorkspaceButton.getSelection())
                return;
            clearErrorMessage();
            // If there is anything typed in at all
            fShowError = (!fTreeViewer.getSelection().isEmpty());
            int state = getInputMethod();
            setEnablePatchFile(state == FILE);
            setEnableURLPatch(state == URL);
            setEnableWorkspacePatch(state == WORKSPACE);
            updateWidgetEnablements();
            fPatchRead = false;
        }
    });

    fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            clearErrorMessage();
            updateWidgetEnablements();
        }
    });

    fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof TreeSelection) {
                TreeSelection treeSel = (TreeSelection) selection;
                Object res = treeSel.getFirstElement();
                if (res != null) {
                    if (res instanceof IProject || res instanceof IFolder) {
                        if (fTreeViewer.getExpandedState(res))
                            fTreeViewer.collapseToLevel(res, 1);
                        else
                            fTreeViewer.expandToLevel(res, 1);
                    } else if (res instanceof IFile)
                        fPatchWizard.showPage(getNextPage());
                }
            }
        }
    });
}

From source file:org.eclipse.compare.internal.patch.PreviewPatchPage2.java

License:Open Source License

private void createFuzzFactorChooser(Composite parent) {
    final WorkspacePatcher patcher = getPatcher();
    Composite pair = new Composite(parent, SWT.NONE);
    GridLayout gl = new GridLayout();
    gl.numColumns = 3;//w  w w  . jav  a2  s . co  m
    gl.marginHeight = gl.marginWidth = 0;
    pair.setLayout(gl);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    pair.setLayoutData(gd);

    Label l = new Label(pair, SWT.NONE);
    l.setText(PatchMessages.PreviewPatchPage_FuzzFactor_text);
    l.setToolTipText(PatchMessages.PreviewPatchPage_FuzzFactor_tooltip);
    gd = new GridData(
            GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.GRAB_HORIZONTAL);
    l.setLayoutData(gd);

    fFuzzField = new Text(pair, SWT.BORDER);
    fFuzzField.setText("0"); //$NON-NLS-1$
    gd = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_END);
    gd.widthHint = 30;
    fFuzzField.setLayoutData(gd);

    Button b = new Button(pair, SWT.PUSH);
    b.setText(PatchMessages.PreviewPatchPage_GuessFuzz_text);
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (promptToRebuild(PatchMessages.PreviewPatchPage2_6)) {
                // Reset the fuzz. We don't use HunkResult.MAXIMUM_FUZZ_FACTOR on purpose here,
                // in order to refresh the tree the result of the calculation needs to be different
                // than the fuzz set in the configuration (see fFuzzField modify listener).
                patcher.setFuzz(-1);
                int fuzz = guessFuzzFactor(patcher);
                if (fuzz >= 0)
                    fFuzzField.setText(Integer.toString(fuzz));
            }
        }
    });
    gd = new GridData(GridData.VERTICAL_ALIGN_CENTER);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    Point minSize = b.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd.widthHint = Math.max(widthHint, minSize.x);
    b.setLayoutData(gd);
}

From source file:org.eclipse.datatools.sqltools.routineeditor.parameter.internal.ParameterTableDialog.java

License:Open Source License

protected void setFillLayoutData(Button button) {
    GridData data = new GridData(GridData.GRAB_HORIZONTAL);
    data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    button.setLayoutData(data);/*from   w  w  w . ja v a  2 s. co  m*/
}

From source file:org.eclipse.debug.internal.ui.sourcelookup.browsers.DirectorySourceContainerDialog.java

License:Open Source License

protected Control createDialogArea(Composite parent) {
    Image image = (fNewContainer) ? DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_ADD_SRC_DIR_WIZ)
            : DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_EDIT_SRC_DIR_WIZ);
    setTitle(SourceLookupUIMessages.DirectorySourceContainerDialog_2);
    setMessage(SourceLookupUIMessages.DirectorySourceContainerDialog_3);
    setTitleImage(image);/*from  w  w  w .java  2  s . com*/
    Composite parentComposite = (Composite) super.createDialogArea(parent);
    Font font = parentComposite.getFont();
    Composite composite = new Composite(parentComposite, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setFont(font);

    Composite dirComposite = new Composite(composite, SWT.NONE);
    layout = new GridLayout(2, false);
    dirComposite.setLayout(layout);
    dirComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    dirComposite.setFont(font);

    Label label = new Label(dirComposite, SWT.NONE);
    label.setText(SourceLookupUIMessages.DirectorySourceContainerDialog_4);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    label.setLayoutData(data);
    label.setFont(font);

    fDirText = new Text(dirComposite, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 1;
    fDirText.setLayoutData(data);
    fDirText.setFont(font);
    fDirText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            validate();
        }
    });

    Button button = new Button(dirComposite, SWT.PUSH);
    button.setText(SourceLookupUIMessages.DirectorySourceContainerDialog_5);
    data = new GridData();
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    data.widthHint = Math.max(widthHint, minSize.x);
    button.setLayoutData(data);
    button.setFont(JFaceResources.getDialogFont());
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browse();
        }
    });

    fSubfoldersButton = new Button(composite, SWT.CHECK);
    fSubfoldersButton.setText(SourceLookupUIMessages.DirectorySourceContainerDialog_6);

    return parentComposite;
}

From source file:org.eclipse.dltk.mod.ui.wizards.WorkingSetConfigurationBlock.java

License:Open Source License

private static int getButtonWidthHint(Button button) {
    button.setFont(JFaceResources.getDialogFont());

    GC gc = new GC(button);
    gc.setFont(button.getFont());//from  w  w  w. j a  va  2  s . com
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
    return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}

From source file:org.eclipse.ecf.internal.example.collab.start.URLListFieldEditor.java

License:Open Source License

private Button createPushButton(Composite parent, String key) {
    Button button = new Button(parent, SWT.PUSH);
    button.setText(JFaceResources.getString(key));
    button.setFont(parent.getFont());/*w ww.  j  av a 2 s . co m*/
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    int widthHint = convertHorizontalDLUsToPixels(button, IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    button.setLayoutData(data);
    button.addSelectionListener(getSelectionListener());
    return button;
}