@SuppressWarnings("unchecked") public void applyPreferences() { if (!hasChanges) { return; } hasChanges = false; // must do the store before setting the preference // to ensure that the store is flushed disableButton.store(); List<String> elts = patternList.getElements(); List<String> result = new ArrayList<String>(elts.size() * 2); for (String elt : elts) { result.add(elt); result.add(patternList.isChecked(elt) ? "y" : "n"); } Activator.getDefault().setPreference(preferences, Activator.GROOVY_SCRIPT_FILTERS, result); boolean yesNo = MessageDialog.openQuestion( parent.getShell(), "Do full build?", "Script folder preferences have changed.\n" + "Must do a full build before they come completely into effect. Do you want to do a full build now?"); if (yesNo) { if (project != null) { new BuildJob(project).schedule(); } else { new BuildJob(GroovyNature.getAllAccessibleGroovyProjects().toArray(new IProject[0])) .schedule(); } } }
private void resetElements() { List<String> elements = findPatterns(); List<String> filteredElements = new ArrayList<String>(elements.size() / 2); List<String> checkedElements = new ArrayList<String>(elements.size() / 2); for (Iterator<String> eltIter = elements.iterator(); eltIter.hasNext(); ) { String elt = eltIter.next(); filteredElements.add(elt); if (eltIter.hasNext()) { String doCopy = eltIter.next(); if (doCopy.equals("y")) { checkedElements.add(elt); } } } patternList.setElements(filteredElements); patternList.setCheckedElements(checkedElements); patternList.selectFirstElement(); hasChanges = false; }
public ListDialogField createListContents() { Label label = new Label(parent, SWT.WRAP); label.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); label.setText("Groovy Script Folders:"); label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT)); Composite inner = new Composite(parent, SWT.BORDER); inner.setFont(parent.getFont()); GridLayout layout = new GridLayout(); layout.marginHeight = 3; layout.marginWidth = 3; layout.numColumns = 1; inner.setLayout(layout); inner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); disableButton = new BooleanFieldEditor( Activator.GROOVY_SCRIPT_FILTERS_ENABLED, "Enable script folder support", BooleanFieldEditor.DEFAULT, inner); disableButton.setPreferenceStore(store); disableButton.load(); // inner composite contains the dialog itself final Composite innerInner = new Composite(inner, SWT.NONE); innerInner.setFont(parent.getFont()); layout = new GridLayout(); layout.marginHeight = 3; layout.marginWidth = 3; layout.numColumns = 3; innerInner.setLayout(layout); innerInner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); innerInner.setToolTipText( "CHECKED boxes are COPIED to output folder.\nUNCHECKED boxes are NOT copied."); boolean enabled = disableButton.getBooleanValue(); innerInner.setEnabled(enabled); // enable/disable pattern list based disableButton.setPropertyChangeListener( new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty() == FieldEditor.VALUE) { Object o = event.getNewValue(); if (o instanceof Boolean) { boolean enabled = ((Boolean) o); innerInner.setEnabled(enabled); for (Control c : innerInner.getChildren()) { c.setEnabled(enabled); } } } hasChanges = true; } }); ScriptPatternAdapter adapter = new ScriptPatternAdapter(); patternList = new CheckedListDialogField(adapter, buttonLabels, new ScriptLabelProvider(DESCRIPTOR)); patternList.setDialogFieldListener(adapter); patternList.setLabelText( "Groovy files that match these patterns are treated as scripts. " + "They will not be compiled and will be copied as-is to the output folder.\n\n" + "CHECKED boxes will be COPIED to the output folder. UNCHECKED boxes are NOT copied to the output folder."); patternList.setRemoveButtonIndex(IDX_REMOVE); patternList.enableButton(IDX_EDIT, false); patternList.setCheckAllButtonIndex(IDX_CHECKALL); patternList.setUncheckAllButtonIndex(IDX_UNCHECKALL); patternList.doFillIntoGrid(innerInner, 3); Label l = patternList.getLabelControl(innerInner); GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false); gd.widthHint = 200; l.setLayoutData(gd); resetElements(); patternList.enableButton(IDX_ADD, true); patternList.setViewerComparator(new ViewerComparator()); // finally force greying out of tree if required innerInner.setEnabled(enabled); for (Control c : innerInner.getChildren()) { c.setEnabled(enabled); } return patternList; }