From 85ba1cd0384a5faad8a683f7885195cd61bfb3a8 Mon Sep 17 00:00:00 2001 From: kuzniarz Date: Tue, 23 Jun 2020 15:47:13 +0200 Subject: [PATCH] Implemented Composite Configuration GUI - composite selection is not implemented yet Signed-off-by: kuzniarz --- ...reateWorkspaceCompositePreferencePage.java | 10 +-- .../CompositeConfigurationDialogHandler.java | 2 + .../AbstractCompositeDialog.java | 75 ++++++++++++++++--- .../CompositeSelectionDialog.java | 71 ++++++++++++++++-- .../WorkspaceCompositeCreationWizard.java | 11 ++- ...orkspaceCompositeWizardMessages.properties | 2 +- 6 files changed, 147 insertions(+), 24 deletions(-) diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCreateWorkspaceCompositePreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCreateWorkspaceCompositePreferencePage.java index 0eec4be7c..96ea1e2d8 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCreateWorkspaceCompositePreferencePage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCreateWorkspaceCompositePreferencePage.java @@ -209,12 +209,11 @@ protected String getPageContextInformation() { @Override public void finish() { - updateCompositeProjects(); - String workspaceCompositeName = this.workspaceCompositeNameText.getText(); - String oldWorkspaceCompositeName = gradleComposite.getName(); - IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); - try { + updateCompositeProjects(); + String workspaceCompositeName = this.workspaceCompositeNameText.getText(); + String oldWorkspaceCompositeName = ""; + IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); File compositePreferenceFile = getWorkspaceCompositesPropertiesFile(workspaceCompositeName); IAdaptable[] compositeElements = getCompositeElements(getConfiguration().getIncludedBuildsList().getValue()); if (gradleComposite == null) { @@ -222,6 +221,7 @@ public void finish() { gradleComposite.setId(IGradleCompositeIDs.NATURE); } else { IAdaptable[] oldElements = gradleComposite.getElements(); + oldWorkspaceCompositeName = gradleComposite.getName(); if (!gradleComposite.getName().equals(this.workspaceCompositeNameText.getText())) { gradleComposite.setName(this.workspaceCompositeNameText.getText()); } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/CompositeConfigurationDialogHandler.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/CompositeConfigurationDialogHandler.java index c8910e602..9b3413f17 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/CompositeConfigurationDialogHandler.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/CompositeConfigurationDialogHandler.java @@ -6,12 +6,14 @@ import org.eclipse.core.commands.*; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.dialogs.WorkingSetSelectionDialog; public class CompositeConfigurationDialogHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + CompositeSelectionDialog dialog = new CompositeSelectionDialog(shell); dialog.open(); return null; diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeDialog.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeDialog.java index 9b81bad30..fd1a79f1c 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeDialog.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeDialog.java @@ -11,6 +11,11 @@ import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -20,9 +25,12 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.IWorkingSetManager; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.SelectionDialog; +import org.eclipse.ui.internal.AggregateWorkingSet; public abstract class AbstractCompositeDialog extends SelectionDialog { @@ -32,6 +40,8 @@ public abstract class AbstractCompositeDialog extends SelectionDialog { private Button selectAllButton; private Button deselectAllButton; private CheckboxTableViewer compositeSelectionListViewer; + private TableViewer viewer; + List composites = new ArrayList(); private ColumnLabelProvider labelProvider = new ColumnLabelProvider() { private Map icons = new Hashtable<>(); @Override @@ -54,9 +64,11 @@ public Image getImage(Object element) { return icon; } }; + private IStructuredContentProvider contentProvider; protected AbstractCompositeDialog(Shell parentShell) { super(parentShell); + contentProvider = new ArrayContentProvider(); } @Override @@ -64,21 +76,44 @@ protected Control createDialogArea(Composite parent) { Composite container = createComponents(parent); addListeners(); loadCompositeNames(); - //initial composite selection + //loadCompositeSelection(); TODO (kuzniarz) selection/deselection currently not possible return container; } + private void loadCompositeSelection() { + this.compositeSelectionListViewer.setAllChecked(false); + + IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); + for (IWorkingSet workingSet : manager.getWorkingSets()) { + //TODO (kuzniarz) Not yet working + this.compositeSelectionListViewer.setChecked(workingSet, workingSet.isVisible()); + System.out.println(workingSet.getName() + ".isVisible() == " + workingSet.isVisible()); + } + + } + + public void setSelection(IWorkingSet[] workingSets) { + setInitialSelections((Object[]) workingSets); + } + private void loadCompositeNames() { compositeSelectionListViewer.setLabelProvider(labelProvider); - compositeSelectionListViewer.setContentProvider(ArrayContentProvider.getInstance()); - IWorkingSet[] workingSetArray = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets(); - List composites = new ArrayList(); + compositeSelectionListViewer.setContentProvider(contentProvider); + IWorkingSet[] workingSetArray = PlatformUI.getWorkbench().getWorkingSetManager().getAllWorkingSets(); for (IWorkingSet workingSet : workingSetArray) { - if (workingSet.getId().equals(IGradleCompositeIDs.NATURE)) { + if (!workingSet.isAggregateWorkingSet() && workingSet.getId().equals(IGradleCompositeIDs.NATURE)) { composites.add(workingSet); } } - compositeSelectionListViewer.setInput(composites); + compositeSelectionListViewer.setInput(composites); + compositeSelectionListViewer.addSelectionChangedListener(e -> selectionChanged()); + } + + private Object selectionChanged() { + IStructuredSelection selection = (IStructuredSelection) compositeSelectionListViewer.getSelection(); + this.removeButton.setEnabled(!selection.isEmpty()); + this.editButton.setEnabled(selection.size() == 1); + return null; } private Composite createComponents(Composite parent) { @@ -93,7 +128,7 @@ private Composite createComponents(Composite parent) { private void createBottomButtonContainer(Composite container) { Composite buttonContainer = new Composite(container, SWT.NONE); buttonContainer.setLayout(LayoutUtils.newGridLayout(3)); - buttonContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1)); + buttonContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); this.newButton = new Button(buttonContainer, SWT.PUSH); this.newButton.setText("New..."); //TODO (kuzniarz) Replace String with constant this.newButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); @@ -101,10 +136,12 @@ private void createBottomButtonContainer(Composite container) { this.editButton = new Button(buttonContainer, SWT.PUSH); this.editButton.setText("Edit..."); this.editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + this.editButton.setEnabled(false); this.removeButton = new Button(buttonContainer, SWT.PUSH); this.removeButton.setText("Remove"); this.removeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + this.removeButton.setEnabled(false); } private void createSideButtonContainer(Composite container) { @@ -122,11 +159,14 @@ private void createSideButtonContainer(Composite container) { private void createCompositeCheckboxList(Composite container) { this.compositeSelectionListViewer = CheckboxTableViewer.newCheckList(container, SWT.BORDER | SWT.MULTI); - this.compositeSelectionListViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + GridData data = new GridData(GridData.FILL_BOTH); + data.heightHint = 200; + data.widthHint = 250; + data.horizontalSpan = 2; + this.compositeSelectionListViewer.getTable().setLayoutData(data); } private void addListeners() { - // TODO Auto-generated method stub this.newButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -158,6 +198,23 @@ public void widgetSelected(SelectionEvent e) { } }); } + + protected ISelection getSelectedComposites() { + return this.compositeSelectionListViewer.getSelection(); + } + + protected void removeSelectedCompositesFromList(IStructuredSelection selection) { + List removedComposites = selection.toList(); + composites.removeAll(removedComposites); + this.compositeSelectionListViewer.refresh(); + } + + protected void addNewCreatedComposite(IWorkingSet workingSet) { + composites.add(workingSet); + this.compositeSelectionListViewer.add(workingSet); + this.compositeSelectionListViewer.setSelection(new StructuredSelection(workingSet), true); + this.compositeSelectionListViewer.setChecked(workingSet, true); + } protected void deselectAllWorkspaceComposites() { compositeSelectionListViewer.setCheckedElements(new Object[0]); diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeSelectionDialog.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeSelectionDialog.java index cc28071f2..69f03d801 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeSelectionDialog.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeSelectionDialog.java @@ -1,43 +1,98 @@ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jdt.internal.ui.workingsets.WorkingSetModel; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.IWorkingSetManager; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.IWorkingSetEditWizard; public class CompositeSelectionDialog extends AbstractCompositeDialog { + + private List removedWorkingSets = new ArrayList(); + private List addedWorkingSets = new ArrayList(); + private List editedWorkingSets = new ArrayList(); + private IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); + private IWorkingSet[] result; public CompositeSelectionDialog(Shell parentShell) { super(parentShell); this.setTitle(WorkspaceCompositeWizardMessages.Title_ConfigureGradleWorkspaceCompositeDialog); + IWorkingSet[] workingSets = getActiveWorkingSets(); + setSelection(workingSets); + result = workingSets; + } + + private IWorkingSet[] getActiveWorkingSets() { + return new IWorkingSet[0]; } @Override protected void createNewWorkspaceComposite() { - // TODO (kuzniarz) Open composite creation wizard - WizardDialog dialog = new WizardDialog(this.getShell(), new WorkspaceCompositeCreationWizard()); - dialog.open(); + WorkspaceCompositeCreationWizard wizard = new WorkspaceCompositeCreationWizard(); + WizardDialog dialog = new WizardDialog(this.getShell(), wizard); + dialog.create(); + if (dialog.open() == Window.OK) { + IWorkingSet workingSet= wizard.getComposite(); + addNewCreatedComposite(workingSet); + manager.addWorkingSet(workingSet); + addedWorkingSets.add(workingSet); + } } @Override protected void editWorkspaceComposite() { - // TODO (kuzniarz) Composite properties for selected composite should be opened - + IStructuredSelection selection = (IStructuredSelection) getSelectedComposites(); + IWorkingSetEditWizard wizard = manager.createWorkingSetEditWizard((IWorkingSet) selection.getFirstElement()); + WizardDialog dialog = new WizardDialog(this.getShell(), wizard); + dialog.create(); + if (dialog.open() == Window.OK) { + IWorkingSet workingSet= wizard.getSelection(); + editedWorkingSets.add(workingSet); + } } @Override protected void removeWorkspaceComposite() { - // TODO Auto-generated method stub - + IStructuredSelection selectedELements = (IStructuredSelection) getSelectedComposites(); + removedWorkingSets.addAll(selectedELements.toList()); + removeSelectedCompositesFromList(selectedELements); } @Override protected void okPressed() { - // TODO Auto-generated method stub + if (!removedWorkingSets.isEmpty()) { + for (Iterator it = removedWorkingSets.iterator(); it.hasNext();) { + IWorkingSet workingSet = it.next(); + manager.removeWorkingSet(workingSet); + it.remove(); + } + } + addedWorkingSets.clear(); + editedWorkingSets.clear(); + //TODO (kuzniarz) Enabling/Disabling composites in the workspace + System.out.println(result); super.okPressed(); } @Override protected void cancelPressed() { + if (!addedWorkingSets.isEmpty()) { + for (Iterator it = addedWorkingSets.iterator(); it.hasNext();) { + IWorkingSet workingSet = it.next(); + manager.removeWorkingSet(workingSet); + it.remove(); + } + } + //restore edited composites // TODO Auto-generated method stub super.cancelPressed(); } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeCreationWizard.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeCreationWizard.java index 0e50c7bd7..cb534e63d 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeCreationWizard.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeCreationWizard.java @@ -15,6 +15,7 @@ import org.eclipse.jface.wizard.IWizardContainer; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.IWorkingSetManager; import org.eclipse.ui.PlatformUI; @@ -41,6 +42,8 @@ public final class WorkspaceCompositeCreationWizard extends AbstractWorkspaceCom private final CompositeCreationWizardController creationController; private final CompositeRootProjectWizardController rootProjectController; + private IWorkingSet composite; + // working set manager private IWorkingSetManager workingSetManager; @@ -107,7 +110,9 @@ public void addPages() { @Override public boolean performFinish() { - return this.importController.performCreateComposite(getContainer(), this.workingSetManager); + boolean finished = this.importController.performCreateComposite(getContainer(), this.workingSetManager); + composite = this.importController.getWorkingSet(); + return finished; } @Override @@ -132,4 +137,8 @@ private static IDialogSettings getOrCreateDialogSection(IDialogSettings dialogSe } return section; } + + public IWorkingSet getComposite() { + return this.composite; + } } diff --git a/org.eclipse.buildship.ui/src/main/resources/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.properties b/org.eclipse.buildship.ui/src/main/resources/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.properties index a986b5264..816ce8bc6 100644 --- a/org.eclipse.buildship.ui/src/main/resources/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.properties +++ b/org.eclipse.buildship.ui/src/main/resources/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.properties @@ -17,7 +17,7 @@ Title_NewGradleWorkspaceCompositeWizardPage=Gradle Workspace Composite Title_NewGradleImportOptionsWizardPage=Import Options Title_NewGradleCompositeRootWizardPage=Composite Root -Title_ConfigureGradleWorkspaceCompositeDialog=Configure Composite +Title_ConfigureGradleWorkspaceCompositeDialog=Configure Composites Label_CompositeName=Composite name