@Override protected void createFieldEditors () { final List<String> tzs = Arrays.asList ( TimeZone.getAvailableIDs () ); Collections.sort ( tzs ); final String[][] entries = new String[tzs.size ()][2]; int i = 0; for ( final String id : tzs ) { entries[i][0] = id; entries[i][1] = id; i += 1; } final FieldEditor field = new ComboFieldEditor ( "timeZone", Messages.TimeZonePreferencePage_TimeZone_Label, entries, getFieldEditorParent () ); //$NON-NLS-1$ addField ( field ); }
/** * Check if all fields are valid * */ private void checkState() { if(editorList != null){ int size = editorList.size(); for(int i=0; i<size; i++){ FieldEditor fieldEditor = editorList.get(i); if(StringUtils.isNotBlank(((StringFieldEditor)fieldEditor).getErrorMessage())){ setErrorMessage(((StringFieldEditor)fieldEditor).getErrorMessage()); setValid(false); break; }else{ setValid(true); } } } }
@Override public Control createContents(Composite parent) { Composite container = new Composite(parent, SWT.NONE); parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); fieldEditor = createFieldEditor(container); fieldEditor.setPage(messages); fieldEditor.setPropertyChangeListener(new IPropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { if (FieldEditor.IS_VALID.equals(event.getProperty())) { fireValueChanged(IS_VALID, event.getOldValue(), event.getNewValue()); } else if (FieldEditor.VALUE.equals(event.getProperty())) { fireValueChanged(VALUE, event.getOldValue(), event.getNewValue()); } } }); fieldEditor.setPreferenceStore(getPreferenceStore()); fieldEditor.load(); fieldEditor.fillIntoGrid(container, fieldEditor.getNumberOfControls()); return container; }
private void createPollChangesIntervalGroup(Composite composite) { Composite groupComposite = new Composite(composite, SWT.LEFT); GridLayout layout = new GridLayout(); layout.numColumns = 2; groupComposite.setLayout(layout); GridData gd = new GridData(); gd.horizontalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; groupComposite.setLayoutData(gd); pollChangesInterval = new IntegerFieldEditor(POLL_CHANGES_INTERVAL_PREF, "Poll changes interval (seconds)", groupComposite); pollChangesInterval.setTextLimit(Integer.toString(MAX_POLL_CHANGES_INTERVAL).length()); pollChangesInterval.setErrorMessage("The workspace save interval should be between 30 and 9999."); pollChangesInterval.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE); pollChangesInterval.setValidRange(MIN_POLL_CHANGES_INTERVAL, MAX_POLL_CHANGES_INTERVAL); pollChangesInterval.setPropertyChangeListener(event -> { if (event.getProperty().equals(FieldEditor.IS_VALID)) { setValid(pollChangesInterval.isValid()); } }); addField(pollChangesInterval); }
/** * The field editor preference page implementation of a <code>PreferencePage</code> * method loads all the field editors with their default values. */ protected void performDefaults() { if (fields != null) { Iterator e = fields.iterator(); while (e.hasNext()) { FieldEditor pe = (FieldEditor) e.next(); pe.loadDefault(); } } // Force a recalculation of my error state. checkState(); super.performDefaults(); }
/** * The field editor preference page implementation of this <code>IPreferencePage</code> * (and <code>IPropertyChangeListener</code>) method intercepts <code>IS_VALID</code> * events but passes other events on to its superclass. */ public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(FieldEditor.IS_VALID)) { boolean newValue = ((Boolean) event.getNewValue()).booleanValue(); // If the new value is true then we must check all field editors. // If it is false, then the page is invalid in any case. if (newValue) { checkState(); } else { setInvalidFieldEditor((FieldEditor) event.getSource()); setValid(newValue); } } }
/** * Recomputes the page's error state by calling <code>isValid</code> for * every field editor. */ protected void checkState() { boolean valid = true; setInvalidFieldEditor(null); // The state can only be set to true if all // field editors contain a valid value. So we must check them all if (fields != null) { int size = fields.size(); for (int i = 0; i < size; i++) { FieldEditor editor = (FieldEditor) fields.get(i); valid = valid && editor.isValid(); if (!valid) { setInvalidFieldEditor(editor); break; } } } setValid(valid); }
@Override public FieldEditor createFieldEditor(final String name, final String label, final Composite parent, final FieldEditorDetails details) { final Class<? extends FieldEditor> type = details.getFieldEditorClass(); if (DatabaseComboFieldEditor.class.equals(type)) { return new DatabaseComboFieldEditor(name, label, details.getLabelsAndValues().toArray(), parent); } if (ReaderComboFieldEditor.class.equals(type)) { return new ReaderComboFieldEditor(name, label, details.getLabelsAndValues().toArray(), parent); } if (ThresholdsListEditor.class.equals(type)) { return new ThresholdsListEditor(name, label, parent); } if (WriterComboFieldEditor.class.equals(type)) { return new WriterComboFieldEditor(name, label, details.getLabelsAndValues().toArray(), parent); } return super.createFieldEditor(name, label, parent, details); }
@Override public void propertyChange(PropertyChangeEvent event) { super.propertyChange(event); if (event.getProperty().equals(FieldEditor.VALUE)) { if (event.getSource() == getCacheHashCodeField()) { getHashCodeCachingField().setEnabled(getCacheHashCodeField().getBooleanValue(), getFieldEditorParent()); } else if (event.getSource() == getCacheToStringField()) { getToStringCachingField().setEnabled(getCacheToStringField().getBooleanValue(), getFieldEditorParent()); } else if (event.getSource() == getHashCodeCachingField() || event.getSource() == getToStringCachingField()) { checkState(); } } }
/** * 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. */ public void createFieldEditors() { this.createBeyondCompareFieldEditors(); this.addField(new EmptyFieldEitor(this.getFieldEditorParent())); this.createTortoiseFieldEditors("SVN", "TortoiseProc.exe", "TortoiseMerge.exe", PreferenceConstants.TORTOISE_SVN); this.addField(new EmptyFieldEitor(this.getFieldEditorParent())); this.createTortoiseFieldEditors("Git", "TortoiseGitProc.exe", "TortoiseGitMerge.exe", PreferenceConstants.TORTOISE_GIT); /*final String tortoiseHgExecutable = "thg.exe"; this.addField(new EmptyFieldEitor(this.getFieldEditorParent())); this.createTortoiseFieldEditors("Hg", tortoiseHgExecutable, tortoiseHgExecutable, PreferenceConstants.TORTOISE_HG); */ for (BooleanFieldEditor featureEnabledEditor : this.controlMapping.keySet()) { featureEnabledEditor.setPropertyChangeListener(this); final boolean featureEnabled = this.getPreferenceStore().getBoolean(featureEnabledEditor.getPreferenceName()); for (FieldEditor fieldEditor : this.controlMapping.get(featureEnabledEditor)) { fieldEditor.setPropertyChangeListener(this); fieldEditor.setEnabled(featureEnabled, getFieldEditorParent()); } } }
@Override public final void propertyChange(final PropertyChangeEvent event) { final Object eventSource = event.getSource(); if (eventSource instanceof BooleanFieldEditor) { final BooleanFieldEditor featureEnabledEditor = (BooleanFieldEditor) eventSource; if (this.controlMapping.keySet().contains(featureEnabledEditor)) { final boolean featureEnabled = featureEnabledEditor.getBooleanValue(); for (FieldEditor fieldEditor : this.controlMapping.get(featureEnabledEditor)) { fieldEditor.setEnabled(featureEnabled, getFieldEditorParent()); } } } // Updated the apply button in every case because the property change // can be caused by a changed string or path value this.updateApplyButton(); }
@Override public final boolean isValid() { // Search for enabled features wit invalid configuration options for (BooleanFieldEditor featureEnabledEditor : this.controlMapping.keySet()) { if (featureEnabledEditor.getBooleanValue() == true) { for (FieldEditor fieldEditor : this.controlMapping.get(featureEnabledEditor)) { if (fieldEditor.isValid() == false) { return false; } } } } return true; }
@Override protected void createFieldEditors() { // Header header = createHeader(); if (header != null) { GridDataFactory.fillDefaults().span(Short.MAX_VALUE, 1).applyTo(header); addSeparator(); } // Fields for (final IPreference preference : preferences) { if (pageDefinition.equals(preference.getPageDefinition())) { if (preference.isSeparate()) { addSeparator(); } final Composite fieldEditorParent = getFieldEditorParent(); final FieldEditor fieldEditor = createFieldEditor(preference, fieldEditorParent); addField(fieldEditor); fieldEditorMap.put(preference, new FieldEditorWrapper(fieldEditor, fieldEditorParent)); } } universe.putAll(fieldEditorMap); }
protected boolean checkParentsEnabled(final Set<IPreference> parents) { boolean parentEnabled = true; for (final IPreference preference : parents) { final FieldEditorWrapper fieldEditorWrapper = universe.get(preference); if (fieldEditorWrapper == null) { parentEnabled = getBooleanFromStore(preference); } else { final FieldEditor fieldEditor = fieldEditorWrapper.getFieldEditor(); if (fieldEditor instanceof BooleanFieldEditor) { try { parentEnabled = ((BooleanFieldEditor) fieldEditor).getBooleanValue(); } catch (final NullPointerException e) { logger.log(Level.FINE, e.toString(), e); parentEnabled = getBooleanFromStore(preference); } } } if (!parentEnabled) { break; // don't waste time } } return parentEnabled; }
/** * Recomputes the page's error state by calling <code>isValid</code> for every field editor. */ protected void checkState() { boolean valid = true; m_invalidFieldEditor = null; // The state can only be set to true if all // field editors contain a valid value. So we must check them all if (m_fields != null) { int size = m_fields.size(); for (int i = 0; i < size; i++) { FieldEditor editor = m_fields.get(i); valid = valid && editor.isValid(); if (!valid) { m_invalidFieldEditor = editor; break; } } } setValid(true); }
@Override protected List<? extends FieldEditor> additionalFields(Composite fieldEditorParent) { modelExtensionSelector = new RadioGroupFieldEditor( PreferenceConstants.EXPORT_RESULT_MODEL_EXTENSION, "Simulink model file extension: ", 1, new String[][] { {"MDL", "mdl"}, {"SLX", "slx"} }, fieldEditorParent); //@formatter:on modelExtensionSelector.setPreferenceStore(store); modelExtensionSelector.load(); return Lists.newArrayList(modelExtensionSelector); }
@Override protected List<FieldEditor> additionalFields(Composite fieldEditorParent) { Label filters = new Label(fieldEditorParent, SWT.NONE); filters.setText("Import filters to use:"); List<FieldEditor> fes = new LinkedList<FieldEditor>(); Map<String, ISimulinkImportFilter> filtersById = ImportFilterRegistry.INSTANCE.getFiltersById(); for (String filterId : filtersById.keySet()) { ISimulinkImportFilter filter = filtersById.get(filterId); BooleanFieldEditor filterCheckbox = new BooleanFieldEditor(filterId, filter.getName(), fieldEditorParent); filterCheckbox.setPreferenceStore(store); filterCheckbox.setPreferenceName(filterId); filterCheckbox.load(); filterCheckbox.getDescriptionControl(fieldEditorParent).setToolTipText(filter.getDescription()); fes.add(filterCheckbox); filterSelectors.put(filterId, filterCheckbox); } importedModelNameEditor = new StringFieldEditor("", "Result Model Name:", fieldEditorParent); importedModelNameEditor.setEmptyStringAllowed(false); importedModelNameEditor.setStringValue(importedModelName); fes.add(importedModelNameEditor); return fes; }
protected void addField(final FieldEditor editor, Composite parent, IPreferenceStore preferenceStore) { fields.add(editor); editor.setPreferenceStore(preferenceStore); editor.load(); editor.setPropertyChangeListener(new IPropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { // Apply on any change! editor.store(); } }); if (editor instanceof BooleanFieldEditorCustom) { editor.fillIntoGrid(parent, 2); } else { editor.fillIntoGrid(parent, 1); } }
/** * @return the preference stores associated with the field editors (they store their values in separate preference * stores) */ public List<IPreferenceStore> getPreferenceStores() { List<IPreferenceStore> stores = new ArrayList<>(); for (FieldEditor field : fields) { stores.add(field.getPreferenceStore()); } return stores; }
/** * Add fields to list */ private void addFields(FieldEditor editor){ if (editorList == null) { editorList = new ArrayList<>(); } editorList.add(editor); }
private void checkState() { if(editorList != null){ int size = editorList.size(); for(int i=0; i<size; i++){ FieldEditor fieldEditor = editorList.get(i); if(StringUtils.isNotBlank(((StringFieldEditor)fieldEditor).getErrorMessage())){ setErrorMessage(((StringFieldEditor)fieldEditor).getErrorMessage()); setValid(false); break; }else{ setValid(true); } } } }
protected void updateFieldEditors(boolean enabled) { Composite parent = getFieldEditorParent(); for (FieldEditor editor : editors) { editor.load(); editor.setEnabled(enabled, parent); } getDefaultsButton().setEnabled(enabled); }
@Override public FieldEditor createFieldEditor(Composite parent) { String[][] entryNamesAndValues = new String[values.size()][2]; for (int i = 0; i < values.size(); ++i) { entryNamesAndValues[i][0] = values.get(i).getDisplayName(); entryNamesAndValues[i][1] = values.get(i).getId(); } return new ComboFieldEditor(this.getKey(), this.getDescription(), entryNamesAndValues, parent); }
@Override protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.FILL); fieldEditors.add(new BooleanFieldEditor(ENABLE_HAETAE, "Enable Epsilon Haetae (experimental)", composite)); for (FieldEditor fieldEditor : fieldEditors) { fieldEditor.setPreferenceStore(Activator.getDefault().getPreferenceStore()); fieldEditor.load(); } return composite; }
@Override public boolean performOk() { for (FieldEditor fieldEditor : fieldEditors) { fieldEditor.store(); } return true; }
protected void initialize() { if (fields != null) { Iterator e = fields.iterator(); while (e.hasNext()) { FieldEditor fieldEditor = (FieldEditor) e.next(); fieldEditor.setPage(this); fieldEditor.setPreferenceStore(getPreferenceStore()); fieldEditor.load(); } } }
protected void addEditor(FieldEditor editor) { if (fields == null) { fields = new ArrayList(); } fields.add(editor); }
/** * The field editor preference page implementation of this * <code>PreferencePage</code> method saves all field editors by * calling <code>FieldEditor.store</code>. Note that this method * does not save the preference store itself; it just stores the * values back into the preference store. * * @see FieldEditor#store() */ public boolean performOk() { if (fields != null) { Iterator e = fields.iterator(); while (e.hasNext()) { FieldEditor pe = (FieldEditor) e.next(); pe.store(); } } return true; }
public void dispose() { for (FieldEditor ed : actives) { ed.setPage(null); ed.setPropertyChangeListener(null); ed.setPreferenceStore(null); } actives.clear(); comp.getParent().dispose(); comp = null; page = null; }
/** * Initializes and sets up the given editor * * @param editor * @param store */ void initEditor(FieldEditor editor, IPreferenceStore store) { addField(editor); editor.setPage(this); editor.setPropertyChangeListener(this); editor.setPreferenceStore(store); editor.load(); }
protected void updateFieldEditors(boolean enabled) { // TODO handle do not use project settings sets project settings to // default Composite parent = getFieldEditorParent(); Iterator<FieldEditor> it = editors.iterator(); while (it.hasNext()) { FieldEditor editor = it.next(); if (enabled) editor.load(); else editor.loadDefault(); editor.setEnabled(enabled, parent); } }
@Override protected final void addField(FieldEditor editor) { String prefix = null; if (getPreferencePrefix() != null) prefix = getPreferencePrefix() + PreferenceConstants.SEPARATOR + editor.getPreferenceName(); else prefix = editor.getPreferenceName(); editor.setPreferenceName(prefix); internalEditorsList.add(editor); super.addField(editor); }
protected final void loadDefaults(String preferencePrefix) { setPreferencePrefix(preferencePrefix); performDefaults(); for (FieldEditor fe : internalEditorsList) { if (fe.presentsDefaultValue()) { internalStore.setValue(fe.getPreferenceName(), masterPreferenceStore.getDefaultString(fe .getPreferenceName())); } } }
@Override public final void propertyChange(PropertyChangeEvent event) { if (event.getSource() instanceof FieldEditor) { FieldEditor fe = (FieldEditor) event.getSource(); internalStore.setValue(fe.getPreferenceName(), fe.getPreferenceStore().getDefaultString(fe.getPreferenceName())); fe.setPreferenceStore(internalStore); fe.store(); } super.propertyChange(event); }
private void setPreferencePrefix(String preferencePrefix) { this.preferencePrefix = preferencePrefix; for (FieldEditor fe : internalEditorsList) { String oldPreferenceName = fe.getPreferenceName(); if (oldPreferenceName.indexOf(PreferenceConstants.SEPARATOR) >= 0) { oldPreferenceName = oldPreferenceName.substring(oldPreferenceName .lastIndexOf(PreferenceConstants.SEPARATOR) + 1); } fe.setPreferenceName(getPreferencePrefix() + PreferenceConstants.SEPARATOR + oldPreferenceName); } }
protected void updateFieldEditors() { boolean pageEnabled = this.isPageEnabled(); Composite parent = this.getFieldEditorParent(); for (FieldEditor field : this.fields) { field.setEnabled(pageEnabled, parent); } }
@Override public void propertyChange(PropertyChangeEvent event) { super.propertyChange(event); Object source = event.getSource(); if (event.getProperty().equals(FieldEditor.VALUE)) { this.updateFieldEditors(); } if (getFields().contains(source)) { this.compilerPreferencesModified = true; } }
private void applyProfile(String profile) { currentProfile = profile; for (Entry<String, FieldEditor> entry : fieldMap.entrySet()) { if (Preferences.PROFILES().equals(entry.getKey())) { continue; } entry.getValue().setPreferenceName(Preferences.getProfilePrefix(currentProfile) + entry.getKey()); entry.getValue().load(); } }
public void init(IWorkbench workbench) { validityChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(FieldEditor.IS_VALID)) updateValidState(); } }; }
@Override public void dispose() { // send dispose to all editors // Composite parent = getFieldEditorParent(); for (FieldEditor editor : editors.keySet()) { editor.dispose(); } super.dispose(); }