/** Handler for the "Rename..." button. */ private void renameConfig() { InputDialog dlg = new InputDialog( tree.getTree().getShell(), WorkingSetMessages.WSConfigsController_renameDlg_title, WorkingSetMessages.WSConfigsController_renameDlg_msg, currentConfig.getName(), new IInputValidator() { public String isValid(String newText) { if (newText.equals(currentConfig.getName())) { return ""; //$NON-NLS-1$ } if (currentWorkingSet.getConfiguration(newText) != null) { return WorkingSetMessages.WSConfigsController_addDlg_nameExists; } if (newText.length() == 0) { return WorkingSetMessages.WSConfigsController_addDlg_emptyName; } return null; } }); if (dlg.open() == IDialogConstants.OK_ID) { currentConfig.setName(dlg.getValue()); tree.refresh(currentWorkingSet); } }
/** * Updates the display to reflect potential changes in project activation and the resulting * changes in working-set config activation, if any. */ private void updateForActivation() { // update all working-set configs that intersect this config Collection<IWorkingSetProxy.ISnapshot> unaffectedWorkingSets = new java.util.HashSet<IWorkingSetProxy.ISnapshot>(workspace.getWorkingSets()); for (IProject project : currentConfig.getWorkingSet().resolveProjects()) { for (Iterator<IWorkingSetProxy.ISnapshot> iter = unaffectedWorkingSets.iterator(); iter.hasNext(); ) { IWorkingSetProxy.ISnapshot next = iter.next(); if (next.resolveProjects().contains(project)) { iter.remove(); if (next.updateActiveConfigurations()) { // major change. Refresh it altogether tree.refresh(next); } else { // lighter-weight updates of its configs for (IWorkingSetConfiguration config : next.getConfigurations()) { tree.update(config, null); } } } } } updateButtons(); }
/** Handler for the "Add..." button. */ private void addConfig() { InputDialog dlg = new InputDialog( tree.getTree().getShell(), WorkingSetMessages.WSConfigsController_addDlg_title, WorkingSetMessages.WSConfigsController_addDlg_msg, WorkingSetMessages.WSConfigsController_addDlg_defaultName, new IInputValidator() { public String isValid(String newText) { if (currentWorkingSet.getConfiguration(newText) != null) { return WorkingSetMessages.WSConfigsController_addDlg_nameExists; } if (newText.length() == 0) { return WorkingSetMessages.WSConfigsController_addDlg_emptyName; } return null; } }); if (dlg.open() == IDialogConstants.OK_ID) { IWorkingSetConfiguration.ISnapshot newConfig = currentWorkingSet.createConfiguration(dlg.getValue()); tree.refresh(currentWorkingSet); tree.setSelection(new StructuredSelection(newConfig), true); currentConfig = newConfig; currentWorkingSet = currentConfig.getWorkingSet(); // this is a "recently used" working set IWorkingSet ws = currentWorkingSet.resolve(); if (ws != null) { WorkingSetConfigurationManager.WS_MGR.addRecentWorkingSet(ws); } } }
/** * Handles selection of working sets and their configurations. Among potentially other actions, * this injects the working-set configuration selection into the project configurations controller * and updates the enablement of the buttons. */ public void selectionChanged(SelectionChangedEvent event) { currentConfig = null; currentWorkingSet = null; if (event.getSelection() instanceof IStructuredSelection) { IStructuredSelection sel = (IStructuredSelection) event.getSelection(); if (!sel.isEmpty()) { Object first = sel.getFirstElement(); if (first instanceof IWorkingSetConfiguration) { currentConfig = (IWorkingSetConfiguration.ISnapshot) first; currentWorkingSet = currentConfig.getWorkingSet(); } else if (first instanceof IWorkingSetProxy) { currentWorkingSet = (IWorkingSetProxy.ISnapshot) first; } } } if (projectsController != null) { // tell the project controller projectsController.setWorkingSetConfiguration(currentConfig); } updateButtons(); }
/** Updates the enablement state of the action buttons according to the current selection. */ private void updateButtons() { if (addButton != null) { addButton.setEnabled(currentWorkingSet != null); } if (removeButton != null) { removeButton.setEnabled((currentConfig != null) && !currentConfig.isReadOnly()); } if (renameButton != null) { renameButton.setEnabled((currentConfig != null) && !currentConfig.isReadOnly()); } if (activateButton != null) { activateButton.setEnabled((currentConfig != null) && !currentConfig.isActive()); } if (buildButton != null) { buildButton.setEnabled(currentConfig != null); } }
/** Handler for the "Activate" button. */ private void activateConfig() { currentConfig.activate(); projectsController.update(); updateForActivation(); }