use of org.eclipse.swt.SWT.CENTER 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;
}
});
}
Aggregations