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

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

Introduction

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

Prototype

public static void applyDialogFont(Control control) 

Source Link

Document

Applies the dialog font to all controls that currently have the default font.

Usage

From source file:com.nokia.cdt.internal.debug.launch.wizard.MainExecutableSelectionWizardPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new GridLayout(1, false));
    composite.setLayoutData(new GridData());

    final Label exeLabel = new Label(composite, SWT.NONE);
    exeLabel.setText(getAltString("MainExecutableSelectionWizardPage.ExeLabel")); //$NON-NLS-1$
    exeLabel.setToolTipText(getAltString("MainExecutableSelectionWizardPage.ExeToolTip")); //$NON-NLS-1$
    exeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    exeLabel.setData(".uid", "MainExecutableSelectionWizardPage.exeLabel");

    viewer = new ComboViewer(composite, SWT.READ_ONLY);
    Combo combo = viewer.getCombo();/*w  w  w .ja  v a 2 s  .c  o  m*/
    combo.setData(".uid", "MainExecutableCombo"); //$NON-NLS-1$ //$NON-NLS-2$
    combo.setToolTipText(getAltString("MainExecutableSelectionWizardPage.ExeToolTip")); //$NON-NLS-1$
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    combo.setVisibleItemCount(20);
    combo.setData(".uid", "MainExecutableSelectionWizardPage.combo");

    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider());

    viewer.setSorter(new ViewerSorter() {
        public int compare(Viewer viewer, Object o1, Object o2) {
            if (o1.equals(EMULATOR) || o2.equals(BROWSE_ITEM))
                return -1;
            if (o2.equals(EMULATOR) || o1.equals(BROWSE_ITEM))
                return 1;
            if (!asProcessToLaunch) { // put .exe before any other extension, if not as process to launch
                boolean isEXE1 = EXE.equalsIgnoreCase(new Path(o1.toString()).getFileExtension());
                boolean isEXE2 = EXE.equalsIgnoreCase(new Path(o2.toString()).getFileExtension());
                if (isEXE1 != isEXE2) { // if only one is an exe
                    return isEXE1 ? -1 : 1; // return -1 if exe path is .exe, 1 otherwise, sorting .exe paths ahead of anything else
                }
            }

            return o1.toString().compareToIgnoreCase(o2.toString());
        }
    });

    input = new ArrayList<String>(displayStringToExeMmpPair.keySet());

    if (emulatorPath != null) {
        input.add(EMULATOR); //$NON-NLS-1$
        input.add(BROWSE_ITEM);
    }

    if (asProcessToLaunch) {
        Label label = new Label(composite, SWT.NONE);
        label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        label.setText(Messages.getString("MainExecutableSelectionWizardPage.FullPathLabel")); //$NON-NLS-1$
        if (emulatorPath == null)
            label.setVisible(false);
        exePathLabel = new Text(composite, SWT.BORDER | SWT.WRAP | SWT.READ_ONLY);
        exePathLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        exePathLabel.setData(".uid", "MainExecutableSelectionWizardPage.exePathLabel");

        if (emulatorPath == null) {
            exePathLabel.setVisible(false);
            usePathCheck = new Button(composite, SWT.CHECK);
            usePathCheck.setSelection(false);
            usePathCheck.setText(Messages.getString("MainExecutableSelectionWizardPage.UsePathLabel.device")); //$NON-NLS-1$
            usePathCheck.setToolTipText(
                    Messages.getString("MainExecutableSelectionWizardPage.UsePathLabel.device.ToolTip")); //$NON-NLS-1$
            usePathCheck.setData(".uid", "MainExecutableSelectionWizardPage.usePathCheck");

            GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
            gd.verticalIndent = 30;
            usePathCheck.setLayoutData(gd);
            usePathCheck.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (input.isEmpty())
                        usePathCheck.setSelection(true);
                    enableControls(usePathCheck.getSelection());
                }
            });

            pathText = new Text(composite, SWT.BORDER);
            pathText.setEnabled(false);
            pathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            pathText.setToolTipText(
                    Messages.getString("MainExecutableSelectionWizardPage.UsePathLabel.device.ToolTip")); //$NON-NLS-1$
            pathText.addModifyListener(new ModifyListener() {
                public void modifyText(ModifyEvent e) {
                    validatePage();
                }
            });
            pathText.setData(".uid", "MainExecutableSelectionWizardPage.pathText");

            if (input.isEmpty()) {
                usePathCheck.setSelection(true);
                enableControls(true);
            }
        }

        viewer.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                String item = (String) selection.getFirstElement();
                if (item.equals(BROWSE_ITEM)) {
                    FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
                    fileDialog.setText(
                            Messages.getString("MainExecutableSelectionWizardPage.SelectExectuableTitle")); //$NON-NLS-1$
                    BrowseDialogUtils.initializeFrom(fileDialog, emulatorPath);
                    fileDialog.setFilterExtensions(FILTER_EXTS);
                    fileDialog.setFilterNames(FILTER_EXT_NAMES);
                    String pathstr = fileDialog.open();
                    if (pathstr != null) {
                        IPath path = new Path(pathstr);
                        String displayString = path.lastSegment();
                        Pair<IPath, IPath> pair = new Pair<IPath, IPath>(path, null);
                        if (!displayStringToExeMmpPair.values().contains(pair)) {
                            displayStringToExeMmpPair.put(displayString, pair);
                            input.add(displayString);
                            viewer.setInput(input);
                        }
                        item = displayString;
                    } else {
                        // just set selection to first item in combo, if user cancels browse
                        item = viewer.getCombo().getItem(0);
                    }
                    viewer.setSelection(new StructuredSelection(item));
                } else {
                    Pair<IPath, IPath> pair = getSelectedExeMmpPair(item);
                    exePathLabel.setText(pair.first.toOSString());
                    exePathLabel.getParent().layout();
                }
            }
        });

    }

    viewer.setInput(input);
    if (!input.isEmpty()) {
        int index = (emulatorPath != null && combo.getItemCount() > 1 && !useEmulatorByDefault) ? 1 : 0;

        if (index == 1 && defaultExecutable != null) {
            int defaultExeIndex = index = combo.indexOf(defaultExecutable.lastSegment());
            if (defaultExeIndex > 0)
                index = defaultExeIndex;
        }

        combo.select(index);
        if (exePathLabel != null) {
            Pair<IPath, IPath> pair = getSelectedExeMmpPair(combo.getItem(index));
            exePathLabel.setText(pair.first.toOSString());
        }
    }

    setControl(composite);
    Dialog.applyDialogFont(parent);
    validatePage();
}

From source file:com.nokia.cdt.internal.debug.launch.wizard.TRKConnectionWizardPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    composite.setLayout(layout);/*from w  w  w.j  a v a2 s.c  o  m*/

    clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI2(
            RemoteConnectionsActivator.getConnectionTypeProvider().findServiceByID(debugServiceId));
    clientSiteUI.createComposite(composite);
    clientSiteUI.addListener(new IListener() {
        public void connectionSelected() {
            validatePage();
        }
    });

    setControl(composite);
    Dialog.applyDialogFont(parent);
    validatePage();
}

From source file:com.nokia.s60tools.imaker.internal.viewers.IMakerTabsViewer.java

License:Open Source License

/**
 * Creates this viewer's control This area displays the name of the launch
 * configuration currently being edited, as well as a tab folder of tabs
 * that are applicable to the launch configuration.
 *
 * @return the composite used for launch configuration editing
 *//*from  w  w w . jav  a 2  s  .c  o m*/
private void createControl(Composite parent) {
    fViewerControl = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    fViewerControl.setLayout(layout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    fViewerControl.setLayoutData(gd);

    fViewform = new ViewForm(fViewerControl, SWT.FLAT | SWT.BORDER);
    layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    fViewform.setLayout(layout);
    gd = new GridData(GridData.FILL_BOTH);
    fViewform.setLayoutData(gd);
    fViewform.setTopLeft(null);

    Composite mainComp = new Composite(fViewform, SWT.FLAT);
    layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    mainComp.setLayout(layout);
    fViewform.setContent(mainComp);

    Composite comboComp = new Composite(mainComp, SWT.NONE);
    comboComp.setLayout(new GridLayout(3, false));
    comboComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Label fNameLabel = new Label(comboComp, SWT.HORIZONTAL | SWT.LEFT);
    fNameLabel.setText(Messages.getString("IMakerTabsViewer.1"));
    fNameLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));

    fConfigWidget = new Combo(comboComp, SWT.NONE);
    fConfigWidget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fConfigWidget.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent se) {
            try {
                String item = getSelectedItem();
                enabaleReload(item);
                tabPreferences.loadImakerFile(item);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }

        public void widgetDefaultSelected(SelectionEvent se) {
            widgetSelected(se);
        }
    });
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fConfigWidget,
            ImageFlasherHelpContextIDs.IMAKERDIALOG_CONFIGURATION);

    fConfigWidget.setToolTipText(Messages.getString("IMakerTabsViewer.2"));
    deleteButton = new Button(comboComp, SWT.PUSH);
    deleteButton.setText("Delete");
    deleteButton.setEnabled(false);
    deleteButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

    fTabPlaceHolder = new Composite(mainComp, SWT.NONE);
    layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    fTabPlaceHolder.setLayout(layout);
    gd = new GridData(GridData.FILL_BOTH);
    fTabPlaceHolder.setLayoutData(gd);

    createTabFolder(fTabPlaceHolder);

    Composite buttonComp = new Composite(mainComp, SWT.NONE);
    GridLayout buttonCompLayout = new GridLayout();
    buttonCompLayout.numColumns = 2;
    buttonCompLayout.makeColumnsEqualWidth = false;
    buttonComp.setLayout(buttonCompLayout);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    buttonComp.setLayoutData(gd);

    fRestoreButton = new Button(buttonComp, SWT.PUSH);
    fRestoreButton.setText(Messages.getString("IMakerTabsViewer.0")); //$NON-NLS-1$
    fRestoreButton.setToolTipText(Messages.getString("IMakerTabsViewer.11")); //$NON-NLS-1$
    gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
    fRestoreButton.setLayoutData(gd);
    SWTFactory.setButtonWidthHint(fRestoreButton);
    fRestoreButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent evt) {
            handleRestorePressed();
        }
    });

    fReloadButton = new Button(buttonComp, SWT.PUSH);
    fReloadButton.setText(Messages.getString("IMakerTabsViewer.12")); //$NON-NLS-1$
    fReloadButton.setToolTipText(Messages.getString("IMakerTabsViewer.13")); //$NON-NLS-1$
    gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
    fReloadButton.setLayoutData(gd);
    SWTFactory.setButtonWidthHint(fReloadButton);
    fReloadButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent evt) {
            handleReloadPressed();
        }
    });

    Dialog.applyDialogFont(parent);
}

From source file:com.nokia.testfw.codegen.ui.preferences.TESTFWTemplatePreferencePage.java

License:Open Source License

protected Control createContents(Composite ancestor) {
    Composite parent = new Composite(ancestor, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;// w w w . ja  v  a  2 s  .  c om
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);

    Composite innerParent = new Composite(parent, SWT.NONE);
    GridLayout innerLayout = new GridLayout();
    innerLayout.numColumns = 2;
    innerLayout.marginHeight = 0;
    innerLayout.marginWidth = 0;
    innerParent.setLayout(innerLayout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    innerParent.setLayoutData(gd);

    Composite treeComposite = new Composite(innerParent, SWT.NONE);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 360;
    data.heightHint = convertHeightInCharsToPixels(10);
    treeComposite.setLayoutData(data);

    FillLayout treeLayout = new FillLayout();
    treeComposite.setLayout(treeLayout);

    TESTFWTemplateAdapter adapter = new TESTFWTemplateAdapter();

    iTreeViewer = new TreeViewer(treeComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    iTreeViewer.setLabelProvider(new TESTFWTemplateLabelProvider());
    iTreeViewer.setContentProvider(adapter);
    iTreeViewer.addSelectionChangedListener(adapter);
    iTreeViewer.addDoubleClickListener(adapter);

    iTreeViewer.setComparator(new ViewerComparator() {
        public int compare(Viewer viewer, Object object1, Object object2) {
            if ((object1 instanceof PathNode) && (object2 instanceof PathNode)) {
                String leftName = ((PathNode) object1).getName();
                String rightName = ((PathNode) object2).getName();
                int result = Collator.getInstance().compare(leftName, rightName);
                return result;
            }
            return super.compare(viewer, object1, object2);
        }

        public boolean isSorterProperty(Object element, String property) {
            return true;
        }
    });

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

    iAddButton = new Button(buttons, SWT.PUSH);
    iAddButton.setText(Messages.getString("TemplatePreferencePage_new"));
    iAddButton.setLayoutData(new GridData(768));
    iAddButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            add();
        }
    });

    iEditButton = new Button(buttons, SWT.PUSH);
    iEditButton.setText(Messages.getString("TemplatePreferencePage_edit"));
    iEditButton.setLayoutData(new GridData(768));
    iEditButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            edit();
        }
    });

    iRemoveButton = new Button(buttons, SWT.PUSH);
    iRemoveButton.setText(Messages.getString("TemplatePreferencePage_remove"));
    iRemoveButton.setLayoutData(new GridData(768));
    iRemoveButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            remove();
        }
    });

    createSeparator(buttons);

    iRestoreButton = new Button(buttons, SWT.PUSH);
    iRestoreButton.setText(Messages.getString("TemplatePreferencePage_restore"));
    iRestoreButton.setLayoutData(new GridData(768));
    iRestoreButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            restoreDeleted();
        }
    });

    iRevertButton = new Button(buttons, SWT.PUSH);
    iRevertButton.setText(Messages.getString("TemplatePreferencePage_revert"));
    iRevertButton.setLayoutData(new GridData(768));
    iRevertButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            revert();
        }
    });

    createSeparator(buttons);

    iImportButton = new Button(buttons, SWT.PUSH);
    iImportButton.setText(Messages.getString("TemplatePreferencePage_import"));
    iImportButton.setLayoutData(new GridData(768));
    iImportButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            import_();
        }
    });

    iExportButton = new Button(buttons, SWT.PUSH);
    iExportButton.setText(Messages.getString("TemplatePreferencePage_export"));
    iExportButton.setLayoutData(new GridData(768));
    iExportButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            export();
        }
    });

    iPatternViewer = createViewer(parent, 2);

    iTreeViewer.setInput(getTemplateStore());

    updateButtons();
    Dialog.applyDialogFont(parent);
    innerParent.layout();

    return parent;
}

From source file:com.nokia.tools.s60.wizards.PluginInstallationDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    setTitle(WizardMessages.Plugin_Installation_Banner_Title);
    setMessage(WizardMessages.Plugin_Installation_Banner_Message);

    Composite area = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(area, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;/* w w  w.  j  ava  2 s  .c  om*/
    layout.marginHeight = 13;
    layout.marginWidth = 13;
    layout.verticalSpacing = 7;
    composite.setLayout(layout);
    GridData data = new GridData(GridData.FILL_BOTH);
    composite.setLayoutData(data);

    Label label = new Label(composite, SWT.NONE);
    label.setText(WizardMessages.Plugin_Installation_File_Text);

    fileText = new Text(composite, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = 314;
    fileText.setLayoutData(data);
    fileText.addListener(SWT.Modify, this);

    Button browse = new Button(composite, SWT.PUSH);
    initializeDialogUnits(browse);
    setButtonLayoutData(browse);
    browse.setText(WizardMessages.Plugin_Installation_Browse_Text);
    browse.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
            dialog.setFilterExtensions(EXTENSIONS);
            String fileName = dialog.open();
            if (fileName != null) {
                fileText.setText(fileName);
            }
        }
    });

    Composite pluginComposite = new Composite(composite, SWT.NONE);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 3;
    data.minimumHeight = 28;
    data.heightHint = 306;
    pluginComposite.setLayoutData(data);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    pluginComposite.setLayout(layout);
    contentViewer = new PluginContentViewer(pluginComposite);

    Composite sepComposite = new Composite(area, SWT.NONE);
    sepComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridLayout layout3 = new GridLayout();
    sepComposite.setLayout(layout3);
    layout3.numColumns = 1;
    layout3.marginHeight = 0;
    layout3.marginWidth = 0;
    layout3.verticalSpacing = 0;

    final Label separator = new Label(sepComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    separator.setLayoutData(data);

    Dialog.applyDialogFont(composite);

    return composite;
}

From source file:com.nokia.tools.variant.confml.ui.wizards.NewVariantPageOne.java

License:Open Source License

protected void setControl(Control newControl) {
    Dialog.applyDialogFont(newControl);

    // PlatformUI.getWorkbench().getHelpSystem().setHelp(newControl,
    // IJavaHelpContextIds.NEW_JAVAPROJECT_WIZARD_PAGE);

    super.setControl(newControl);
}

From source file:com.opera.widgets.ui.launcher.WidgetTab.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(3, false));
    Label label = new Label(composite, SWT.None);
    label.setText("Widget Emulator path:");
    fPathText = new Text(composite, SWT.BORDER);

    Button browseButton = new Button(composite, SWT.PUSH);
    browseButton.setText("Browse");
    browseButton.addSelectionListener(new SelectionAdapter() {
        @Override//ww w . j av  a 2  s. co m
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog fileDialog = new DirectoryDialog(getShell());
            String fileName = fileDialog.open();
            fPathText.setText(fileName);
            WidgetTab.this.setDirty(true);
            scheduleUpdateJob();
            updateLaunchConfigurationDialog();
        }
    });

    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    fPathText.setLayoutData(gd);
    setControl(composite);
    Dialog.applyDialogFont(composite);
}

From source file:com.palantir.typescript.text.TypeScriptOutlineInformationControl.java

License:Apache License

private Text createFilterText(Composite parent) {
    this.textBox = new Text(parent, SWT.NONE);
    Dialog.applyDialogFont(this.textBox);

    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.CENTER;

    this.textBox.setLayoutData(gridData);

    this.textBox.addKeyListener(new KeyListener() {
        @Override/* w  w w .j  av  a  2 s . co  m*/
        public void keyPressed(KeyEvent keyEvent) {
            switch (keyEvent.keyCode) {
            case SWT.CR:
            case SWT.KEYPAD_CR:
                goToSelectedElement();
                break;
            case SWT.ARROW_DOWN:
            case SWT.ARROW_UP:
                TypeScriptOutlineInformationControl.this.treeViewer.getTree().setFocus();
                break;
            case SWT.ESC:
                dispose();
                break;
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }
    });
    return this.textBox;
}

From source file:com.python.pydev.refactoring.refactorer.search.copied.ReplaceConfigurationPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite result = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    result.setLayout(layout);//from   w w  w .  ja va  2 s  . c om

    Label description = new Label(result, SWT.NONE);
    int numberOfMatches = fReplaceRefactoring.getNumberOfMatches();
    int numberOfFiles = fReplaceRefactoring.getNumberOfFiles();
    String[] arguments = { String.valueOf(numberOfMatches), String.valueOf(numberOfFiles) };
    if (numberOfMatches > 1 && numberOfFiles > 1) {
        description.setText(
                Messages.format(SearchMessages.ReplaceConfigurationPage_description_many_in_many, arguments));
    } else if (numberOfMatches == 1) {
        description.setText(SearchMessages.ReplaceConfigurationPage_description_one_in_one);
    } else {
        description.setText(
                Messages.format(SearchMessages.ReplaceConfigurationPage_description_many_in_one, arguments));
    }
    description.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 2, 1));

    AbstractPythonSearchQuery query = fReplaceRefactoring.getQuery();

    Label label1 = new Label(result, SWT.NONE);
    label1.setText(SearchMessages.ReplaceConfigurationPage_replace_label);

    Text clabel = new Text(result, SWT.BORDER | SWT.READ_ONLY);
    clabel.setText(query.getSearchString());
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = convertWidthInCharsToPixels(50);
    clabel.setLayoutData(gd);

    Label label2 = new Label(result, SWT.NONE);
    label2.setText(SearchMessages.ReplaceConfigurationPage_with_label);

    fTextField = new Combo(result, SWT.DROP_DOWN);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = convertWidthInCharsToPixels(50);
    fTextField.setLayoutData(gd);
    fTextField.setFocus();
    fTextField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            updateOKStatus();
        }
    });

    IDialogSettings settings = PydevPlugin.getDefault().getDialogSettings().getSection(SETTINGS_GROUP);
    if (settings != null) {
        String[] previousReplaceWith = settings.getArray(SETTINGS_REPLACE_WITH);
        if (previousReplaceWith != null) {
            fTextField.setItems(previousReplaceWith);
            fTextField.select(0);
        }
    }

    ComboContentAdapter contentAdapter = new ComboContentAdapter();
    IContentProposalProvider replaceProposer = null;

    //the code below is so that this works in Eclipse 3.3.
    try {
        //new FindReplaceDocumentAdapterContentProposalProvider(false);
        Class<?> class1 = getClass().getClassLoader()
                .loadClass("org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider");
        Constructor<?> constructor = class1.getConstructor(Boolean.class);
        replaceProposer = (IContentProposalProvider) constructor.newInstance(false);
    } catch (Throwable e) {
        //just ignore it if we don't succeed
    }

    try {
        fTextFieldContentAssist = new ContentAssistCommandAdapter(fTextField, contentAdapter, replaceProposer,
                ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[] { '$', '\\' }, true);
    } catch (Throwable e) {
        // Not available in eclipse 3.2
        fTextFieldContentAssist = new ContentAssistCommandAdapter(fTextField, contentAdapter, replaceProposer,
                ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[] { '$', '\\' });
    }

    new Label(result, SWT.NONE);
    fReplaceWithRegex = new Button(result, SWT.CHECK);
    fReplaceWithRegex.setText(SearchMessages.ReplaceConfigurationPage_isRegex_label);
    fReplaceWithRegex.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            setContentAssistsEnablement(fReplaceWithRegex.getSelection());
        }
    });
    if (query.isRegexSearch()) {
        fReplaceWithRegex.setSelection(true);
    } else {
        fReplaceWithRegex.setSelection(false);
        fReplaceWithRegex.setEnabled(false);
    }

    fStatusLabel = new Label(result, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.verticalAlignment = SWT.BOTTOM;
    gd.horizontalSpan = 2;
    fStatusLabel.setLayoutData(gd);

    setContentAssistsEnablement(fReplaceWithRegex.getSelection());

    setControl(result);

    Dialog.applyDialogFont(result);

    PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), ISearchHelpContextIds.REPLACE_DIALOG);
}

From source file:com.python.pydev.refactoring.wizards.rename.PyRenameRefactoringWizard.java

License:Open Source License

protected TextInputWizardPage createInputPage(String message, final String initialSetting) {
    return new TextInputWizardPage(message, true, initialSetting) {
        private Text textField;
        private IFile targetFile;

        @Override//from   w w  w.j  a v a2s .  co m
        protected RefactoringStatus validateTextField(String text) {
            RefactoringStatus status = new RefactoringStatus();
            boolean acceptPoint = fRequest.isModuleRenameRefactoringRequest();
            if (PyStringUtils.isValidIdentifier(text, acceptPoint)) {
                fRequest.setInputName(text);
            } else {
                status.addFatalError("The name: " + text + " is not a valid identifier.");
            }
            return status;
        }

        @Override
        protected Text createTextInputField(Composite parent, int style) {
            Text ret = super.createTextInputField(parent, style);
            this.textField = ret;
            setTextToFullName();
            return ret;
        }

        private void setTextToResourceName() {
            if (targetFile != null) {
                String curr = targetFile.getName();
                textField.setText(curr);
                int i = curr.lastIndexOf('.');

                if (i >= 0) {
                    textField.setSelection(0, i);
                } else {
                    textField.selectAll();
                }
            }
        }

        private void setTextToFullName() {
            textField.setText(initialSetting);

            String text = initialSetting;
            int i = text.lastIndexOf('.');
            if (i >= 0) {
                textField.setSelection(i + 1, text.length());
            } else {
                textField.selectAll();
            }
        }

        @Override
        protected void textModified(String text) {
            if (targetFile != null && fRequest.getSimpleResourceRename()) {
                if (!isEmptyInputValid() && text.equals("")) { //$NON-NLS-1$
                    setPageComplete(false);
                    setErrorMessage(null);
                    restoreMessage();
                    return;
                }
                if ((!isInitialInputValid()) && text.equals(targetFile.getName())) {
                    setPageComplete(false);
                    setErrorMessage(null);
                    restoreMessage();
                    return;
                }

                setPageComplete(validateTextField(text));
            }
            if (fRequest instanceof MultiModuleMoveRefactoringRequest) {
                RefactoringStatus status;
                if (text.length() == 0) {
                    //Accept empty for move!
                    status = new RefactoringStatus();
                    status.addInfo("Empty text: move to source folder");
                } else {
                    status = validateTextField(text);
                }

                if (!status.hasFatalError()) {
                    fRequest.setInputName(text);
                }
                setPageComplete(status);
            } else {
                super.textModified(text);
            }
        }

        public void createControl(Composite parent) {
            Composite superComposite = new Composite(parent, SWT.NONE);
            setControl(superComposite);
            initializeDialogUnits(superComposite);

            superComposite.setLayout(new GridLayout());
            Composite composite = new Composite(superComposite, SWT.NONE);
            composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

            GridLayout layout = new GridLayout();
            layout.numColumns = 2;
            layout.verticalSpacing = 8;
            composite.setLayout(layout);

            Label label = new Label(composite, SWT.NONE);
            label.setText("New &value:");

            Text text = createTextInputField(composite);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.widthHint = convertWidthInCharsToPixels(25);
            text.setLayoutData(gd);

            // layouter.perform(label, text, 1);
            //
            if (fRequest.isModuleRenameRefactoringRequest()) {
                Button updateReferencesButton = addOptionalUpdateReferencesCheckbox(composite);
                IFile targetFile = fRequest.getIFileResource();
                if (targetFile != null) {
                    this.targetFile = targetFile;
                    addResourceRenameCheckbox(composite, updateReferencesButton);
                }
            }
            // addOptionalUpdateTextualMatches(composite, layouter);
            // addOptionalUpdateQualifiedNameComponent(composite, layouter, layout.marginWidth);

            Dialog.applyDialogFont(superComposite);
        }

        protected Button addResourceRenameCheckbox(Composite result, final Button updateReferencesButton) {
            final Button resourceRename = new Button(result, SWT.CHECK);
            resourceRename.setText("&Simple Resource Rename / Change Extension?");

            IPreferenceStore preferences = PydevPrefs.getPreferences();
            preferences.setDefault(SIMPLE_RESOURCE_RENAME, false); //Default is always false to rename resources.
            boolean simpleResourceRenameBool = preferences.getBoolean(SIMPLE_RESOURCE_RENAME);
            resourceRename.setSelection(simpleResourceRenameBool);
            fRequest.setSimpleResourceRename(simpleResourceRenameBool);
            resourceRename.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    IPreferenceStore preferences = PydevPrefs.getPreferences();
                    boolean simpleResourceRenameBool = resourceRename.getSelection();
                    updateReferencesButton.setVisible(!simpleResourceRenameBool);
                    preferences.setValue(SIMPLE_RESOURCE_RENAME, simpleResourceRenameBool);
                    fRequest.setSimpleResourceRename(simpleResourceRenameBool);

                    // Must be the last thing.
                    if (simpleResourceRenameBool) {
                        setTextToResourceName();
                    } else {
                        setTextToFullName();
                    }
                }

            });
            GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
            gridData.horizontalSpan = 2;
            resourceRename.setLayoutData(gridData);
            updateReferencesButton.setVisible(!simpleResourceRenameBool);
            if (simpleResourceRenameBool) {
                setTextToResourceName();
            }
            return resourceRename;
        }

        protected Button addOptionalUpdateReferencesCheckbox(Composite result) {
            final Button updateReferences = new Button(result, SWT.CHECK);
            updateReferences.setText("&Update References?");

            IPreferenceStore preferences = PydevPrefs.getPreferences();
            preferences.setDefault(UPDATE_REFERENCES, true); //Default is always true to update references.
            boolean updateRefs = preferences.getBoolean(UPDATE_REFERENCES);
            updateReferences.setSelection(updateRefs);
            fRequest.setUpdateReferences(updateRefs);
            updateReferences.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    IPreferenceStore preferences = PydevPrefs.getPreferences();
                    boolean updateRefs = updateReferences.getSelection();
                    preferences.setValue(UPDATE_REFERENCES, updateRefs);
                    fRequest.setUpdateReferences(updateRefs);
                }

            });
            GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
            gridData.horizontalSpan = 2;
            updateReferences.setLayoutData(gridData);
            return updateReferences;

        }
    };

}