Skip to content

Commit

Permalink
Implemented Composite Configuration GUI
Browse files Browse the repository at this point in the history
- composite selection is not implemented yet

Signed-off-by: kuzniarz <[email protected]>
  • Loading branch information
kuzniarz committed Jun 23, 2020
1 parent c31e786 commit 85ba1cd
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,19 @@ 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) {
gradleComposite = workingSetManager.createWorkingSet(workspaceCompositeName, compositeElements);
gradleComposite.setId(IGradleCompositeIDs.NATURE);
} else {
IAdaptable[] oldElements = gradleComposite.getElements();
oldWorkspaceCompositeName = gradleComposite.getName();
if (!gradleComposite.getName().equals(this.workspaceCompositeNameText.getText())) {
gradleComposite.setName(this.workspaceCompositeNameText.getText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -32,6 +40,8 @@ public abstract class AbstractCompositeDialog extends SelectionDialog {
private Button selectAllButton;
private Button deselectAllButton;
private CheckboxTableViewer compositeSelectionListViewer;
private TableViewer viewer;
List<IWorkingSet> composites = new ArrayList<IWorkingSet>();
private ColumnLabelProvider labelProvider = new ColumnLabelProvider() {
private Map<ImageDescriptor, Image> icons = new Hashtable<>();
@Override
Expand All @@ -54,31 +64,56 @@ public Image getImage(Object element) {
return icon;
}
};
private IStructuredContentProvider contentProvider;

protected AbstractCompositeDialog(Shell parentShell) {
super(parentShell);
contentProvider = new ArrayContentProvider();
}

@Override
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<IWorkingSet> composites = new ArrayList<IWorkingSet>();
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) {
Expand All @@ -93,18 +128,20 @@ 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));

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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -158,6 +198,23 @@ public void widgetSelected(SelectionEvent e) {
}
});
}

protected ISelection getSelectedComposites() {
return this.compositeSelectionListViewer.getSelection();
}

protected void removeSelectedCompositesFromList(IStructuredSelection selection) {
List<IWorkingSet> 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]);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IWorkingSet> removedWorkingSets = new ArrayList<IWorkingSet>();
private List<IWorkingSet> addedWorkingSets = new ArrayList<IWorkingSet>();
private List<IWorkingSet> editedWorkingSets = new ArrayList<IWorkingSet>();
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<IWorkingSet> 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<IWorkingSet> it = addedWorkingSets.iterator(); it.hasNext();) {
IWorkingSet workingSet = it.next();
manager.removeWorkingSet(workingSet);
it.remove();
}
}
//restore edited composites
// TODO Auto-generated method stub
super.cancelPressed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -132,4 +137,8 @@ private static IDialogSettings getOrCreateDialogSection(IDialogSettings dialogSe
}
return section;
}

public IWorkingSet getComposite() {
return this.composite;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 85ba1cd

Please sign in to comment.