use of org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager in project n4js by eclipse.
the class AssignWorkingSetsAction method run.
@Override
public void run() {
// fail if the action hasn't been initialized
if (site == null) {
return;
}
final Object[] selectionElements = getStructuredSelection().toArray();
// get Iterable of selected project names
Iterable<String> selectionProjectNames = Arrays.asList(selectionElements).stream().filter(item -> item instanceof IProject).map(item -> ((IProject) item).getName()).collect(Collectors.toList());
// double-check that the active Working Sets Manager is {@link ManualAssociationAwareWorkingSetManager}
if (!(broker.getActiveManager() instanceof ManualAssociationAwareWorkingSetManager)) {
return;
}
// open the dialog
SelectionDialog dialog = createDialog(Arrays.asList(((ManualAssociationAwareWorkingSetManager) broker.getActiveManager()).getWorkingSets()), selectionElements.length);
dialog.open();
// Abort if user didn't press OK
if (dialog.getReturnCode() != Window.OK) {
return;
}
// perform specified working set updates
performWorkingSetUpdate(dialog.getResult(), selectionProjectNames);
}
use of org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager in project n4js by eclipse.
the class AssignWorkingSetsAction method performWorkingSetUpdate.
/**
* Performs the working sets update specified by the given dialog result.
*
* @param dialogResult
* The result of the list selection dialog.
* @param selectionProjectNames
* A list of names of the selected projects
* @returns {@code true} if the update was successfully performed. {@code false} otherwise.
*/
private boolean performWorkingSetUpdate(Object[] dialogResult, Iterable<String> selectionProjectNames) {
if (dialogResult == null) {
return false;
}
WorkingSetManager workingSetManager = broker.getActiveManager();
if (!(workingSetManager instanceof ManualAssociationAwareWorkingSetManager)) {
return false;
}
// get copies of the workspace working sets.
List<WorkingSet> allWorkingSets = new ArrayList<>(Arrays.asList(workingSetManager.getAllWorkingSets()));
List<WorkingSet> workingSets = new ArrayList<>(Arrays.asList(workingSetManager.getWorkingSets()));
// build WorkingSet edit difference
WorkingSetDiffBuilder builder = new WorkingSetDiffBuilder(workingSetManager);
for (Object resultItem : dialogResult) {
// abort if the dialog returned a non-working-set item
if (!(resultItem instanceof ManualAssociationWorkingSet)) {
return false;
}
ManualAssociationWorkingSet oldState = (ManualAssociationWorkingSet) resultItem;
ManualAssociationWorkingSet newState = getWorkingSetWithAddedProjects(oldState, selectionProjectNames);
// register working set edit
builder.edit(oldState, newState);
// replace working set with its new state
replaceWorkingSet(workingSets, newState);
replaceWorkingSet(allWorkingSets, newState);
}
// apply WorkingSet update and refresh UI
workingSetManager.updateState(builder.build(workingSets, allWorkingSets));
broker.refreshNavigator();
return true;
}
Aggregations