List of usage examples for org.eclipse.jface.preference StringButtonFieldEditor StringButtonFieldEditor
protected StringButtonFieldEditor(String name, String labelText, Composite parent)
From source file:com.aptana.ide.core.ui.preferences.ExportPreferencesPreferencePage.java
License:Open Source License
/** * Creates the field editors. Field editors are abstractions of the common GUI blocks needed to manipulate various * types of preferences. Each field editor knows how to save and restore itself. *//* w w w . ja va 2 s . c o m*/ public void createFieldEditors() { final Composite c = getFieldEditorParent(); final BooleanFieldEditor booleanFieldEditor = new BooleanFieldEditor( IPreferenceConstants.PREF_AUTO_BACKUP_ENABLED, Messages.ExportPreferencesPreferencePage_BACKUP_TITLE, c); checkBox = (Button) c.getChildren()[0]; addField(booleanFieldEditor); stringButtonFieldEditor = new StringButtonFieldEditor(IPreferenceConstants.PREF_AUTO_BACKUP_PATH, Messages.ExportPreferencesPreferencePage_PATH, c) { protected String changePressed() { DirectoryDialog dlg = new DirectoryDialog(getShell(), SWT.SAVE); dlg.setFilterPath(stringButtonFieldEditor.getStringValue()); dlg.setText(Messages.ExportPreferencesPreferencePage_CHOOSE_CONTAINER); String open = dlg.open(); return open; } }; stringButtonFieldEditor.getTextControl(c).setEditable(false); addField(stringButtonFieldEditor); GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); data.widthHint = 150; stringButtonFieldEditor.getTextControl(c).setLayoutData(data); String string = CoreUIPlugin.getDefault().getPreferenceStore() .getString(IPreferenceConstants.PREF_AUTO_BACKUP_LASTNAME); String lastBackup = StringUtils.format(Messages.ExportPreferencesPreferencePage_LAST_BACKUP, string); if (string.length() == 0) { lastBackup = Messages.ExportPreferencesPreferencePage_NONE; } Label lastBacked = new Label(c, SWT.NONE); lastBacked.setText(Messages.ExportPreferencesPreferencePage_LASTBACKED); Text lastBackedLabel = new Text(c, SWT.READ_ONLY | SWT.BORDER | SWT.SINGLE); lastBackedLabel.setEditable(false); lastBackedLabel.setText(lastBackup); data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1); data.widthHint = 150; lastBackedLabel.setLayoutData(data); Label cm = new Label(c, SWT.NONE); cm.setText(Messages.ExportPreferencesPreferencePage_LAST); lastRestore = new Text(c, SWT.READ_ONLY | SWT.BORDER | SWT.SINGLE); lastRestore.setEditable(false); data = new GridData(SWT.FILL, SWT.FILL, true, false); data.widthHint = 150; lastRestore.setLayoutData(data); checkBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { stringButtonFieldEditor.setEnabled(checkBox.getSelection(), c); } }); Button restore = new Button(c, SWT.PUSH); restore.setText(Messages.ExportPreferencesPreferencePage_RESTORE_TITLE); restore.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileDialog dlg = new FileDialog(getShell(), SWT.OPEN); dlg.setFilterPath(stringButtonFieldEditor.getStringValue()); dlg.setFilterExtensions(new String[] { "*.epr" }); //$NON-NLS-1$ dlg.setText(Messages.ExportPreferencesPreferencePage_RESTORE_TEXT); String open = dlg.open(); if (open != null) { long l = System.currentTimeMillis(); File file = new File(open); boolean importPreferences = PlatformValidatorPatcher.importPreferences(file); if (importPreferences) { CoreUIPlugin.getDefault().getPreferenceStore() .setValue(IPreferenceConstants.PREF_AUTO_BACKUP_LASTRESTORE_NAME, file.getName()); CoreUIPlugin.getDefault().getPreferenceStore() .setValue(IPreferenceConstants.PREF_AUTO_BACKUP_LASTRESTORE_TIME, l); updatePreferences(); } } } }); }
From source file:com.technophobia.substeps.editor.preferences.page.SubstepsPropertyPage.java
License:Open Source License
private FieldEditor createStringFieldEditor(final SubstepsPreferences preference, final String label, final Group group) { final StringButtonFieldEditor fieldEditor = new StringButtonFieldEditor(preference.key(), label, group) { @Override/* ww w .j a v a 2 s . co m*/ protected String changePressed() { final String newLocation = handleBrowseFolderClick(); return newLocation != null ? newLocation : ""; } }; fieldEditor.setChangeButtonText("Browse"); fieldEditor.setPage(this); fieldEditor.setPreferenceStore(getPreferenceStore()); fieldEditor.load(); return fieldEditor; }
From source file:it.unibz.instasearch.ui.InstaSearchPage.java
License:Open Source License
private void createExtensionEditor(Composite pageComposite) { GridLayout pageLayout = new GridLayout(); pageLayout.numColumns = 1;//from w ww.j ava 2s . c o m pageLayout.marginWidth = 1; Composite labelComposite = new Composite(pageComposite, SWT.FILL); labelComposite.setLayout(pageLayout); Label label = new Label(labelComposite, SWT.NONE); label.setText("File types:"); labelComposite.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false, 1, 1)); Composite extensionsComposite = new Composite(pageComposite, SWT.FILL); extensionsComposite.setLayout(pageLayout); extensionsComposite.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1)); extensionEditor = new StringButtonFieldEditor(PreferenceConstants.P_SEARCH_EXTENSIONS, "", extensionsComposite) { protected String changePressed() { String exts = this.getStringValue(); exts = exts.replace(" ", ""); List<String> extList = Arrays.asList(exts.split(",")); TypeFilteringDialog dialog = new TypeFilteringDialog(getShell(), extList); dialog.open(); Object[] newSelectedTypes = dialog.getResult(); return StringUtils.join(newSelectedTypes, ","); } }; extensionEditor.setChangeButtonText("Choose..."); extensionEditor.setEmptyStringAllowed(true); extensionEditor.setPreferenceStore(InstaSearchPlugin.getDefault().getPreferenceStore()); extensionEditor.load(); Text txt = extensionEditor.getTextControl(extensionsComposite); txt.setToolTipText("E.g:\njava, xml"); }
From source file:org.caltoopia.frontend.ui.preferences.CalRootPreferencePage.java
License:Open Source License
@Override protected void createFieldEditors() { addField(new StringButtonFieldEditor("rts", "&Run-time installation:", getFieldEditorParent()) { protected String changePressed() { return browseFolder(this.getShell()); }/*from w w w .j a v a2s . c om*/ }); addField(new StringButtonFieldEditor("calsim", "&CALSim installation:", getFieldEditorParent()) { protected String changePressed() { return browseFolder(this.getShell()); } }); addField(new StringButtonFieldEditor("systemc", "&SystemC installation:", getFieldEditorParent()) { protected String changePressed() { return browseFolder(this.getShell()); } }); addField(new StringButtonFieldEditor("sdf3", "&SDF3 installation:", getFieldEditorParent()) { protected String changePressed() { return browseFolder(this.getShell()); } }); }
From source file:org.eclipse.oomph.setup.ui.SetupPreferencePage.java
License:Open Source License
@Override protected void createFieldEditors() { final Composite parent = getFieldEditorParent(); addBooleanField(parent, // SetupUIPlugin.PREF_SKIP_STARTUP_TASKS, // "Skip automatic task execution at startup time", // "Don't automatically perform setup tasks when a new workspace is opened"); addBooleanField(parent, // SetupPropertyTester.SHOW_TOOL_BAR_CONTRIBUTIONS, // "Show tool bar contributions", // "Show the 'Perform Setup Tasks' and 'Open Setups' tool bar contributions on the main tool bar"); addBooleanField(parent, // SetupPropertyTester.SHOW_PROGRESS_IN_WIZARD, // "Show progress in setup wizard", // "Don't automatically minimize the setup wizard when it starts performing.\n" // + "If this setting is enabled the wizard can be manually minimized.\n" // + "A minimized wizard can be restored by clicking the animated perform\n" // + "button in the status bar in front of the progress indicator."); final StringButtonFieldEditor preferredTextEditor = new StringButtonFieldEditor( SetupEditorSupport.PREF_TEXT_EDITOR_ID, "Preferred text editor for models", parent) { @Override/*from w w w . j av a 2s . c o m*/ protected String changePressed() { EditorSelectionDialog dialog = new EditorSelectionDialog(getControl().getShell()); dialog.setMessage( "Choose the editor to open when 'Open in text editor' is selected in a model editor:"); if (dialog.open() == EditorSelectionDialog.OK) { IEditorDescriptor descriptor = dialog.getSelectedEditor(); if (descriptor != null) { return descriptor.getId(); } } return null; } }; addField(preferredTextEditor); preferredTextEditor.fillIntoGrid(parent, 3); preferredTextEditor.getLabelControl(parent) .setToolTipText("The editor to open when 'Open in text editor' is selected in a model editor"); if (Questionnaire.exists()) { Button questionnaireButton = new Button(parent, SWT.PUSH); questionnaireButton.setText("Start Welcome Questionnaire..."); questionnaireButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Shell shell = workbench.getActiveWorkbenchWindow().getShell(); IPreferencePageContainer container = getContainer(); if (container instanceof IShellProvider) { shell = ((IShellProvider) container).getShell(); } final Shell parentShell = shell; Questionnaire.perform(parentShell, true); } }); } }
From source file:org.fastcode.preferences.CreateSimilarPreferencePage.java
License:Open Source License
/** * Creates the field editors. Field editors are abstractions of the common * GUI blocks needed to manipulate various types of preferences. Each field * editor knows how to save and restore itself. *//*from w w w. j av a2s. co m*/ @Override public void createFieldEditors() { this.project = getPreferenceStore().getString(getPreferenceLabel(P_PROJECT, this.preferenceId)); String configItems = null; final GlobalSettings globalSettings = getInstance(); final String classType = getPreferenceStoreValueString(P_CLASS_TYPE, this.preferenceId); final boolean isClass = CLASS_TYPE.getClassType(classType) == CLASS_TYPE.CLASS; if (getPreferenceStore().contains(getPreferenceLabel(P_CONFIG_ITEMS, this.preferenceId))) { configItems = getPreferenceStore().getString(getPreferenceLabel(P_CONFIG_ITEMS, this.preferenceId)); } String[] configItemArr = null; if (!isEmpty(configItems)) { configItemArr = configItems.split(COLON); } this.numConfigs = configItemArr == null ? this.numMaxConfigs : configItemArr.length; if (!isCreateNew()) { this.fromPattern = new StringFieldEditor(getPreferenceLabel(P_FROM_PATTERN, this.preferenceId), "From Clasees :", 60, getFieldEditorParent()); this.fromPattern.setEmptyStringAllowed(false); addField(this.fromPattern); } if (!isClass) { new Separator(SWT.SEPARATOR | SWT.HORIZONTAL).doFillIntoGrid(getFieldEditorParent(), 10, convertHeightInCharsToPixels(2)); } this.toPattern = new StringFieldEditor(getPreferenceLabel(P_TO_PATTERN, this.preferenceId), "To classes :", 40, getFieldEditorParent()); this.toPattern.setEmptyStringAllowed(false); addField(this.toPattern); this.classTypeRadio = new RadioGroupFieldEditor(getPreferenceLabel(P_CLASS_TYPE, this.preferenceId), "This is a : ", CLASS_CHOICE_TYPES.length, CLASS_CHOICE_TYPES, getFieldEditorParent(), true); addField(this.classTypeRadio); this.classTypeRadio.setEnabled(false, getFieldEditorParent()); final String[][] projects = getAllProjects(); this.projectComboList = new ComboFieldEditor(getPreferenceLabel(P_PROJECT, this.preferenceId), "Project:", projects, getFieldEditorParent()); addField(this.projectComboList); if (!globalSettings.isUseDefaultForPath()) { // String[][] sourcePaths = // getSourcePathsForProject(getPreferenceStore().getString(getPreferenceLabel(P_PROJECT, // preferenceId))); final String[][] sourcePaths = getAllSourcePathsInWorkspace(); this.sourceComboList = new ComboFieldEditor(getPreferenceLabel(P_SOURCE_PATH, this.preferenceId), "Source Paths:", sourcePaths, getFieldEditorParent()); addField(this.sourceComboList); } if (isCreateNew()) { this.packageFieldEditor = new StringButtonFieldEditor(getPreferenceLabel(P_PACKAGE, this.preferenceId), "Package :", getFieldEditorParent()) { @Override protected String changePressed() { try { final IJavaProject javaProject = getJavaProject(CreateSimilarPreferencePage.this.project); final SelectionDialog selectionDialog = JavaUI.createPackageDialog(getShell(), javaProject, 0, EMPTY_STR); final int ret = selectionDialog.open(); if (ret == Window.CANCEL) { return null; } final IPackageFragment packageFragment = (IPackageFragment) selectionDialog.getResult()[0]; return packageFragment.getElementName(); } catch (final JavaModelException e) { e.printStackTrace(); } return null; } }; // final IJavaProject javaProject = // getJavaProject(CreateSimilarPreferencePage.this.project); // this.packageFieldEditor = new // FastCodeListEditor(getPreferenceLabel(P_PACKAGE, // this.preferenceId), "Package", getFieldEditorParent(), // IJavaElement.PACKAGE_FRAGMENT, javaProject); addField(this.packageFieldEditor); this.packageFieldEditor.setEnabled(!isEmpty(CreateSimilarPreferencePage.this.project), getFieldEditorParent()); } // classBodyPattern = new // MultiStringFieldEditor(getPreferenceLabel(P_CLASS_BODY_PATTERN, // preferenceId), "To Class Pattern :", getFieldEditorParent()); // addField(classBodyPattern); // new // AutoCompleteField(classBodyPattern.getTextControl(getFieldEditorParent()), // new TextContentAdapter(), keyWords); if (!isForValueBeans()) { if (!isClass) { this.createImplCheckBox = new BooleanFieldEditor( getPreferenceLabel(P_IMPLEMENT_INT, this.preferenceId), "Create an &Implementation of above interface :", getFieldEditorParent()); addField(this.createImplCheckBox); this.implSubPkg = new StringFieldEditor(getPreferenceLabel(P_IMPL_SUB_PACKAGE, this.preferenceId), "Implementation &Sub Package :", 10, getFieldEditorParent()); addField(this.implSubPkg); this.implSubPkg.setEnabled( getPreferenceStore().getBoolean(getPreferenceLabel(P_IMPLEMENT_INT, this.preferenceId)), getFieldEditorParent()); } this.finalCheckBox = new BooleanFieldEditor(getPreferenceLabel(P_FINAL_CLASS, this.preferenceId), "Make this Class final :", getFieldEditorParent()); addField(this.finalCheckBox); if (this.preferenceId.equals(CREATE_NEW_PREFERENCE_SERVICE_ID)) { this.finalCheckBox.setEnabled(false, getFieldEditorParent()); } // this.classHeader = new // MultiStringFieldEditor(getPreferenceLabel(P_CLASS_HEADER, // preferenceId), "Code Before Class (Header) :", // getFieldEditorParent()); // addField(this.classHeader); this.classInsideBody = new MultiStringFieldEditor( getPreferenceLabel(P_CLASS_INSIDE_BODY, this.preferenceId), "Code In the Class (&Body) :", getFieldEditorParent()); addField(this.classInsideBody); this.implSuperClass = new FastCodeListEditor(getPreferenceLabel(P_SUPER_CLASS, this.preferenceId), "Implementation &Super Class :", getFieldEditorParent(), IJavaElementSearchConstants.CONSIDER_CLASSES, null); addField(this.implSuperClass); // this.implSuperClass.setEnabled(getPreferenceStore().getBoolean(getPreferenceLabel(P_IMPLEMENT_INTERFACES, // preferenceId)), getFieldEditorParent()); //this.implSuperClass.setChangeButtonText(BUTTON_TEXT_BROWSE); this.interfaces = new FastCodeListEditor(getPreferenceLabel(P_IMPLEMENT_INTERFACES, this.preferenceId), "Interfaces To &Implement:", getFieldEditorParent(), CONSIDER_INTERFACES, null); addField(this.interfaces); this.classImports = new FastCodeListEditor(getPreferenceLabel(P_CLASS_IMPORTS, this.preferenceId), "Clases To I&mport:", getFieldEditorParent(), CONSIDER_ALL_TYPES, null); addField(this.classImports); this.inclInstanceCheckBox = new BooleanFieldEditor( getPreferenceLabel(P_INCLUDE_INSTACE_FROM, this.preferenceId), "Include an in&stance of the from class :", getFieldEditorParent()); addField(this.inclInstanceCheckBox); this.inclInstanceCheckBox.setEnabled(!isCreateNew(), getFieldEditorParent()); this.createDefaultConstructor = new BooleanFieldEditor( getPreferenceLabel(P_CREATE_DEFAULT_CONSTRUCTOR, this.preferenceId), "Create Default Co&nstructor :", getFieldEditorParent()); addField(this.createDefaultConstructor); this.createInstanceConstructor = new BooleanFieldEditor( getPreferenceLabel(P_CREATE_INSTANCE_CONSTRUCTOR, this.preferenceId), "Create Instance Co&nstructor :", getFieldEditorParent()); addField(this.createInstanceConstructor); this.inclGetterSetterCheckBox = new BooleanFieldEditor( getPreferenceLabel(P_INCLUDE_GETTER_SETTER_INSTACE_FROM, this.preferenceId), "Generate &getter/setters for private fields :", getFieldEditorParent()); addField(this.inclGetterSetterCheckBox); this.copyMethodCheckBox = new BooleanFieldEditor(getPreferenceLabel(P_COPY_METHODS, this.preferenceId), "Copy &methods from the from Class", getFieldEditorParent()); addField(this.copyMethodCheckBox); this.copyMethodCheckBox.setEnabled(!isCreateNew(), getFieldEditorParent()); this.createMethodBody = new BooleanFieldEditor( getPreferenceLabel(P_CREATE_METHOD_BODY, this.preferenceId), "Create &method Body", getFieldEditorParent()); addField(this.createMethodBody); this.createMethodBody.setEnabled(!isCreateNew(), getFieldEditorParent()); this.addionalFieldsCheckBox = new BooleanFieldEditor( getPreferenceLabel(P_CREATE_FIELDS, this.preferenceId), "Create &Additional Fields", getFieldEditorParent()); addField(this.addionalFieldsCheckBox); this.addionalFieldsNameField = new StringFieldEditor( getPreferenceLabel(P_CREATE_FIELDS_NAME, this.preferenceId), "Name/Pattern for &Additional Fields", getFieldEditorParent()); addField(this.addionalFieldsNameField); this.includePattern = new StringFieldEditor(getPreferenceLabel(P_INCLUDE_PATTERN, this.preferenceId), "Include Methods/Fields:", 20, getFieldEditorParent()); addField(this.includePattern); this.includePattern.setEnabled(!isCreateNew(), getFieldEditorParent()); this.excludePattern = new StringFieldEditor(getPreferenceLabel(P_EXCLUDE_PATTERN, this.preferenceId), "Exclude Methods/Fields:", 20, getFieldEditorParent()); addField(this.excludePattern); this.excludePattern.setEnabled(!isCreateNew(), getFieldEditorParent()); this.classAnnotations = new FastCodeListEditor( getPreferenceLabel(P_CLASS_ANNOTATIONS, this.preferenceId), "Class &Annotations:", getFieldEditorParent(), CONSIDER_ANNOTATION_TYPES, null); addField(this.classAnnotations); this.fieldAnnotations = new FastCodeListEditor( getPreferenceLabel(P_FIELD_ANNOTATIONS, this.preferenceId), "Field &Annotations:", getFieldEditorParent(), CONSIDER_ANNOTATION_TYPES, null); addField(this.fieldAnnotations); this.methodAnnotations = new FastCodeListEditor( getPreferenceLabel(P_METHOD_ANNOTATIONS, this.preferenceId), "Method &Annotations:", getFieldEditorParent(), CONSIDER_ANNOTATION_TYPES, null); addField(this.methodAnnotations); /* this.assignReturnCheckBox = new BooleanFieldEditor(getPreferenceLabel(P_RETURN_VARIABLE, this.preferenceId), "Assign &return type to a variable :", getFieldEditorParent()); addField(this.assignReturnCheckBox); this.assignReturnCheckBox.setEnabled(!isCreateNew(),getFieldEditorParent()); this.returnVariableName = new StringFieldEditor(getPreferenceLabel(P_RETURN_VARIABLE_NAME, this.preferenceId), "&Return variable name :", 20, getFieldEditorParent()); this.returnVariableName.setEmptyStringAllowed(!this.assignReturnCheckBox.getBooleanValue()); addField(this.returnVariableName); this.returnVariableName.setEnabled(!isCreateNew(),getFieldEditorParent());*/ this.convertMethodParamCheckBox = new BooleanFieldEditor( getPreferenceLabel(P_CONVERT_METHOD_PARAM, this.preferenceId), "Convert Method &Parameter:", getFieldEditorParent()); addField(this.convertMethodParamCheckBox); this.convertMethodParamCheckBox.setEnabled(!isCreateNew(), getFieldEditorParent()); this.convertMethodParamFromField = new StringFieldEditor( getPreferenceLabel(P_CONVERT_METHOD_PARAM_FROM, this.preferenceId), "Convert Method &Parameter From :", 50, getFieldEditorParent()); addField(this.convertMethodParamFromField); this.convertMethodParamFromField.setEnabled(!isCreateNew(), getFieldEditorParent()); this.convertMethodParamToField = new StringFieldEditor( getPreferenceLabel(P_CONVERT_METHOD_PARAM_TO, this.preferenceId), "Convert Method &Parameter To :", 50, getFieldEditorParent()); addField(this.convertMethodParamToField); this.convertMethodParamToField.setEnabled(!isCreateNew(), getFieldEditorParent()); this.createUnitTestCheckBox = new BooleanFieldEditor( getPreferenceLabel(P_CREATE_UNIT_TEST, this.preferenceId), "Create &Unit Test of the Target Class:", getFieldEditorParent()); addField(this.createUnitTestCheckBox); this.createUnitTestCheckBox.setEnabled(false, getFieldEditorParent()); } else { // classHeader = new // MultiStringFieldEditor(getPreferenceLabel(P_CLASS_HEADER, // preferenceId), "Code Before Class (Header) :", // getFieldEditorParent()); // addField(classHeader); this.finalCheckBox = new BooleanFieldEditor(getPreferenceLabel(P_FINAL_CLASS, this.preferenceId), "Make this Class final :", getFieldEditorParent()); addField(this.finalCheckBox); this.classInsideBody = new MultiStringFieldEditor( getPreferenceLabel(P_CLASS_INSIDE_BODY, this.preferenceId), "Code In the Class (&Body) :", getFieldEditorParent()); addField(this.classInsideBody); this.implSuperClass = new FastCodeListEditor(getPreferenceLabel(P_SUPER_CLASS, this.preferenceId), "Implementation &Super Class :", getFieldEditorParent(), IJavaElementSearchConstants.CONSIDER_CLASSES, null); addField(this.implSuperClass); this.interfaces = new FastCodeListEditor(getPreferenceLabel(P_IMPLEMENT_INTERFACES, this.preferenceId), "Interfaces To &Implement:", getFieldEditorParent(), CONSIDER_INTERFACES, null); addField(this.interfaces); this.classImports = new FastCodeListEditor(getPreferenceLabel(P_CLASS_IMPORTS, this.preferenceId), "Clases To I&mport:", getFieldEditorParent(), CONSIDER_ALL_TYPES, null); addField(this.classImports); this.createDefaultConstructor = new BooleanFieldEditor( getPreferenceLabel(P_CREATE_DEFAULT_CONSTRUCTOR, this.preferenceId), "Create Default &Constructor :", getFieldEditorParent()); addField(this.createDefaultConstructor); this.createInstanceConstructor = new BooleanFieldEditor( getPreferenceLabel(P_CREATE_INSTANCE_CONSTRUCTOR, this.preferenceId), "Create Instance &Constructor :", getFieldEditorParent()); addField(this.createInstanceConstructor); this.copyFieldsCheckBox = new BooleanFieldEditor(getPreferenceLabel(P_COPY_FIELDS, this.preferenceId), "Copy &Fields from the from Class :", getFieldEditorParent()); addField(this.copyFieldsCheckBox); this.copyFieldsCheckBox.setEnabled(!isCreateNew(), getFieldEditorParent()); this.breakDateFieldsCheckBox = new BooleanFieldEditor( getPreferenceLabel(P_BREAK_DATE_FIELDS, this.preferenceId), "Break &Date Fields :", getFieldEditorParent()); addField(this.breakDateFieldsCheckBox); this.breakDateFieldsCheckBox.setEnabled(!isCreateNew(), getFieldEditorParent()); this.classAnnotations = new FastCodeListEditor( getPreferenceLabel(P_CLASS_ANNOTATIONS, this.preferenceId), "Class &Annotations:", getFieldEditorParent(), CONSIDER_ANNOTATION_TYPES, null); addField(this.classAnnotations); this.fieldAnnotations = new FastCodeListEditor( getPreferenceLabel(P_FIELD_ANNOTATIONS, this.preferenceId), "Field &Annotations:", getFieldEditorParent(), CONSIDER_ANNOTATION_TYPES, null); addField(this.fieldAnnotations); this.includePattern = new StringFieldEditor(getPreferenceLabel(P_INCLUDE_PATTERN, this.preferenceId), "Include Methods/Fields:", getFieldEditorParent()); addField(this.includePattern); this.excludePattern = new StringFieldEditor(getPreferenceLabel(P_EXCLUDE_PATTERN, this.preferenceId), "Exclude Methods/Fields:", getFieldEditorParent()); addField(this.excludePattern); } this.createWorkingSetCheckBox = new BooleanFieldEditor( getPreferenceLabel(P_CREATE_WORKING_SET, this.preferenceId), "Automatically Create a Working Set :", 30, getFieldEditorParent()); addField(this.createWorkingSetCheckBox); this.workingSetName = new StringFieldEditor(getPreferenceLabel(P_WORKING_SET_NAME, this.preferenceId), "Working Set Name :", 30, getFieldEditorParent()); addField(this.workingSetName); final String[][] configTypes = new String[this.configPattern.getConfigs().length][2]; for (int k = 0; k < configTypes.length; k++) { configTypes[k][0] = configTypes[k][1] = this.configPattern.getConfigs()[k].getConfigType(); } final String[][] configFileConvTypes = new String[4][2]; configFileConvTypes[0][0] = configFileConvTypes[0][1] = CONVERSION_NONE; configFileConvTypes[1][0] = configFileConvTypes[1][1] = CONVERSION_LOWER_CASE; configFileConvTypes[2][0] = configFileConvTypes[2][1] = CONVERSION_CAMEL_CASE; configFileConvTypes[3][0] = configFileConvTypes[3][1] = CONVERSION_CAMEL_CASE_HYPHEN; // Create the configuration file items. for (int configCount = 0; configCount < this.numMaxConfigs; configCount++) { final String configType = this.configPattern.getConfigs()[configCount].getConfigType(); if (!(isStringInArray(configType, configItemArr) || isStringInArray(configType, this.configPattern.getConfigTypes().get(this.preferenceId)))) { continue; } new Separator(SWT.SEPARATOR | SWT.HORIZONTAL).doFillIntoGrid(getFieldEditorParent(), 100, convertHeightInCharsToPixels(2)); this.createConfigCheckBox[configCount] = new BooleanFieldEditor( getPreferenceLabel(P_CREATE_CONFIG, this.preferenceId) + configCount, "Create configuration file :", getFieldEditorParent()); addField(this.createConfigCheckBox[configCount]); final boolean enableConfigParts = getPreferenceStore() .getBoolean(getPreferenceLabel(P_CREATE_CONFIG, this.preferenceId) + configCount); FieldEditor fieldEditor; fieldEditor = createRadioGroupFieldEditor( getPreferenceLabel(P_CONFIG_TYPE, this.preferenceId) + configCount, "Configuration Type", this.configPattern.getConfigs().length, configTypes, getFieldEditorParent(), true); this.createSimilarConfigurationPart.setConfigTypeRadio(configCount, (RadioGroupFieldEditor) fieldEditor); addField(fieldEditor); fieldEditor.setEnabled(false, getFieldEditorParent()); fieldEditor = createStringFieldEditor( getPreferenceLabel(P_CONFIG_LOCATION, this.preferenceId) + configCount, "Configuration Location :", getFieldEditorParent()); this.createSimilarConfigurationPart.setConfigLocation(configCount, (StringFieldEditor) fieldEditor); addField(fieldEditor); fieldEditor.setEnabled(enableConfigParts, getFieldEditorParent()); // ((StringFieldEditor)fieldEditor).setEmptyStringAllowed(enableConfigParts // ? false : true); fieldEditor = createStringFieldEditor( getPreferenceLabel(P_CONFIG_FILE_NAME, this.preferenceId) + configCount, "Configuration File Name :", getFieldEditorParent()); this.createSimilarConfigurationPart.setConfigFile(configCount, (StringFieldEditor) fieldEditor); // configFile[configCount] = new // StringFieldEditor(getPreferenceLabel(P_CONFIG_FILE_NAME, // preferenceId)+configCount, "Configuration File Name :", // getFieldEditorParent()); addField(fieldEditor); fieldEditor.setEnabled(enableConfigParts, getFieldEditorParent()); ((StringFieldEditor) fieldEditor).setEmptyStringAllowed(enableConfigParts ? false : true); fieldEditor = new RadioGroupFieldEditor( getPreferenceLabel(P_CONFIG_FILE_CONV_TYPES, this.preferenceId) + configCount, "Convert the File Name :", configFileConvTypes.length, configFileConvTypes, getFieldEditorParent(), true); this.createSimilarConfigurationPart.setConfigFileNameConversion(configCount, (RadioGroupFieldEditor) fieldEditor); addField(fieldEditor); fieldEditor.setEnabled(enableConfigParts, getFieldEditorParent()); if (!isEmpty(this.configPattern.getConfigs()[configCount].getConfigLocale())) { fieldEditor = new StringFieldEditor( getPreferenceLabel(P_CONFIG_LOCALE, this.preferenceId) + configCount, "Configuration Locale :", getFieldEditorParent()); this.createSimilarConfigurationPart.setConfigLocale(configCount, (StringFieldEditor) fieldEditor); addField(fieldEditor); fieldEditor.setEnabled(enableConfigParts, getFieldEditorParent()); } fieldEditor = createMultiStringFieldEditor( getPreferenceLabel(P_CONFIG_HEADER_PATTERN, this.preferenceId) + configCount, "Configuration Header :", getFieldEditorParent()); this.createSimilarConfigurationPart.setConfigHeaderPattern(configCount, (MultiStringFieldEditor) fieldEditor); addField(fieldEditor); fieldEditor.setEnabled(enableConfigParts, getFieldEditorParent()); fieldEditor = createMultiStringFieldEditor( getPreferenceLabel(P_CONFIG_START_PATTERN, this.preferenceId) + configCount, "Configuration Start :", getFieldEditorParent()); this.createSimilarConfigurationPart.setConfigStartPattern(configCount, (MultiStringFieldEditor) fieldEditor); addField(fieldEditor); fieldEditor.setEnabled(enableConfigParts, getFieldEditorParent()); fieldEditor = createStringFieldEditor( getPreferenceLabel(P_CONFIG_END_PATTERN, this.preferenceId) + configCount, "Configuration End :", getFieldEditorParent()); this.createSimilarConfigurationPart.setConfigEndPattern(configCount, (StringFieldEditor) fieldEditor); addField(fieldEditor); fieldEditor.setEnabled(enableConfigParts, getFieldEditorParent()); fieldEditor = createMultiStringFieldEditor( getPreferenceLabel(P_CONFIG_PATTERN, this.preferenceId) + configCount, "Configuration Pattern :", getFieldEditorParent()); this.createSimilarConfigurationPart.setConfigBodyPattern(configCount, (MultiStringFieldEditor) fieldEditor); addField(fieldEditor); fieldEditor.setEnabled(enableConfigParts, getFieldEditorParent()); ((MultiStringFieldEditor) fieldEditor).setEmptyStringAllowed(enableConfigParts ? false : true); } this.removeConfigCheckBox = new BooleanFieldEditor(getPreferenceLabel(P_REMOVE_CONFIG, this.preferenceId), "Remove unused configurations :", BooleanFieldEditor.SEPARATE_LABEL, getFieldEditorParent()); if (this.numConfigs > 1) { // removeConfig should be always off. addField(this.removeConfigCheckBox); getPreferenceStore().setValue(getPreferenceLabel(P_REMOVE_CONFIG, this.preferenceId), false); this.removeConfigCheckBox.load(); } final Button restoreConfigButton = new Button(getFieldEditorParent(), SWT.PUSH); restoreConfigButton.setText("Restore configurations"); if (this.numConfigs == this.numMaxConfigs) { restoreConfigButton.setEnabled(false); } restoreConfigButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { final MessageDialogWithToggle dialogWithToggle = MessageDialogWithToggle.openYesNoQuestion( CreateSimilarPreferencePage.this.getShell(), "Restore configurations", "Restore configurations, this will close the preference dialog, You have reopen it.", "Remember Decision", false, CreateSimilarPreferencePage.this.getPreferenceStore(), getPreferenceLabel(P_RESTORE_CONFIG_ITEMS, CreateSimilarPreferencePage.this.preferenceId)); if (dialogWithToggle.getReturnCode() != MESSAGE_DIALOG_RETURN_YES) { return; } CreateSimilarPreferencePage.this.getPreferenceStore().setValue( getPreferenceLabel(P_CONFIG_ITEMS, CreateSimilarPreferencePage.this.preferenceId), ""); CreateSimilarPreferencePage.this.getShell().close(); // getShell().open(); } }); }
From source file:org.fastcode.preferences.JUnitPreferencePage.java
License:Open Source License
/** * Creates the field editors. Field editors are abstractions of the common * GUI blocks needed to manipulate various types of preferences. Each field * editor knows how to save and restore itself. *///from w ww . j av a 2 s .c o m @Override public void createFieldEditors() { // getFieldEditorParent().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)); // applyFont(); this.junitProfiles = new ComboFieldEditor(P_JUNIT_TEST_PROFILE, "JUnit Test Profiles:", this.allTestProfiles, getFieldEditorParent()); addField(this.junitProfiles); this.createNewProfCheckBox = new BooleanFieldEditor(P_JUNIT_CREATE_NEW_PROF, "Create A New Profile :", getFieldEditorParent()); addField(this.createNewProfCheckBox); this.deleteCurrentProfCheckBox = new BooleanFieldEditor(P_JUNIT_DELETE_CURR_PROF, "Delete Current Profile :", getFieldEditorParent()); addField(this.deleteCurrentProfCheckBox); if (this.allTestProfiles.length == 1) { this.deleteCurrentProfCheckBox.setEnabled(false, getFieldEditorParent()); } this.junitProfileName = new StringFieldEditor(getPreferenceName(P_JUNIT_PROFILE_NAME), "Junit Test Profile Name :", 30, getFieldEditorParent()); addField(this.junitProfileName); this.junitProfileName.setEnabled(false, getFieldEditorParent()); //this.junitProfileName.setEmptyStringAllowed(false); this.junitProfilePattern = new StringFieldEditor(getPreferenceName(P_JUNIT_PROFILE_PATTERN), "Class Name Pattern :", 30, getFieldEditorParent()); addField(this.junitProfilePattern); this.junitProfilePattern.setEnabled(false, getFieldEditorParent()); //this.junitProfilePattern.setEmptyStringAllowed(false); final GlobalSettings globalSettings = getInstance(); final String[][] junitTypes = { { "Junit 4", P_JUNIT_TYPE_4 }, { "Junit 3", P_JUNIT_TYPE_3 }, { "TestNG", P_JUNIT_TYPE_TESTNG }, { "Custom", P_JUNIT_TYPE_CUSTOM } }; this.junitTypeRadio = new RadioGroupFieldEditor(getPreferenceName(P_JUNIT_TYPE), "Junit Type", 4, junitTypes, getFieldEditorParent(), true); addField(this.junitTypeRadio); this.junitTestClass = new StringFieldEditor(getPreferenceName(P_JUNIT_TEST_CLASS), "Junit Test Class Name :", 30, getFieldEditorParent()); addField(this.junitTestClass); this.junitTestClass.setEmptyStringAllowed(false); this.junitTestMethod = new StringFieldEditor(getPreferenceName(P_JUNIT_TEST_METHOD), "Junit Test Method Name :", 30, getFieldEditorParent()); addField(this.junitTestMethod); this.junitTestMethod.setEmptyStringAllowed(false); this.junitSuperClass = new StringButtonFieldEditor(getPreferenceName(P_BASE_TEST), "Base Test Class :", getFieldEditorParent()) { @Override protected String changePressed() { setTextLimit(200); try { final SelectionDialog selectionDialog = createTypeDialog(getShell(), null, createWorkspaceScope(), CONSIDER_CLASSES, false, "*TestCase"); if (selectionDialog.open() == SWT.CANCEL) { return EMPTY_STR; } final IType type = (IType) selectionDialog.getResult()[0]; JUnitPreferencePage.this.override = true; if (!isJunitTest(type)) { openError(getShell(), "Error", "This is not valid base class for Junit Tests. Please try again."); return EMPTY_STR; } return type.getFullyQualifiedName(); } catch (final JavaModelException e) { e.printStackTrace(); } return EMPTY_STR; } }; //this.junitSuperClass.setEmptyStringAllowed(false); this.junitSuperClass.setChangeButtonText(BUTTON_TEXT_BROWSE); addField(this.junitSuperClass); if (this.junitType.equals(P_JUNIT_TYPE_4)) { this.junitSuperClass.setEnabled(false, getFieldEditorParent()); } // this.showAllCheckBox = new BooleanFieldEditor(getPreferenceName(P_JUNIT_SHOW_ALL_PATHS), "Show All Paths", getFieldEditorParent()); // addField(this.showAllCheckBox); // boolean showAll = preferenceStore.getBoolean(P_JUNIT_SHOW_ALL_PATHS); // if (showAll) { // entryNamesAndValues = getAllSourcePaths(null); // } final String[][] projects = getAllProjects(); this.projectComboList = new ComboFieldEditor(getPreferenceName(P_JUNIT_TEST_PROJECT), "Project:", projects, getFieldEditorParent()); addField(this.projectComboList); final String[][] entryNamesAndValues = getSourcePathsForProject( this.preferenceStore.getString(getPreferenceName(P_JUNIT_TEST_PROJECT))); this.junitLocation = new ComboFieldEditor(getPreferenceName(P_JUNIT_TEST_LOCATION), "Test Location:", entryNamesAndValues, getFieldEditorParent()); addField(this.junitLocation); this.junitLocation.setEnabled(!globalSettings.isUseDefaultForPath(), getFieldEditorParent()); this.createInstance = new BooleanFieldEditor(getPreferenceName(P_JUNIT_ALWAYS_CREATE_INSTANCE), "Always Create an Instance at Class Level", getFieldEditorParent()); addField(this.createInstance); this.fieldAnnotations = new FastCodeListEditor(getPreferenceName(P_JUNIT_FIELD_ANNOTATIONS), "Field Annotations:", getFieldEditorParent(), CONSIDER_ANNOTATION_TYPES, null); addField(this.fieldAnnotations); // this.junitTestFormat = new MultiStringFieldEditor(getPreferenceName(P_JUNIT_TEST_FORMAT), "Test Test Format:", getFieldEditorParent()); // addField(this.junitTestFormat); //((StringFieldEditor)junitTestFormat).setEmptyStringAllowed(false); this.classImports = new FastCodeListEditor(getPreferenceName(P_JUNIT_CLASS_IMPORTS), "Clases To Import:", getFieldEditorParent(), CONSIDER_ALL_TYPES, null); addField(this.classImports); this.classInsideBody = new MultiStringFieldEditor(getPreferenceName(P_JUNIT_CLASS_INSIDE_BODY), "Code Inside Class :", getFieldEditorParent()); addField(this.classInsideBody); this.classAnnotations = new FastCodeListEditor(getPreferenceName(P_JUNIT_CLASS_ANNOTATIONS), "Class Annotations:", getFieldEditorParent(), CONSIDER_ANNOTATION_TYPES, null); addField(this.classAnnotations); this.methodAnnotations = new FastCodeListEditor(getPreferenceName(P_JUNIT_METHOD_ANNOTATIONS), "Test Method Annotations:", getFieldEditorParent(), CONSIDER_ANNOTATION_TYPES, null); addField(this.methodAnnotations); this.methodComment = new StringFieldEditor(getPreferenceName(P_JUNIT_METHOD_COMMENT), "Test Method Comment:", 60, getFieldEditorParent()); addField(this.methodComment); this.junitCreateMethodBody = new BooleanFieldEditor(getPreferenceName(P_JUNIT_CREATE_METHOD_BODY), "Create Method Body", getFieldEditorParent()); addField(this.junitCreateMethodBody); /*this.junitAlwaysCreateTryCatch = new BooleanFieldEditor(getPreferenceName(P_JUNIT_ALWAYS_CREATE_TRY_CATCH), "Always Create Try Catch Block", getFieldEditorParent()); addField(this.junitAlwaysCreateTryCatch);*/ this.exceptionBody = new MultiStringFieldEditor(getPreferenceName(P_JUNIT_EXCEPTION_BODY), "Body in the Catch Block (for happy tests)", getFieldEditorParent()); addField(this.exceptionBody); this.negativeBody = new MultiStringFieldEditor(getPreferenceName(P_JUNIT_NEGATIVE_BODY), "Test body for negative tests :", getFieldEditorParent()); addField(this.negativeBody); createImportExportButtons(getFieldEditorParent()); }