use of org.eclipse.n4js.utils.collections.Arrays2 in project n4js by eclipse.
the class WorkingSetManualAssociationWizard method addPages.
@Override
public void addPages() {
addPage(new WizardPage("") {
private Text nameText;
private final Collection<IProject> workspaceProjects = newTreeSet(PROJECT_NAME_COMPARATOR);
private final Collection<IProject> workingSetProjects = newTreeSet(PROJECT_NAME_COMPARATOR);
@Override
public void createControl(Composite parent) {
final Composite composite = new Composite(parent, NONE);
composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).create());
composite.setLayoutData(fillDefaults().align(FILL, FILL).grab(true, true).create());
new Label(composite, NONE).setText("Working set name:");
nameText = new Text(composite, BORDER);
nameText.setLayoutData(fillDefaults().align(FILL, CENTER).grab(true, false).create());
Composite tableComposite = new Composite(composite, NONE);
tableComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).create());
tableComposite.setLayoutData(fillDefaults().align(FILL, FILL).grab(true, true).span(2, 1).create());
Group workspaceGroup = new Group(tableComposite, SHADOW_IN);
workspaceGroup.setText("Available workspace projects");
workspaceGroup.setLayout(GridLayoutFactory.fillDefaults().create());
workspaceGroup.setLayoutData(fillDefaults().align(FILL, FILL).grab(true, true).create());
final TableViewer allProjectsViewer = new TableViewerBuilder(singletonList("")).setHasBorder(true).setHeaderVisible(false).setLinesVisible(false).setMultipleSelection(true).setColumnWidthsInPixel(Ints.asList(350)).setLabelProvider(labelProvider).build(workspaceGroup);
Composite buttonComposite = new Composite(tableComposite, NONE);
buttonComposite.setLayout(GridLayoutFactory.fillDefaults().create());
// buttonComposite.setLayoutData(fillDefaults().align(CENTER, CENTER).grab(false, false).create());
final Button addButton = new Button(buttonComposite, PUSH);
addButton.setImage(ImageRef.RIGHT_ARROW.asImage().orNull());
addButton.setToolTipText("Add all selected workspace projects");
addButton.setEnabled(false);
final Button removeButton = new Button(buttonComposite, PUSH);
removeButton.setImage(ImageRef.LEFT_ARROW.asImage().orNull());
removeButton.setToolTipText("Remove all selected working set element projects");
removeButton.setEnabled(false);
Group workingSetGroup = new Group(tableComposite, SHADOW_IN);
workingSetGroup.setText("Associated working set projects");
workingSetGroup.setLayout(GridLayoutFactory.fillDefaults().create());
workingSetGroup.setLayoutData(fillDefaults().align(FILL, FILL).grab(true, true).create());
final TableViewer associatedProjectsViewer = new TableViewerBuilder(singletonList("")).setHasBorder(true).setHeaderVisible(false).setLinesVisible(false).setMultipleSelection(true).setColumnWidthsInPixel(Ints.asList(350)).setLabelProvider(labelProvider).build(workingSetGroup);
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = allProjectsViewer.getStructuredSelection();
if (selection != null && !selection.isEmpty()) {
final IProject[] projects = Arrays2.filter(selection.toArray(), IProject.class);
allProjectsViewer.remove(projects);
associatedProjectsViewer.add(projects);
workspaceProjects.removeAll(Arrays.asList(projects));
workingSetProjects.addAll(Arrays.asList(projects));
setPageComplete(validatePage());
}
}
});
removeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = associatedProjectsViewer.getStructuredSelection();
if (selection != null && !selection.isEmpty()) {
final IProject[] projects = Arrays2.filter(selection.toArray(), IProject.class);
associatedProjectsViewer.remove(projects);
allProjectsViewer.add(projects);
workingSetProjects.removeAll(Arrays.asList(projects));
workspaceProjects.addAll(Arrays.asList(projects));
setPageComplete(validatePage());
}
}
});
associatedProjectsViewer.addSelectionChangedListener(event -> {
final IStructuredSelection selection = associatedProjectsViewer.getStructuredSelection();
removeButton.setEnabled(null != selection && !selection.isEmpty());
});
allProjectsViewer.addSelectionChangedListener(event -> {
final IStructuredSelection selection = allProjectsViewer.getStructuredSelection();
addButton.setEnabled(null != selection && !selection.isEmpty());
});
setPageComplete(false);
setControl(composite);
final Optional<WorkingSet> editedWorkingSet = getEditedWorkingSet();
workspaceProjects.addAll(Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects()));
if (editedWorkingSet.isPresent()) {
final ManualAssociationWorkingSet workingSet = (ManualAssociationWorkingSet) editedWorkingSet.get();
workingSetRef.set(workingSet);
nameText.setText(workingSet.getName());
nameText.selectAll();
workingSetProjects.addAll(workingSet.getAssociatedProjects());
workspaceProjects.removeAll(workingSetProjects);
originalName.set(workingSet.getName());
}
composite.getDisplay().asyncExec(() -> {
setTitle(TITLE);
setDescription(DESCRIPTION);
allProjectsViewer.setInput(workspaceProjects);
associatedProjectsViewer.setInput(workingSetProjects);
});
nameText.addModifyListener(e -> setPageComplete(validatePage()));
}
@Override
public void setVisible(boolean visible) {
if (visible) {
Rectangle location = UIUtils.getConstrainedShellBounds(getShell(), SHELL_SIZE);
getShell().setBounds(location);
}
super.setVisible(visible);
}
@SuppressWarnings("null")
private boolean validatePage() {
String errorMessage = null;
final String name = nameText.getText();
final WorkingSetManager manager = getManager();
if (manager == null) {
errorMessage = "No active working set manager is available.";
}
if (errorMessage == null) {
if (name == null || name.trim().length() == 0) {
errorMessage = "Working set name should be specified.";
}
}
if (errorMessage == null) {
if (!name.equals(originalName.get()) && // This case ID and name are equal. Intentionally name.
getAllWorkingSets().stream().anyMatch(ws -> ws.getName().equals(name))) {
errorMessage = "A working set already exists with name '" + name + "'.";
}
}
if (errorMessage != null) {
workingSetRef.set(null);
} else {
final Iterable<String> projectNames = from(workingSetProjects).transform(p -> p.getName());
workingSetRef.set(new ManualAssociationWorkingSet(projectNames, name, manager));
}
setMessage(errorMessage, ERROR);
return errorMessage == null;
}
});
}
use of org.eclipse.n4js.utils.collections.Arrays2 in project n4js by eclipse.
the class N4JSProjectExplorerHelper method getVirtualNodesForProject.
/**
* Returns with an array of virtual {@link Node node} instances for the project that should be revealed in the
* project explorer.
*
* @param project
* the workspace project.
* @return an array of virtual nodes.
*/
public Node[] getVirtualNodesForProject(IProject project) {
checkArgument(!(project instanceof ExternalProject), "Expected Eclipse workspace project. Got: " + project);
if (null == project || !project.exists() || !project.isAccessible()) {
return Node.EMPTY_NODES;
}
IN4JSProject n4Project = getProject(project);
if (null == n4Project || !n4Project.exists() || n4Project.isExternal()) {
return Node.EMPTY_NODES;
}
final Image image = ImageRef.LIB_PATH.asImage().get();
final NamedNode rootNode = new NamedNode(project, "External Dependencies", image);
Iterable<IN4JSProject> directDependencies = from(n4Project.getAllDirectDependencies()).filter(IN4JSProject.class);
Iterable<IN4JSProject> runtimeLibraries = getExternalDependenciesOfType(directDependencies, RUNTIME_LIBRARY);
if (!from(runtimeLibraries).isEmpty()) {
Map<String, IN4JSProject> builtInRuntimeEnvironments = getBuiltInRuntimeEnvironments();
Map<String, IN4JSProject> builtInRuntimeLibraries = getBuiltInRuntimeLibraries();
Collection<IN4JSProject> libs = newHashSet();
Collection<IN4JSProject> envs = newHashSet();
for (IN4JSProject p : runtimeLibraries) {
IN4JSProject dependency = builtInRuntimeLibraries.get(p.getProjectId());
if (null != dependency) {
libs.add(dependency);
}
}
if (!libs.isEmpty()) {
OUTER: for (IN4JSProject p : builtInRuntimeEnvironments.values()) {
for (IN4JSProject providedLib : from(p.getProvidedRuntimeLibraries()).filter(IN4JSProject.class)) {
if (libs.contains(providedLib)) {
envs.add(p);
String extndedRuntimeEnvName = p.getExtendedRuntimeEnvironmentId().orNull();
if (null != extndedRuntimeEnvName) {
final IN4JSProject extension = builtInRuntimeEnvironments.get(extndedRuntimeEnvName);
if (null != extension) {
envs.add(extension);
}
}
continue OUTER;
}
}
}
}
NamedNode runtimeNode = new NamedNode(rootNode, "N4JS Runtime", image);
if (!envs.isEmpty()) {
NamedNode envsNode = new NamedNode(runtimeNode, "Runtime Environments", image);
envsNode.addChild(from(envs).transform(p -> new BuiltInProjectNode(envsNode, p)));
runtimeNode.addChild(envsNode);
}
if (!libs.isEmpty()) {
NamedNode libsNode = new NamedNode(runtimeNode, "Runtime Libraries", image);
libsNode.addChild(from(libs).transform(p -> new BuiltInProjectNode(libsNode, p)));
runtimeNode.addChild(libsNode);
}
if (!Arrays2.isEmpty(runtimeNode.getChildren())) {
rootNode.addChild(runtimeNode);
}
}
Map<String, IN4JSProject> langProjects = getAvailableLangProjects();
Map<String, IN4JSProject> mangelhaftProjects = getAvailableMangelhaftProjects();
Map<String, IN4JSProject> npmProjects = getAvailableNpmProjects();
Collection<IN4JSProject> requiredLangLibs = newHashSet();
Collection<IN4JSProject> requiredMangelhaftLibs = newHashSet();
Collection<IN4JSProject> requiredNpmLibs = newHashSet();
for (IN4JSProject directDependecy : directDependencies) {
if (directDependecy.exists() && directDependecy.isExternal()) {
IN4JSProject externalDepenency = mangelhaftProjects.get(directDependecy.getProjectId());
if (null != externalDepenency) {
requiredMangelhaftLibs.add(externalDepenency);
} else {
externalDepenency = npmProjects.get(directDependecy.getProjectId());
if (null != externalDepenency) {
requiredNpmLibs.add(externalDepenency);
} else {
externalDepenency = langProjects.get(directDependecy.getProjectId());
if (null != externalDepenency) {
requiredLangLibs.add(externalDepenency);
}
}
}
}
}
if (!requiredLangLibs.isEmpty()) {
NamedNode langNode = new NamedNode(rootNode, EXTERNAL_LIBRARY_NAMES.get(LANG_CATEGORY), image);
langNode.addChild(from(requiredLangLibs).transform(p -> new BuiltInProjectNode(langNode, p)));
rootNode.addChild(langNode);
}
if (!requiredMangelhaftLibs.isEmpty()) {
NamedNode mangNode = new NamedNode(rootNode, EXTERNAL_LIBRARY_NAMES.get(MANGELHAFT_CATEGORY), image);
mangNode.addChild(from(requiredMangelhaftLibs).transform(p -> new BuiltInProjectNode(mangNode, p)));
rootNode.addChild(mangNode);
}
if (!requiredNpmLibs.isEmpty()) {
NamedNode npmNode = new NamedNode(rootNode, EXTERNAL_LIBRARY_NAMES.get(NPM_CATEGORY), image);
npmNode.addChild(from(requiredNpmLibs).transform(p -> new BuiltInProjectNode(npmNode, p)));
rootNode.addChild(npmNode);
}
return Arrays2.isEmpty(rootNode.getChildren()) ? new Node[0] : new Node[] { rootNode };
}
use of org.eclipse.n4js.utils.collections.Arrays2 in project n4js by eclipse.
the class RebuildWorkspaceProjectsScheduler method scheduleBuildIfNecessary.
/**
* Schedules a build with the given projects. Does nothing if the {@link Platform platform} is not running, or the
* iterable of projects is empty.
*
* @param toUpdate
* an iterable of projects to build.
*/
public void scheduleBuildIfNecessary(final Iterable<IProject> toUpdate) {
if (Platform.isRunning() && !Iterables.isEmpty(toUpdate)) {
final Workspace workspace = (Workspace) ResourcesPlugin.getWorkspace();
final IBuildConfiguration[] projectsToReBuild = from(asList(workspace.getBuildOrder())).filter(config -> Iterables.contains(toUpdate, config.getProject())).toArray(IBuildConfiguration.class);
if (!Arrays2.isEmpty(projectsToReBuild)) {
new RebuildWorkspaceProjectsJob(projectsToReBuild).schedule();
}
}
}
use of org.eclipse.n4js.utils.collections.Arrays2 in project n4js by eclipse.
the class GHOLD_101_WorkingSetsTest_PluginUITest method tearDown.
@Override
public void tearDown() throws Exception {
super.tearDown();
broker.resetState();
waitForIdleState();
final TreeItem[] treeItems = commonViewer.getTree().getItems();
assertTrue("Expected empty Project Explorer. Input was: " + Arrays.toString(treeItems), Arrays2.isEmpty(treeItems));
assertFalse("Expected projects as top level elements in navigator.", broker.isWorkingSetTopLevel());
assertNull("Select working set drop down contribution was visible when projects are configured as top level elements.", getWorkingSetDropDownContribution());
IContributionItem showHiddenWorkingSetsItem = from(Arrays.asList(projectExplorer.getViewSite().getActionBars().getToolBarManager().getItems())).firstMatch(i -> ShowHiddenWorkingSetsDropDownAction.class.getName().equals(i.getId())).orNull();
assertNull("Show hidden working set drop down contribution was visible when projects are configured as top level elements.", showHiddenWorkingSetsItem);
}
use of org.eclipse.n4js.utils.collections.Arrays2 in project n4js by eclipse.
the class SelectAllProjectExplorer_PluginUITest method tearDown.
@Override
public void tearDown() throws Exception {
super.tearDown();
broker.resetState();
waitForIdleState();
final TreeItem[] treeItems = commonViewer.getTree().getItems();
assertTrue("Expected empty Project Explorer. Input was: " + Arrays.toString(treeItems), Arrays2.isEmpty(treeItems));
assertFalse("Expected projects as top level elements in navigator.", broker.isWorkingSetTopLevel());
assertNull("Select working set drop down contribution was visible when projects are configured as top level elements.", getWorkingSetDropDownContribution());
IContributionItem showHiddenWorkingSetsItem = from(Arrays.asList(projectExplorer.getViewSite().getActionBars().getToolBarManager().getItems())).firstMatch(i -> ShowHiddenWorkingSetsDropDownAction.class.getName().equals(i.getId())).orNull();
assertNull("Show hidden working set drop down contribution was visible when projects are configured as top level elements.", showHiddenWorkingSetsItem);
}
Aggregations