/** 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); } } }
/** * 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(); }
/** * 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(); }