From 69c7f2bd60640e376d3c8350f093a2b47e5b0c51 Mon Sep 17 00:00:00 2001 From: Sebastian Kuzniarz Date: Fri, 12 Apr 2019 13:18:59 +0200 Subject: [PATCH 01/15] Implemented no-op UIs for workspace-composite wizard + preferences (#867) * Implemented no-op UIs for workspace-composite wizard + preferences * Changed workspace composite wizard element name * Changed composite wizard element description * Fixed java doc and useless indent * Javadoc/author fix+ line nitpick * Remove UiBuilder * Fixed indend * Fixed javadoc and indent * Remove UiBuilder/JavaDoc fix * Fixed checkbox tree layout * Refactor HelpContextIdProvider and WizardHelper * Knitpick and format fix Signed-off-by: kuzniarz --- org.eclipse.buildship.ui/plugin.xml | 22 +++ ...eCompositeImportOptionsPreferencePage.java | 133 +++++++++++++ ...dleCompositeRootProjectPreferencePage.java | 93 +++++++++ ...radleWorkspaceCompositePreferencePage.java | 71 +++++++ .../util/widget/GradleProjectGroup.java | 87 +++++++++ .../ui/internal/util/widget/UiBuilder.java | 33 ++++ .../{project => }/HelpContextIdProvider.java | 2 +- .../wizard/{project => }/WizardHelper.java | 4 +- .../wizard/project/AbstractProjectWizard.java | 1 + .../wizard/project/AbstractWizardPage.java | 1 + .../ProjectImportWizardController.java | 1 + .../project/ProjectPreviewWizardPage.java | 1 + .../AbstractWizardPage.java | 180 ++++++++++++++++++ .../AbstractWorkspaceCompositeWizard.java | 75 ++++++++ ...dleCreateWorkspaceCompositeWizardPage.java | 71 +++++++ .../GradleImportOptionsWizardPage.java | 80 ++++++++ .../GradleRootProjectWizardPage.java | 102 ++++++++++ .../WorkspaceCompositeCreationWizard.java | 129 +++++++++++++ .../WorkspaceCompositeWizardMessages.java | 61 ++++++ ...orkspaceCompositeWizardMessages.properties | 39 ++++ 20 files changed, 1183 insertions(+), 3 deletions(-) create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java rename org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/{project => }/HelpContextIdProvider.java (92%) rename org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/{project => }/WizardHelper.java (89%) create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractWizardPage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractWorkspaceCompositeWizard.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleImportOptionsWizardPage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleRootProjectWizardPage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeCreationWizard.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java create mode 100644 org.eclipse.buildship.ui/src/main/resources/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.properties diff --git a/org.eclipse.buildship.ui/plugin.xml b/org.eclipse.buildship.ui/plugin.xml index 1b1d329b72..855661ab97 100644 --- a/org.eclipse.buildship.ui/plugin.xml +++ b/org.eclipse.buildship.ui/plugin.xml @@ -51,6 +51,28 @@ name="Gradle"> + + + + + + Create a new Gradle workspace composite. + + + + + + distributionValidator; + private final Validator javaHomeValidator; + private final Validator gradleUserHomeValidator; + + public GradleCompositeImportOptionsPreferencePage() { + this.gradleUserHomeValidator = Validators.optionalDirectoryValidator("Gradle user home"); + this.javaHomeValidator = Validators.optionalDirectoryValidator("Java home"); + this.distributionValidator = GradleDistributionViewModel.validator(); + } + + @Override + protected Control createContents(Composite parent) { + this.gradleProjectSettingsComposite = GradleProjectSettingsComposite.builder(parent) + .withAutoSyncCheckbox() + .withOverrideCheckbox("Override workspace settings", "Configure Workspace Settings") + .build(); + initValues(); + addListeners(); + return this.gradleProjectSettingsComposite; + } + + private void initValues() { + IProject project = getTargetProject(); + BuildConfiguration buildConfig = CorePlugin.configurationManager().loadProjectConfiguration(project).getBuildConfiguration(); + boolean overrideWorkspaceSettings = buildConfig.isOverrideWorkspaceSettings(); + this.gradleProjectSettingsComposite.getGradleDistributionGroup().setDistribution(GradleDistributionViewModel.from(buildConfig.getGradleDistribution())); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setGradleUserHome(buildConfig.getGradleUserHome()); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setJavaHome(buildConfig.getJavaHome()); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setArguments(buildConfig.getArguments()); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setJvmArguments(buildConfig.getJvmArguments()); + this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().setSelection(overrideWorkspaceSettings); + this.gradleProjectSettingsComposite.getBuildScansCheckbox().setSelection(buildConfig.isBuildScansEnabled()); + this.gradleProjectSettingsComposite.getOfflineModeCheckbox().setSelection(buildConfig.isOfflineMode()); + this.gradleProjectSettingsComposite.getAutoSyncCheckbox().setSelection(buildConfig.isAutoSync()); + this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().setSelection(buildConfig.isShowConsoleView()); + this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().setSelection(buildConfig.isShowExecutionsView()); + this.gradleProjectSettingsComposite.updateEnablement(); + } + + private void addListeners() { + this.gradleProjectSettingsComposite.getParentPreferenceLink().addSelectionListener(new WorkbenchPreferenceOpeningSelectionListener()); + AdvancedOptionsGroup advancedOptionsGroup = this.gradleProjectSettingsComposite.getAdvancedOptionsGroup(); + advancedOptionsGroup.getGradleUserHomeText().addModifyListener(new ValidatingListener<>(this, () -> advancedOptionsGroup.getGradleUserHome(), this.gradleUserHomeValidator)); + advancedOptionsGroup.getJavaHomeText().addModifyListener(new ValidatingListener<>(this, () -> advancedOptionsGroup.getJavaHome(), this.javaHomeValidator)); + this.gradleProjectSettingsComposite.getGradleDistributionGroup().addDistributionChangedListener(new GradleDistributionValidatingListener(this, this.distributionValidator)); + } + + @Override + public boolean performOk() { + IProject project = getTargetProject(); + ConfigurationManager manager = CorePlugin.configurationManager(); + BuildConfiguration currentConfig = manager.loadProjectConfiguration(project).getBuildConfiguration(); + BuildConfiguration updatedConfig = manager.createBuildConfiguration(currentConfig.getRootProjectDirectory(), + this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getGradleDistributionGroup().getDistribution().toGradleDistribution(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getGradleUserHome(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJavaHome(), + this.gradleProjectSettingsComposite.getBuildScansCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getOfflineModeCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getAutoSyncCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getArguments(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJvmArguments(), + this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().getSelection()); + manager.saveBuildConfiguration(updatedConfig); + return true; + } + + @SuppressWarnings("cast") + private IProject getTargetProject() { + return (IProject) Platform.getAdapterManager().getAdapter(getElement(), IProject.class); + } + + /** + * Opens the workspace preferences dialog. + */ + private class WorkbenchPreferenceOpeningSelectionListener implements SelectionListener { + + @Override + public void widgetSelected(SelectionEvent e) { + openWorkspacePreferences(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + openWorkspacePreferences(); + } + + private void openWorkspacePreferences() { + PreferencesUtil.createPreferenceDialogOn(getShell(), GradleWorkbenchPreferencePage.PAGE_ID, null, null).open(); + } + } +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java new file mode 100644 index 0000000000..6570fd72b4 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2017 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.eclipse.buildship.ui.internal.preferences; + +import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Layout; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.PropertyPage; + +/** + * Preference page for composite root project. + * + * @author Sebastian Kuzniarz + */ + +public final class GradleCompositeRootProjectPreferencePage extends PropertyPage { + + public static final String PAGE_ID = "org.eclipse.buildship.ui.compositeRootProjectProperties"; + + private Text workspaceCompositeRootProjectLabel; + private Text overrideCheckboxLabel; + private Button overrideSettingsCheckbox; + private Button selectRootProject; + private Composite rootProjectSettingsComposite; + private Label rootProjectLabel; + + private Layout createLayout() { + GridLayout layout = LayoutUtils.newGridLayout(2); + layout.horizontalSpacing = 4; + layout.verticalSpacing = 4; + return layout; + } + + @Override + protected Control createContents(Composite parent) { + + this.rootProjectSettingsComposite = new Composite(parent, SWT.NONE); + rootProjectSettingsComposite.setLayout(createLayout()); + + this.overrideSettingsCheckbox = new Button(rootProjectSettingsComposite, SWT.CHECK); + this.overrideSettingsCheckbox.setText("Use project as composite root"); + GridDataFactory.swtDefaults().applyTo(rootProjectSettingsComposite); + + Label line = new Label(rootProjectSettingsComposite, SWT.SEPARATOR | SWT.HORIZONTAL); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).applyTo(line); + + // composite root container + Composite workspaceCompositeNameComposite = new Composite(rootProjectSettingsComposite, SWT.NONE); + GridLayoutFactory.swtDefaults().extendedMargins(0, 0, 0, 10).numColumns(3).applyTo(workspaceCompositeNameComposite); + GridDataFactory.swtDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).span(3, SWT.DEFAULT).applyTo(workspaceCompositeNameComposite); + + // root project label + this.rootProjectLabel = new Label(workspaceCompositeNameComposite, SWT.NONE); + this.rootProjectLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + this.rootProjectLabel.setText(WorkspaceCompositeWizardMessages.Label_RootProject); + + // root project text field + this.workspaceCompositeRootProjectLabel = new Text(workspaceCompositeNameComposite, SWT.BORDER); + this.workspaceCompositeRootProjectLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + // root project select button + this.selectRootProject = new Button(workspaceCompositeNameComposite, SWT.PUSH); + this.selectRootProject.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + this.selectRootProject.setText(WorkspaceCompositeWizardMessages.Button_Select_RootProject); + return rootProjectSettingsComposite; + } + + @Override + public void dispose() { + super.dispose(); + } + + @Override + public boolean performOk() { + return true; + } +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java new file mode 100644 index 0000000000..34d0b5a146 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.eclipse.buildship.ui.internal.preferences; + +import org.eclipse.buildship.ui.internal.util.font.FontUtils; +import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; +import org.eclipse.buildship.ui.internal.util.widget.GradleProjectGroup; +import org.eclipse.buildship.ui.internal.util.widget.UiBuilder; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.PropertyPage; + +/** + * Preference page for workspace composite configuration + * + * @author Sebastian Kuzniarz + */ +@SuppressWarnings("unused") +public final class GradleWorkspaceCompositePreferencePage extends PropertyPage { + + public static final String PAGE_ID = "org.eclipse.buildship.ui.compositeproperties"; + + private Text workspaceCompositeNameText; + private Label compositeName; + private GradleProjectGroup gradleProjectCheckboxtreeComposite; + private Composite gradleWorkspaceCompositeSettingsComposite; + + @Override + protected Control createContents(Composite parent) { + this.gradleWorkspaceCompositeSettingsComposite = new Composite(parent, SWT.FILL); + gradleWorkspaceCompositeSettingsComposite.setLayout(LayoutUtils.newGridLayout(2)); + + // composite name container + Composite workspaceCompositeNameComposite = new Composite(gradleWorkspaceCompositeSettingsComposite, SWT.FILL); + GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 5).numColumns(2).applyTo(workspaceCompositeNameComposite); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).span(3, SWT.DEFAULT).applyTo(workspaceCompositeNameComposite); + + // composite name label + this.compositeName = new Label(workspaceCompositeNameComposite, SWT.NONE); + this.compositeName.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + this.compositeName.setText(WorkspaceCompositeWizardMessages.Label_CompositeName); + + // composite name text field + this.workspaceCompositeNameText = new Text(workspaceCompositeNameComposite, SWT.BORDER); + this.workspaceCompositeNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(gradleWorkspaceCompositeSettingsComposite); + GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(3, SWT.DEFAULT).applyTo(this.gradleProjectCheckboxtreeComposite); + + return gradleWorkspaceCompositeSettingsComposite; + } + + @Override + public boolean performOk() { + return true; + } +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java new file mode 100644 index 0000000000..2bd1a42502 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2015 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - initial UI implementation + */ + +package org.eclipse.buildship.ui.internal.util.widget; + +import org.eclipse.buildship.ui.internal.util.gradle.GradleDistributionViewModel; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; + +@SuppressWarnings("unused") +public class GradleProjectGroup extends Group { + + private Font font; + private Button newGradleProject; + private Button addExternalGradleProject; + private Composite buttonComposite; + private Tree gradleProjectTree; + + public GradleProjectGroup(Composite parent) { + super(parent, SWT.NONE); + setText(WorkspaceCompositeWizardMessages.Group_Label_GradleProjects); + createWidgets(); + } + + public void createWidgets() { + setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayoutFactory.swtDefaults().numColumns(4).applyTo(this); + + this.gradleProjectTree = new Tree(this, SWT.CHECK); + this.gradleProjectTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + + this.buttonComposite = new Composite(this, SWT.NONE); + this.buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1)); + GridLayoutFactory.fillDefaults().numColumns(1).applyTo(buttonComposite); + + this.newGradleProject = new Button(buttonComposite, SWT.PUSH); + this.newGradleProject.setText(WorkspaceCompositeWizardMessages.Button_New_GradleProject); + this.newGradleProject.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + this.addExternalGradleProject = new Button(buttonComposite, SWT.PUSH); + this.addExternalGradleProject.setText(WorkspaceCompositeWizardMessages.Button_Add_ExternalGradleProject); + this.addExternalGradleProject.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + fillCheckboxTreeWithFakeData(); + } + + + private void fillCheckboxTreeWithFakeData() { + for (int i = 0; i < 4; i++) { + TreeItem iItem = new TreeItem(this.gradleProjectTree, 0); + iItem.setText("TreeItem (0) -" + i); + for (int j = 0; j < 4; j++) { + TreeItem jItem = new TreeItem(iItem, 0); + jItem.setText("TreeItem (1) -" + j); + for (int k = 0; k < 4; k++) { + TreeItem kItem = new TreeItem(jItem, 0); + kItem.setText("TreeItem (2) -" + k); + for (int l = 0; l < 4; l++) { + TreeItem lItem = new TreeItem(kItem, 0); + lItem.setText("TreeItem (3) -" + l); + } + } + } + } + } + + @Override + protected void checkSubclass() { + // Disable the check that prevents subclassing of SWT components + } +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/UiBuilder.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/UiBuilder.java index ecc1c7e1cb..f6a936b538 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/UiBuilder.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/UiBuilder.java @@ -84,6 +84,16 @@ public UiBuilder alignFillHorizontal() { this.control.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); return this; } + + /** + * Aligns the created widget to fill the cell vertically aligned at top. + * + * @return the builder + */ + public UiBuilder alignFillVerticalTop() { + this.control.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1)); + return this; + } /** * Aligns the created widget to fill both horizontal and vertical. @@ -176,6 +186,17 @@ public UiBuilder - - - - - - Create a new Gradle workspace composite. - - - - - - - - - - - - + + @@ -428,6 +419,10 @@ type="org.eclipse.ui.views.properties.IPropertySource"> + + @@ -451,75 +446,84 @@ + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + point="org.eclipse.ui.menus"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + ifEmpty="false" + operator="or"> + + + + + + - - - + + + @@ -592,6 +596,31 @@ + + + + + + + + + + + + + + + + + + @@ -636,6 +665,39 @@ + + + + + + + + + + + + + + + + + + @@ -648,6 +710,17 @@ + + + + + @@ -658,4 +731,30 @@ + + + + + + + + + + + + + + + diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/composite/WorkingSetProperyTester.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/composite/WorkingSetProperyTester.java new file mode 100644 index 0000000000..36da6eef8b --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/composite/WorkingSetProperyTester.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.eclipse.buildship.ui.internal.composite; + +import org.eclipse.ui.IWorkingSet; +import org.eclipse.buildship.core.internal.GradlePluginsRuntimeException; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.IGradleCompositeIDs; + +/** + * Property tester to determine if the test launch shortcut should be visible in the context menus. + */ +public final class WorkingSetProperyTester extends org.eclipse.core.expressions.PropertyTester { + + private static final String PROPERTY_NAME_IS_GRADLE_COMPOSITE_ID = "gradlecomposite"; + private static final String GRADLE_COMPOSITE_ID = IGradleCompositeIDs.NATURE; + + @Override + public boolean test(Object receiver, String propertyString, Object[] args, Object expectedValue) { + if (propertyString.equals(PROPERTY_NAME_IS_GRADLE_COMPOSITE_ID)) { + return receiver instanceof IWorkingSet && isGradleComposite((IWorkingSet)receiver); + } else { + throw new GradlePluginsRuntimeException("Unrecognized property to test: " + propertyString); + } + } + + private boolean isGradleComposite(IWorkingSet workingSet) { + try { + return workingSet.getId().equals(GRADLE_COMPOSITE_ID); + } catch (Exception e) { + return false; + } + } + +} + diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/AbstractPropertiesPage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/AbstractPropertiesPage.java new file mode 100644 index 0000000000..57372c91c1 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/AbstractPropertiesPage.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2015 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Etienne Studer & Donát Csikós (Gradle Inc.) - initial API and implementation and initial documentation + * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - refactored HelpContextIdProvider + */ + +package org.eclipse.buildship.ui.internal.preferences; + +import java.util.List; + +import org.eclipse.buildship.core.internal.util.binding.Property; +import org.eclipse.buildship.ui.internal.wizard.HelpContextIdProvider; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.CompositeConfiguration; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.GradleCreateWorkspaceCompositeWizardPage; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeCreationWizard; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PlatformUI; + +/** + * Common base class for all pages in the {@link WorkspaceCompositeCreationWizard}. + */ +public abstract class AbstractPropertiesPage extends WizardPage { + + private final CompositeConfiguration configuration; + + /** + * Constructor setting up the main messages and the validation facility for this wizard page. + * + * @param name the name of the page + * @param title the page title + * @param defaultMessage the default message to show when there is no validation error + * @param configuration the data model of the wizard + * @param observedProperties the subset of the properties from the data model that are managed + * on this page + */ + protected AbstractPropertiesPage(String name, String title, String defaultMessage, CompositeConfiguration configuration, final List> observedProperties) { + super(name); + + this.configuration = configuration; + + // set the basic message and the attached image + setTitle(title); + setDescription(defaultMessage); + setImageDescriptor(ImageDescriptor.createFromFile(GradleCreateWorkspaceCompositeWizardPage.class, "/icons/full/wizban/wizard.png")); //$NON-NLS-1$ + } + + protected CompositeConfiguration getConfiguration() { + return this.configuration; + } + + @Override + public void createControl(Composite parent) { + // align dialog units to the current resolution + initializeDialogUnits(parent); + + // create the container control + Composite pageControl = createWizardPageContent(parent); + + // assign the created control to the wizard page + setControl(pageControl); + } + + private Composite createWizardPageContent(Composite parent) { + // create a scrollable root to handle resizing + ScrolledComposite externalRoot = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); + externalRoot.setExpandHorizontal(true); + externalRoot.setExpandVertical(true); + externalRoot.setMinSize(new Point(230, 380)); + + // add the controls inside the root composite + Composite container = new Composite(externalRoot, SWT.NONE); + createWidgets(container); + + // also compute the size of the container, otherwise the ScrolledComposite's content is not + // rendered properly + Point containerSize = container.computeSize(SWT.DEFAULT, SWT.DEFAULT); + container.setSize(containerSize); + + // set the root's content and return it + externalRoot.setContent(container); + return externalRoot; + } + + /** + * Populates the widgets in the wizard page. + */ + protected abstract void createWidgets(Composite root); + + /** + * Returns text to display under the widgets. If {@code null} or empty then nothing is displayed. + * + * @return explanation text for for the wizard page + */ + protected abstract String getPageContextInformation(); + + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + + // every time the page becomes visible, set the proper help context, this is required since + // the user could navigate back to the initial Eclipse import page which sets another help + // context + if (visible) { + if (getWizard() instanceof HelpContextIdProvider) { + String helpContextId = ((HelpContextIdProvider) getWizard()).getHelpContextId(); + PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), helpContextId); + } + } + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java index c1e74bbc38..f0331fe736 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java @@ -14,18 +14,21 @@ import org.eclipse.buildship.core.internal.CorePlugin; import org.eclipse.buildship.core.internal.configuration.BuildConfiguration; +import org.eclipse.buildship.core.internal.configuration.CompositeConfiguration; import org.eclipse.buildship.core.internal.configuration.ConfigurationManager; +import org.eclipse.buildship.core.internal.configuration.DefaultCompositeConfiguration; import org.eclipse.buildship.core.internal.util.binding.Validator; import org.eclipse.buildship.core.internal.util.binding.Validators; import org.eclipse.buildship.ui.internal.util.gradle.GradleDistributionViewModel; import org.eclipse.buildship.ui.internal.util.widget.AdvancedOptionsGroup; import org.eclipse.buildship.ui.internal.util.widget.GradleProjectSettingsComposite; -import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Platform; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbenchPropertyPage; +import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.dialogs.PreferencesUtil; import org.eclipse.ui.dialogs.PropertyPage; @@ -34,7 +37,7 @@ * * @author Sebastian Kuzniarz */ -public final class GradleCompositeImportOptionsPreferencePage extends PropertyPage { +public final class GradleCompositeImportOptionsPreferencePage extends PropertyPage implements IWorkbenchPropertyPage{ public static final String PAGE_ID = "org.eclipse.buildship.ui.compositeImportOptionsProperties"; @@ -62,8 +65,10 @@ protected Control createContents(Composite parent) { } private void initValues() { - IProject project = getTargetProject(); - BuildConfiguration buildConfig = CorePlugin.configurationManager().loadProjectConfiguration(project).getBuildConfiguration(); + IWorkingSet composite = getTargetComposite(); + + BuildConfiguration buildConfig = CorePlugin.configurationManager().loadCompositeConfiguration(composite).getBuildConfiguration(); + boolean overrideWorkspaceSettings = buildConfig.isOverrideWorkspaceSettings(); this.gradleProjectSettingsComposite.getGradleDistributionGroup().setDistribution(GradleDistributionViewModel.from(buildConfig.getGradleDistribution())); this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setGradleUserHome(buildConfig.getGradleUserHome()); @@ -77,6 +82,7 @@ private void initValues() { this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().setSelection(buildConfig.isShowConsoleView()); this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().setSelection(buildConfig.isShowExecutionsView()); this.gradleProjectSettingsComposite.updateEnablement(); + } private void addListeners() { @@ -89,28 +95,30 @@ private void addListeners() { @Override public boolean performOk() { - IProject project = getTargetProject(); - ConfigurationManager manager = CorePlugin.configurationManager(); - BuildConfiguration currentConfig = manager.loadProjectConfiguration(project).getBuildConfiguration(); - BuildConfiguration updatedConfig = manager.createBuildConfiguration(currentConfig.getRootProjectDirectory(), - this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().getSelection(), - this.gradleProjectSettingsComposite.getGradleDistributionGroup().getDistribution().toGradleDistribution(), - this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getGradleUserHome(), - this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJavaHome(), - this.gradleProjectSettingsComposite.getBuildScansCheckbox().getSelection(), - this.gradleProjectSettingsComposite.getOfflineModeCheckbox().getSelection(), - this.gradleProjectSettingsComposite.getAutoSyncCheckbox().getSelection(), - this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getArguments(), - this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJvmArguments(), - this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().getSelection(), - this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().getSelection()); - manager.saveBuildConfiguration(updatedConfig); - return true; + IWorkingSet composite = getTargetComposite(); + ConfigurationManager manager = CorePlugin.configurationManager(); + CompositeConfiguration currentConfig = manager.loadCompositeConfiguration(composite); + + BuildConfiguration updatedConfig = manager.createBuildConfiguration(currentConfig.getBuildConfiguration().getRootProjectDirectory(), + this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getGradleDistributionGroup().getDistribution().toGradleDistribution(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getGradleUserHome(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJavaHome(), + this.gradleProjectSettingsComposite.getBuildScansCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getOfflineModeCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getAutoSyncCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getArguments(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJvmArguments(), + this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().getSelection()); + CompositeConfiguration compConf = new DefaultCompositeConfiguration(currentConfig.getCompositeDir(), composite.getElements(), updatedConfig, currentConfig.projectAsCompositeRoot() ,currentConfig.getRootProject()); + manager.saveCompositeConfiguration(compConf); + return true; } @SuppressWarnings("cast") - private IProject getTargetProject() { - return (IProject) Platform.getAdapterManager().getAdapter(getElement(), IProject.class); + private IWorkingSet getTargetComposite() { + return (IWorkingSet) Platform.getAdapterManager().getAdapter(getElement(), IWorkingSet.class); } /** diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java index 1afc18af35..9657c360c7 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java @@ -10,9 +10,14 @@ package org.eclipse.buildship.ui.internal.preferences; +import java.io.File; + +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -21,8 +26,17 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Layout; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbenchPropertyPage; +import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.dialogs.PropertyPage; +import org.eclipse.buildship.core.internal.CorePlugin; +import org.eclipse.buildship.core.internal.configuration.CompositeConfiguration; +import org.eclipse.buildship.core.internal.configuration.ConfigurationManager; +import org.eclipse.buildship.core.internal.configuration.DefaultCompositeConfiguration; +import org.eclipse.buildship.core.internal.util.binding.Validator; +import org.eclipse.buildship.core.internal.util.binding.Validators; +import org.eclipse.buildship.ui.internal.util.file.DirectoryDialogSelectionListener; import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; @@ -32,17 +46,20 @@ * @author Sebastian Kuzniarz */ -public final class GradleCompositeRootProjectPreferencePage extends PropertyPage { +public final class GradleCompositeRootProjectPreferencePage extends PropertyPage implements IWorkbenchPropertyPage{ public static final String PAGE_ID = "org.eclipse.buildship.ui.compositeRootProjectProperties"; private Text workspaceCompositeRootProjectLabel; - private Text overrideCheckboxLabel; - private Button overrideSettingsCheckbox; + private Button projectAsCompositeRootCheckbox; private Button selectRootProject; private Composite rootProjectSettingsComposite; private Label rootProjectLabel; + + private final Validator rootProjectValidator; + CompositeConfiguration compositeConfig; + private Layout createLayout() { GridLayout layout = LayoutUtils.newGridLayout(2); layout.horizontalSpacing = 4; @@ -50,21 +67,31 @@ private Layout createLayout() { return layout; } + public GradleCompositeRootProjectPreferencePage() { + this.rootProjectValidator = Validators.optionalDirectoryValidator("Root project"); + } + @Override protected Control createContents(Composite parent) { + this.rootProjectSettingsComposite = buildRootProjectSettingsComposite(parent); + addListeners(); + initValues(); + return this.rootProjectSettingsComposite; + } - this.rootProjectSettingsComposite = new Composite(parent, SWT.NONE); - this.rootProjectSettingsComposite.setLayout(createLayout()); + private Composite buildRootProjectSettingsComposite(Composite parent) { + Composite rootProjectComposite = new Composite(parent, SWT.WRAP); + rootProjectComposite.setLayout(createLayout()); - this.overrideSettingsCheckbox = new Button(this.rootProjectSettingsComposite, SWT.CHECK); - this.overrideSettingsCheckbox.setText("Use project as composite root"); - GridDataFactory.swtDefaults().applyTo(this.rootProjectSettingsComposite); + this.projectAsCompositeRootCheckbox = new Button(rootProjectComposite, SWT.CHECK); + this.projectAsCompositeRootCheckbox.setText("Use project as composite root"); + GridDataFactory.swtDefaults().applyTo(rootProjectComposite); - Label line = new Label(this.rootProjectSettingsComposite, SWT.SEPARATOR | SWT.HORIZONTAL); + Label line = new Label(rootProjectComposite, SWT.SEPARATOR | SWT.HORIZONTAL); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).applyTo(line); // composite root container - Composite workspaceCompositeNameComposite = new Composite(this.rootProjectSettingsComposite, SWT.NONE); + Composite workspaceCompositeNameComposite = new Composite(rootProjectComposite, SWT.NONE); GridLayoutFactory.swtDefaults().extendedMargins(0, 0, 0, 10).numColumns(3).applyTo(workspaceCompositeNameComposite); GridDataFactory.swtDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).span(3, SWT.DEFAULT).applyTo(workspaceCompositeNameComposite); @@ -72,16 +99,66 @@ protected Control createContents(Composite parent) { this.rootProjectLabel = new Label(workspaceCompositeNameComposite, SWT.NONE); this.rootProjectLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); this.rootProjectLabel.setText(WorkspaceCompositeWizardMessages.Label_RootProject); + this.rootProjectLabel.setEnabled(false); // root project text field this.workspaceCompositeRootProjectLabel = new Text(workspaceCompositeNameComposite, SWT.BORDER); this.workspaceCompositeRootProjectLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + this.workspaceCompositeRootProjectLabel.setEnabled(false); // root project select button this.selectRootProject = new Button(workspaceCompositeNameComposite, SWT.PUSH); this.selectRootProject.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); this.selectRootProject.setText(WorkspaceCompositeWizardMessages.Button_Select_RootProject); - return this.rootProjectSettingsComposite; + this.selectRootProject.setEnabled(false); + return rootProjectComposite; + } + + private void initValues() { + IWorkingSet composite = getTargetComposite(); + + this.compositeConfig = CorePlugin.configurationManager().loadCompositeConfiguration(composite); + boolean useProjectAsCompositeRoot = this.compositeConfig.projectAsCompositeRoot(); + + this.projectAsCompositeRootCheckbox.setSelection(useProjectAsCompositeRoot); + this.workspaceCompositeRootProjectLabel.setText(this.compositeConfig.getRootProject().toString()); + updateEnablement(); + } + + private void addListeners() { + if (this.projectAsCompositeRootCheckbox != null) { + this.projectAsCompositeRootCheckbox.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + updateEnablement(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + updateEnablement(); + } + }); + + File rootProjectDir = this.workspaceCompositeRootProjectLabel.getText().isEmpty() ? null: new File(this.workspaceCompositeRootProjectLabel.getText()); + this.workspaceCompositeRootProjectLabel.addModifyListener(new ValidatingListener<>(this, () -> rootProjectDir, this.rootProjectValidator)); + + this.selectRootProject.addSelectionListener(new DirectoryDialogSelectionListener(this.getShell(), this.workspaceCompositeRootProjectLabel, "Root project")); + } + } + + public void updateEnablement() { + if (this.projectAsCompositeRootCheckbox != null) { + boolean enabled = this.projectAsCompositeRootCheckbox.getSelection(); + this.rootProjectLabel.setEnabled(enabled); + this.selectRootProject.setEnabled(enabled); + this.workspaceCompositeRootProjectLabel.setEnabled(enabled); + } + } + + @SuppressWarnings("cast") + private IWorkingSet getTargetComposite() { + return (IWorkingSet) Platform.getAdapterManager().getAdapter(getElement(), IWorkingSet.class); } @Override @@ -91,6 +168,16 @@ public void dispose() { @Override public boolean performOk() { - return true; + IWorkingSet composite = getTargetComposite(); + ConfigurationManager manager = CorePlugin.configurationManager(); + CompositeConfiguration currentConfig = manager.loadCompositeConfiguration(composite); + + CompositeConfiguration compConf = new DefaultCompositeConfiguration(currentConfig.getCompositeDir(), + composite.getElements(), + currentConfig.getBuildConfiguration(), + this.projectAsCompositeRootCheckbox.getSelection(), + new File(this.workspaceCompositeRootProjectLabel.getText())); + manager.saveCompositeConfiguration(compConf); + return true; } } 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 new file mode 100644 index 0000000000..6ea0fcf741 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCreateWorkspaceCompositePreferencePage.java @@ -0,0 +1,299 @@ +/* + * Copyright (c) 2015 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Simon Scholz (vogella GmbH) - initial API and implementation and initial documentation + * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - adaptation and customization for workspace composite wizard + */ + +package org.eclipse.buildship.ui.internal.preferences; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.eclipse.buildship.core.internal.CorePlugin; +import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; +import org.eclipse.buildship.ui.internal.util.widget.GradleProjectGroup; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.CompositeConfiguration; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.CompositeCreationConfiguration; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.CompositeCreationWizardController; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.CompositeImportWizardController; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.GradleImportOptionsWizardPage; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.IGradleCompositeIDs; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeCreationWizard; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.IWorkingSetManager; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.IWorkingSetPage; + +import com.google.common.collect.ImmutableList; + +/** + * Page on the {@link WorkspaceCompositeCreationWizard} declaring the workspace + * composite name and included projects. + */ +public final class GradleCreateWorkspaceCompositePreferencePage extends AbstractPropertiesPage + implements IWorkingSetPage { + + private final CompositeCreationConfiguration creationConfiguration; + + @SuppressWarnings("unused") + private Text workspaceCompositeNameText; + private Label compositeName; + private GradleProjectGroup gradleProjectCheckboxtreeComposite; + + private static IWorkingSet gradleComposite; + private boolean firstCheck; + private static CompositeImportWizardController importController; + + public GradleCreateWorkspaceCompositePreferencePage(CompositeConfiguration importConfiguration, + CompositeCreationConfiguration creationConfiguration) { + super("NewGradleWorkspaceComposite", //$NON-NLS-1$ + WorkspaceCompositeWizardMessages.Title_NewGradleWorkspaceCompositeWizardPage, + WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeWizardPageDefault, importConfiguration, ImmutableList.of(creationConfiguration.getCompositeName(), + creationConfiguration.getCompositeProjects())); + gradleComposite = null; + this.creationConfiguration = creationConfiguration; + firstCheck = true; + } + + public GradleCreateWorkspaceCompositePreferencePage() { + this(getCompositeImportConfiguration(), getCompositeCreationConfiguration()); + } + + private IWizardPage buildImportOptionsWizardPage() { + IWizardPage page = new GradleImportOptionsWizardPage(getConfiguration()); + page.setWizard(getWizard()); + return page; + } + + protected String getPageId() { + return "org.eclipse.buildship.ui.GradleCompositePage"; //$NON-NLS-1$ + } + + private static CompositeCreationConfiguration getCompositeCreationConfiguration() { + ArrayList compositeElements = new ArrayList(); + String compositeName = gradleComposite != null ? gradleComposite.getName() : ""; + CompositeCreationWizardController creationController = new CompositeCreationWizardController(compositeName, compositeElements); + return creationController.getConfiguration(); + } + + private static CompositeConfiguration getCompositeImportConfiguration() { + importController = new CompositeImportWizardController(null); + return importController.getConfiguration(); + } + + @Override + public void createControl(Composite parent) { + super.createControl(parent); + } + + @Override + protected void createWidgets(Composite root) { + root.setLayout(LayoutUtils.newGridLayout(3)); + createContent(root); + } + + private void createContent(Composite root) { + + // composite name container + Composite workspaceCompositeNameComposite = new Composite(root, SWT.FILL); + GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 5).numColumns(2) + .applyTo(workspaceCompositeNameComposite); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).span(3, SWT.DEFAULT) + .applyTo(workspaceCompositeNameComposite); + + // composite name label + this.compositeName = new Label(workspaceCompositeNameComposite, SWT.NONE); + this.compositeName.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + this.compositeName.setText(WorkspaceCompositeWizardMessages.Label_CompositeName); + + // composite name text field + this.workspaceCompositeNameText = new Text(workspaceCompositeNameComposite, SWT.BORDER); + this.workspaceCompositeNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(root, (gradleComposite != null)); + GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(3, SWT.DEFAULT) + .applyTo(this.gradleProjectCheckboxtreeComposite); + + addListeners(); + + if (gradleComposite != null) { + workspaceCompositeNameText.setText(gradleComposite.getName()); + } + } + + private void addListeners() { + this.workspaceCompositeNameText.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + updateLocation(); + validateInput(); + } + }); + this.gradleProjectCheckboxtreeComposite.getCheckboxTree().addListener(SWT.Selection, new Listener() { + + @Override + public void handleEvent(Event event) { + updateCompositeProjects(); + validateInput(); + } + }); + } + + protected void updateCompositeProjects() { + List projectList = new ArrayList(); + + for (TreeItem treeElement : gradleProjectCheckboxtreeComposite.getCheckboxTree().getItems()) { + if (treeElement.getChecked() == true) { + if (treeElement.getText().contains(" (External): ")) { + //String[] treeValues = treeElement.getText().replace(" (External): ", "$").split("\\$"); + // treeValues[0] contains the project name + // treeValues[1] contains the file path + //File externalFolder = new File(treeValues[1]); + projectList.add(null); + } else { + projectList.add(ResourcesPlugin.getWorkspace().getRoot().getProject(treeElement.getText())); + } + } + } + getConfiguration().getProjectList().setValue(projectList.toArray(new IAdaptable[projectList.size()])); + this.creationConfiguration.setCompositeProjects(projectList); + } + + private void updateLocation() { + File parentLocation = CorePlugin.getInstance().getStateLocation().append("workspace-composites").toFile(); + File projectDir = parentLocation != null ? new File(parentLocation, this.workspaceCompositeNameText.getText()) + : null; + + // always update project name last to ensure project name validation errors have + // precedence in the UI + getConfiguration().getCompositePreferencesDir().setValue(projectDir); + this.creationConfiguration.setCompositeName(this.workspaceCompositeNameText.getText()); + } + + @Override + protected String getPageContextInformation() { + return WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeWizardPageContext; + } + + @Override + public void finish() { + updateCompositeProjects(); + String workspaceCompositeName = workspaceCompositeNameText.getText(); + IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); + + try { + File compositePreferenceFile = CorePlugin.getInstance().getStateLocation() + .append("workspace-composites").append(workspaceCompositeName).toFile(); + + if (gradleComposite == null) { + gradleComposite = workingSetManager.createWorkingSet(workspaceCompositeName, + getConfiguration().getProjectList().getValue()); + gradleComposite.setId(IGradleCompositeIDs.NATURE); + } else { + IAdaptable[] oldElements = gradleComposite.getElements(); + if (!gradleComposite.getName().equals(workspaceCompositeNameText.getText())) { + gradleComposite.setName(workspaceCompositeNameText.getText()); + } + + if (!oldElements.equals(getConfiguration().getProjectList().getValue())) { + gradleComposite.setElements(getConfiguration().getProjectList().getValue()); + } + } + FileOutputStream out = new FileOutputStream(compositePreferenceFile.getAbsoluteFile()); + Properties prop = getConfiguration().toCompositeProperties().toProperties(); + prop.store(out, " "); + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + public IWorkingSet getSelection() { + return gradleComposite; + } + + @Override + public void setSelection(IWorkingSet workingSet) { + Assert.isNotNull(workingSet, "Composite must not be null"); //$NON-NLS-1$ + gradleComposite = workingSet; + if (getContainer() == null && getShell() != null && workspaceCompositeNameText != null) { + workspaceCompositeNameText.setText(gradleComposite.getName()); + } + } + + @Override + public IWizardPage getNextPage() { + return buildImportOptionsWizardPage(); + } + + protected void validateInput() { + String errorMessage = null; + String infoMessage = null; + String newText= workspaceCompositeNameText.getText(); + + if (newText.equals(newText.trim()) == false) + errorMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_NameWhitespaces; + if (newText.isEmpty()) { + if (firstCheck) { + setPageComplete(false); + firstCheck= false; + return; + } else + errorMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_NameEmpty; + } + + firstCheck= false; + + if (errorMessage == null && (gradleComposite == null || newText.equals(gradleComposite.getName()) == false)) { + IWorkingSet[] workingSets= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets(); + for (int i= 0; i < workingSets.length; i++) { + if (newText.equals(workingSets[i].getName())) { + errorMessage= WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_CompositeNameExists; + } + } + } + + if (!hasSelectedElement()) { + infoMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_CompositeEmpty; + } + + setMessage(infoMessage, INFORMATION); + setErrorMessage(errorMessage); + setPageComplete(errorMessage == null); + } + + private boolean hasSelectedElement() { + return this.creationConfiguration.getCompositeProjects().getValue().size() > 0; + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleDistributionValidatingListener.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleDistributionValidatingListener.java index 8921d41d0b..ff7aee82b8 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleDistributionValidatingListener.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleDistributionValidatingListener.java @@ -22,7 +22,7 @@ * * @author Donat Csikos */ -final class GradleDistributionValidatingListener implements DistributionChangedListener { +public final class GradleDistributionValidatingListener implements DistributionChangedListener { private final PreferencePage preferencePage; private final Validator distributionValidator; diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleProjectPreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleProjectPreferencePage.java index c87dbf2a93..ba2d14ae94 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleProjectPreferencePage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleProjectPreferencePage.java @@ -110,7 +110,7 @@ public boolean performOk() { return true; } - @SuppressWarnings({"cast", "RedundantCast"}) + @SuppressWarnings({"cast"}) private IProject getTargetProject() { return (IProject) Platform.getAdapterManager().getAdapter(getElement(), IProject.class); } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java index 63d52f0aa1..ae35c9a68c 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java @@ -58,7 +58,7 @@ protected Control createContents(Composite parent) { this.workspaceCompositeNameText = new Text(workspaceCompositeNameComposite, SWT.BORDER); this.workspaceCompositeNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(this.gradleWorkspaceCompositeSettingsComposite); + this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(this.gradleWorkspaceCompositeSettingsComposite, false); // TODO (donat) was this properly merged? GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(3, SWT.DEFAULT).applyTo(this.gradleProjectCheckboxtreeComposite); return this.gradleWorkspaceCompositeSettingsComposite; diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/ValidatingListener.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/ValidatingListener.java index d394b3ece3..00b3ee4a37 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/ValidatingListener.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/ValidatingListener.java @@ -23,7 +23,7 @@ * * @author Donat Csikos */ -final class ValidatingListener implements ModifyListener { +public final class ValidatingListener implements ModifyListener { private final PreferencePage preferencePage; private final Supplier target; diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/file/ExternalProjectDialogSelectionListener.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/file/ExternalProjectDialogSelectionListener.java new file mode 100644 index 0000000000..21447250cb --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/file/ExternalProjectDialogSelectionListener.java @@ -0,0 +1,107 @@ +package org.eclipse.buildship.ui.internal.util.file; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.eclipse.buildship.ui.internal.i18n.UiMessages; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TreeItem; + +import com.google.common.base.Preconditions; + +public class ExternalProjectDialogSelectionListener extends SelectionAdapter { + + + + private final Shell shell; + private final TreeViewer projectTreeViewer; + private final String title; + private final Map externalProjectPaths; + + public ExternalProjectDialogSelectionListener(Shell shell, TreeViewer treeViewer, String entity) { + + this.shell = Preconditions.checkNotNull(shell); + this.projectTreeViewer = treeViewer; + this.title = NLS.bind(UiMessages.Title_Select_0, entity); + ColumnViewerToolTipSupport.enableFor(projectTreeViewer); + externalProjectPaths = new HashMap(); + } + + @Override + public void widgetSelected(SelectionEvent e) { + DirectoryDialog directoryDialog = new DirectoryDialog(this.shell, SWT.SHEET); + directoryDialog.setText(this.title); + + String userHomeDir = System.getProperty("user.home"); + directoryDialog.setFilterPath(userHomeDir); + + String selectedDirectory = directoryDialog.open(); + if (selectedDirectory != null) { + addExternalProjectToProjectTree(selectedDirectory); + } + } + + private void addExternalProjectToProjectTree(String selectedDirectory) { + String projectDir = selectedDirectory; + File gradleSettingsFile = getGradleSettings(projectDir); + if (gradleSettingsFile.isFile()) { + try { + FileInputStream inputStream = new FileInputStream(gradleSettingsFile); + Properties gradleSettings = new Properties(); + gradleSettings.load(inputStream); + String projectName = getProjectName(gradleSettings); + TreeItem jItem = new TreeItem(this.projectTreeViewer.getTree(), 0); + jItem.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT)); + jItem.setChecked(true); + jItem.setText(projectName + " (External): " + gradleSettingsFile.getParentFile().getPath()); + if (!externalProjectPaths.containsKey(gradleSettingsFile.getParentFile().getPath())) { + externalProjectPaths.put(gradleSettingsFile.getParentFile().getPath(), projectName); + } + } catch (IOException e) { + e.printStackTrace(); + } + } else { + MessageBox dialog = new MessageBox(this.shell, SWT.ICON_ERROR | SWT.OK); + dialog.setText("Error"); + dialog.setMessage("The selected directory is not a gradle project dir!"); + dialog.open(); + } + } + + private String getProjectName(Properties gradleSettings) { + //Refactored method to include String cleaning + return gradleSettings.get("rootProject.name").toString().replaceAll("'", "").replaceAll("\"", ""); + } + + private File getGradleSettings(String projectDir) { + File groovyFile = new File(projectDir + "\\settings.gradle"); + File kotlinFile = new File(projectDir + "\\settings.gradle.kts"); + if (groovyFile.exists()) { + return groovyFile; + } else if (kotlinFile.exists()) { + return kotlinFile; + } else { + return new File(""); + } + } + + public Map getExternalProjectPaths() { + return externalProjectPaths; + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java index c23d4511b5..fc33586146 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java @@ -10,8 +10,25 @@ package org.eclipse.buildship.ui.internal.util.widget; +import java.util.ArrayList; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; @@ -19,7 +36,15 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.PlatformUI; +import org.eclipse.buildship.core.internal.configuration.GradleProjectNature; +import org.eclipse.buildship.ui.internal.util.file.ExternalProjectDialogSelectionListener; +import org.eclipse.buildship.ui.internal.wizard.project.ProjectCreationWizard; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.IGradleCompositeIDs; import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; @SuppressWarnings("unused") @@ -28,12 +53,15 @@ public class GradleProjectGroup extends Group { private Font font; private Button newGradleProject; private Button addExternalGradleProject; + private ExternalProjectDialogSelectionListener externalProjectListener; private Composite buttonComposite; - private Tree gradleProjectTree; + private TreeViewer gradleProjectTree; + private boolean editMode; - public GradleProjectGroup(Composite parent) { + public GradleProjectGroup(Composite parent, boolean editMode) { super(parent, SWT.NONE); setText(WorkspaceCompositeWizardMessages.Group_Label_GradleProjects); + this.editMode = editMode; createWidgets(); } @@ -41,8 +69,12 @@ public void createWidgets() { setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); GridLayoutFactory.swtDefaults().numColumns(4).applyTo(this); - this.gradleProjectTree = new Tree(this, SWT.CHECK); - this.gradleProjectTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + this.gradleProjectTree = new TreeViewer(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CHECK); + this.gradleProjectTree.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + fillCheckboxTreeWithProjects(); + if (this.editMode) { + configureTree(); + }this.gradleProjectTree.setUseHashlookup(true); this.buttonComposite = new Composite(this, SWT.NONE); this.buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1)); @@ -56,30 +88,125 @@ public void createWidgets() { this.addExternalGradleProject.setText(WorkspaceCompositeWizardMessages.Button_Add_ExternalGradleProject); this.addExternalGradleProject.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - fillCheckboxTreeWithFakeData(); + addListener(); } - private void fillCheckboxTreeWithFakeData() { - for (int i = 0; i < 4; i++) { - TreeItem iItem = new TreeItem(this.gradleProjectTree, 0); - iItem.setText("TreeItem (0) -" + i); - for (int j = 0; j < 4; j++) { - TreeItem jItem = new TreeItem(iItem, 0); - jItem.setText("TreeItem (1) -" + j); - for (int k = 0; k < 4; k++) { - TreeItem kItem = new TreeItem(jItem, 0); - kItem.setText("TreeItem (2) -" + k); - for (int l = 0; l < 4; l++) { - TreeItem lItem = new TreeItem(kItem, 0); - lItem.setText("TreeItem (3) -" + l); - } + private void addListener() { + this.newGradleProject.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + WizardDialog wizard = new WizardDialog(getShell(), new ProjectCreationWizard()); + if (wizard.open() == WizardDialog.OK) { + fillCheckboxTreeWithProjects(); + configureTree(); + }; + } + }); + this.externalProjectListener = new ExternalProjectDialogSelectionListener(getShell(), this.gradleProjectTree, ""); + this.addExternalGradleProject.addSelectionListener(this.externalProjectListener); + } + + private void configureTree() { + + ArrayList selection = getInitialTreeSelection(); + + try { + this.gradleProjectTree.getTree().setRedraw(false); + for (TreeItem item : this.gradleProjectTree.getTree().getItems()) { + if (selection.contains(item.getText())) { + item.setChecked(true); } } + } finally { + this.gradleProjectTree.getTree().setRedraw(true); } + + } + + public boolean hasSelectedItems() { + return this.gradleProjectTree.getTree().getSelectionCount() > 0; + } + + private ArrayList getInitialTreeSelection() { + ArrayList projectNames = new ArrayList<>(); + BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { + @Override + public void run() { + IStructuredSelection projectSelection = null; + IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + if (page == null) { + return; + } + + IWorkbenchPart part= page.getActivePart(); + if (part == null) { + return; + } + + try { + ISelectionProvider provider= part.getSite().getSelectionProvider(); + if (provider != null) { + ISelection selection = provider.getSelection(); + projectSelection = selection instanceof IStructuredSelection ? (IStructuredSelection) selection : StructuredSelection.EMPTY; + } + } catch (Exception e) { + return; + } + + + Object[] elements= projectSelection.toArray(); + + + for (int i=0; i < elements.length; i++) { + if (elements[i] instanceof IWorkingSet) { + IWorkingSet ge = ((IWorkingSet) elements[i]); + if (ge != null && ge.getId().equals(IGradleCompositeIDs.NATURE)) { + for (int j = 0; j < ge.getElements().length; j++) { + IAdaptable[] element = ge.getElements(); + projectNames.add(((IAdaptable) element[j]).getAdapter(IProject.class).getName()); + } + elements[i] = projectNames; + } + } + } + } + }); + + return projectNames; +} + + private void fillCheckboxTreeWithProjects() { + this.gradleProjectTree.getTree().removeAll(); + try { + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + IProject[] projects = workspaceRoot.getProjects(); + for(int i = 0; i < projects.length; i++) { + IProject project = projects[i]; + if(project.hasNature(GradleProjectNature.ID)) { + TreeItem jItem = new TreeItem(this.gradleProjectTree.getTree(), 0); + jItem.setText(project.getName()); + } + } + } + catch(CoreException ce) { + ce.printStackTrace(); + } + } + + public Tree getCheckboxTree() { + return this.gradleProjectTree.getTree(); + } + + public TreeViewer getCheckboxTreeViewer() { + return this.gradleProjectTree; + } + + public Map getExternalProjectPathList() { + return this.externalProjectListener.getExternalProjectPaths(); } @Override - protected void checkSubclass() { + protected void checkSubclass() { // Disable the check that prevents subclassing of SWT components } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/RemoveComposite.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/RemoveComposite.java new file mode 100644 index 0000000000..2af0ec4a98 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/RemoveComposite.java @@ -0,0 +1,47 @@ +package org.eclipse.buildship.ui.internal.view.task; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; + +public class RemoveComposite implements IHandler { + + @Override + public void addHandlerListener(IHandlerListener handlerListener) { + // TODO Auto-generated method stub + + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isEnabled() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isHandled() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void removeHandlerListener(IHandlerListener handlerListener) { + // TODO Auto-generated method stub + + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeWizardPage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeWizardPage.java new file mode 100644 index 0000000000..f5bde8ac49 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeWizardPage.java @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2015 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Etienne Studer & Donát Csikós (Gradle Inc.) - initial API and implementation and initial documentation + * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - refactored HelpContextIdProvider + */ + +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +import java.util.List; + +import com.google.common.base.Optional; +import com.google.common.base.Strings; + +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.PlatformUI; + +import org.eclipse.buildship.core.internal.util.binding.Property; +import org.eclipse.buildship.core.internal.util.binding.ValidationListener; +import org.eclipse.buildship.ui.internal.wizard.HelpContextIdProvider; + +/** + * Common base class for all pages in the {@link WorkspaceCompositeCreationWizard}. + */ +public abstract class AbstractCompositeWizardPage extends WizardPage { + + private final CompositeConfiguration configuration; + private final List> observedProperties; + private final String defaultMessage; + + /** + * Constructor setting up the main messages and the validation facility for this wizard page. + * + * @param name the name of the page + * @param title the page title + * @param defaultMessage the default message to show when there is no validation error + * @param configuration the data model of the wizard + * @param observedProperties the subset of the properties from the data model that are managed + * on this page + */ + protected AbstractCompositeWizardPage(String name, String title, String defaultMessage, CompositeConfiguration configuration, final List> observedProperties) { + super(name); + + this.configuration = configuration; + this.observedProperties = observedProperties; + this.defaultMessage = defaultMessage; + + // set the basic message and the attached image + setTitle(title); + setMessage(defaultMessage); + setImageDescriptor(ImageDescriptor.createFromFile(GradleCreateWorkspaceCompositeWizardPage.class, "/icons/full/wizban/wizard.png")); //$NON-NLS-1$ + + // create a listener that updates the state and the message if an observed property in the + // model changes + ValidationListener listener = new ValidationListener() { + @Override + public void validationTriggered(Property source, Optional validationErrorMessage) { + validateInput(source, validationErrorMessage); + // we set the page to completed if all its properties are valid + setPageComplete(isPageComplete()); + } + }; + + // attach the listener to all of the observed properties + for (Property property : observedProperties) { + property.addValidationListener(listener); + } + } + /** + * This method is overided by the main composite creation page due to a different validation machanism + * @param source + * @param validationErrorMessage + */ + protected void validateInput(Property source, Optional validationErrorMessage) { + // if the modified property is invalid, show its error message, otherwise check if + // any of the other properties of this page is invalid and if so, display the first + // found error message + if (validationErrorMessage.isPresent()) { + setMessage(validationErrorMessage.get(), IMessageProvider.ERROR); + } else { + Optional otherErrorMessage = validateAllObservedProperties(); + if (!otherErrorMessage.isPresent()) { + setMessage(AbstractCompositeWizardPage.this.defaultMessage); + } else { + setMessage(otherErrorMessage.get(), IMessageProvider.ERROR); + } + } + } + + private Optional validateAllObservedProperties() { + for (Property property : this.observedProperties) { + Optional errorMessage = property.validate(); + if (errorMessage.isPresent()) { + return errorMessage; + } + } + return Optional.absent(); + } + + protected CompositeConfiguration getConfiguration() { + return this.configuration; + } + + protected List> getObservedProperties() { + return this.observedProperties; + } + + @Override + public final void createControl(Composite parent) { + // align dialog units to the current resolution + initializeDialogUnits(parent); + + // create the container control + Composite pageControl = createWizardPageContent(parent); + + // assign the created control to the wizard page + setControl(pageControl); + } + + private Composite createWizardPageContent(Composite parent) { + // create a scrollable root to handle resizing + ScrolledComposite externalRoot = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); + externalRoot.setExpandHorizontal(true); + externalRoot.setExpandVertical(true); + externalRoot.setMinSize(new Point(230, 380)); + + // add the controls inside the root composite + Composite container = new Composite(externalRoot, SWT.NONE); + createWidgets(container); + + // add context information to the bottom of the page if the page defines it + String contextInformation = Strings.emptyToNull(getPageContextInformation()); + if (contextInformation != null) { + createWidgetsForContextInformation(container, contextInformation); + } + + // also compute the size of the container, otherwise the ScrolledComposite's content is not + // rendered properly + Point containerSize = container.computeSize(SWT.DEFAULT, SWT.DEFAULT); + container.setSize(containerSize); + + // set the root's content and return it + externalRoot.setContent(container); + return externalRoot; + } + + /** + * Populates the widgets in the wizard page. + */ + protected abstract void createWidgets(Composite root); + + private void createWidgetsForContextInformation(Composite root, String contextInformation) { + // create a container box occupying all horizontal space and has a 1-column row layout and a + // 30 pixel margin to not stretch the separator widgets to the edge of the wizard page + Composite contextInformationContainer = new Composite(root, SWT.NONE); + GridLayout contextInformationContainerLayout = new GridLayout(1, false); + contextInformationContainerLayout.marginLeft = contextInformationContainerLayout.marginRight = contextInformationContainerLayout.marginTop = 30; + contextInformationContainerLayout.verticalSpacing = 15; + contextInformationContainer.setLayout(contextInformationContainerLayout); + contextInformationContainer.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1)); + + // separator widget + Label separator = new Label(contextInformationContainer, SWT.HORIZONTAL | SWT.SEPARATOR); + separator.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false)); + + // internal container for flexible resize + Composite textContainer = new Composite(contextInformationContainer, SWT.NONE); + textContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + GridLayout textContainerLayout = new GridLayout(1, false); + textContainerLayout.marginLeft = textContainerLayout.marginRight = 50; + textContainer.setLayout(textContainerLayout); + + // text widget aligned to the center having 400 pixels allocated for each line of content + StyledText contextInformationText = new StyledText(textContainer, SWT.WRAP | SWT.MULTI | SWT.CENTER); + contextInformationText.setText(contextInformation); + contextInformationText.setBackground(contextInformationText.getParent().getBackground()); + contextInformationText.setEnabled(false); + contextInformationText.setEditable(false); + GridData contextInformationTextLayoutData = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1); + contextInformationTextLayoutData.widthHint = 400; + contextInformationText.setLayoutData(contextInformationTextLayoutData); + } + + /** + * Returns text to display under the widgets. If {@code null} or empty then nothing is displayed. + * + * @return explanation text for for the wizard page + */ + protected abstract String getPageContextInformation(); + + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + + // every time the page becomes visible, set the proper help context, this is required since + // the user could navigate back to the initial Eclipse import page which sets another help + // context + if (visible) { + if (getWizard() instanceof HelpContextIdProvider) { + String helpContextId = ((HelpContextIdProvider) getWizard()).getHelpContextId(); + PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), helpContextId); + } + } + } + + @Override + public boolean isPageComplete() { + for (Property property : this.observedProperties) { + if (!property.isValid()) { + return false; + } + } + return true; + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractWorkspaceCompositeWizard.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractWorkspaceCompositeWizard.java index e2022669c9..6d579135fa 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractWorkspaceCompositeWizard.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractWorkspaceCompositeWizard.java @@ -18,40 +18,24 @@ import org.eclipse.jface.wizard.Wizard; import org.osgi.service.prefs.BackingStoreException; -import com.google.common.base.Preconditions; - /** * Base class for project wizards. */ public abstract class AbstractWorkspaceCompositeWizard extends Wizard implements HelpContextIdProvider { - // the preference key under which it is stored whether to show the welcome page or not - private final String welcomePageEnabledPreferenceKey; - // state bit storing that the wizard is blocked to finish globally private boolean finishGloballyEnabled; - protected AbstractWorkspaceCompositeWizard(String welcomePageEnabledPreferenceKey) { - this.welcomePageEnabledPreferenceKey = Preconditions.checkNotNull(welcomePageEnabledPreferenceKey); + protected AbstractWorkspaceCompositeWizard() { // the wizard must not be finishable unless this global flag is enabled this.finishGloballyEnabled = true; } - public boolean isShowWelcomePage() { - // store the in the configuration scope to have the same settings for - // all workspaces - @SuppressWarnings("deprecation") - ConfigurationScope configurationScope = new ConfigurationScope(); - IEclipsePreferences node = configurationScope.getNode(UiPlugin.PLUGIN_ID); - return node.getBoolean(this.welcomePageEnabledPreferenceKey, true); - } - public void setWelcomePageEnabled(boolean enabled) { @SuppressWarnings("deprecation") ConfigurationScope configurationScope = new ConfigurationScope(); IEclipsePreferences node = configurationScope.getNode(UiPlugin.PLUGIN_ID); - node.putBoolean(this.welcomePageEnabledPreferenceKey, enabled); try { node.flush(); } catch (BackingStoreException e) { diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeConfiguration.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeConfiguration.java new file mode 100644 index 0000000000..bef3613aee --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeConfiguration.java @@ -0,0 +1,227 @@ +/******************************************************************************* + * Copyright (c) 2019 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ + +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +import java.io.File; +import java.util.List; + +import org.eclipse.buildship.core.CompositeProperties; +import org.eclipse.buildship.core.internal.util.binding.Property; +import org.eclipse.buildship.core.internal.util.binding.Validator; +import org.eclipse.buildship.core.internal.util.binding.Validators; +import org.eclipse.buildship.ui.internal.util.gradle.GradleDistributionViewModel; +import org.eclipse.core.runtime.IAdaptable; + +/** + * Serves as the data model of the composite import wizard. + */ +public final class CompositeConfiguration { + + private final Property compositePreferencesDir; + private final Property projectList; + private final Property overwriteWorkspaceSettings; + private final Property distribution; + private final Property gradleUserHome; + private final Property javaHome; + private final Property applyWorkingSets; + private final Property> workingSets; + private final Property buildScansEnabled; + private final Property offlineMode; + private final Property autoSync; + private final Property> arguments; + private final Property> jvmArguments; + private final Property showConsoleView; + private final Property showExecutionsView; + private final Property projectAsCompositeRoot; + private final Property rootProject; + + public CompositeConfiguration() { + this(Validators.noOp(), Validators.noOp(), Validators.noOp(), Validators.noOp(), Validators.noOp(), Validators.>noOp(), Validators.noOp()); + } + + public CompositeConfiguration(Validator compositePreferencesDirValidator, Validator distributionValidator, + Validator gradleUserHomeValidator, Validator javaHomeValidator, Validator applyWorkingSetsValidator, Validator> workingSetsValidators, Validator rootProjectValidator) { + this.compositePreferencesDir = Property.create(compositePreferencesDirValidator); + this.projectList = Property.create(Validators.noOp()); + this.overwriteWorkspaceSettings = Property.create(Validators.noOp()); + this.distribution = Property.create(distributionValidator); + this.gradleUserHome = Property.create(gradleUserHomeValidator); + this.javaHome = Property.create(javaHomeValidator); + this.applyWorkingSets = Property.create(applyWorkingSetsValidator); + this.workingSets = Property.create(workingSetsValidators); + this.buildScansEnabled = Property.create(Validators.noOp()); + this.offlineMode = Property.create(Validators.noOp()); + this.autoSync = Property.create(Validators.noOp()); + this.arguments = Property.>create(Validators.>noOp()); + this.jvmArguments = Property.>create(Validators.>noOp()); + this.showConsoleView = Property.create(Validators.noOp()); + this.showExecutionsView = Property.create(Validators.noOp()); + this.projectAsCompositeRoot = Property.create(Validators.noOp()); + this.rootProject = Property.create(rootProjectValidator); + + } + + public Property getCompositePreferencesDir() { + return this.compositePreferencesDir; + } + + public void setCompositePreferencesDir(File compositePreferencesDir) { + this.compositePreferencesDir.setValue(compositePreferencesDir); + } + + public Property getProjectList() { + return this.projectList; + } + + public void setProjectList(IAdaptable[] projectList) { + this.projectList.setValue(projectList); + } + + public Property getOverrideWorkspaceConfiguration() { + return this.overwriteWorkspaceSettings; + } + + public void setOverwriteWorkspaceSettings(boolean overwriteWorkspaceSettings) { + this.overwriteWorkspaceSettings.setValue(Boolean.valueOf(overwriteWorkspaceSettings)); + } + + public Property getDistribution() { + return this.distribution; + } + + public void setDistribution(GradleDistributionViewModel distribution) { + this.distribution.setValue(distribution); + } + + public Property getGradleUserHome() { + return this.gradleUserHome; + } + + public void setGradleUserHome(File gradleUserHome) { + this.gradleUserHome.setValue(gradleUserHome); + } + + public Property getJavaHome() { + return this.javaHome; + } + + public void setJavaHomeHome(File javaHome) { + this.javaHome.setValue(javaHome); + } + + public Property getApplyWorkingSets() { + return this.applyWorkingSets; + } + + public void setApplyWorkingSets(Boolean applyWorkingSets) { + this.applyWorkingSets.setValue(applyWorkingSets); + } + + public Property> getWorkingSets() { + return this.workingSets; + } + + public void setWorkingSets(List workingSets) { + this.workingSets.setValue(workingSets); + } + + public Property getBuildScansEnabled() { + return this.buildScansEnabled; + } + + public void setBuildScansEnabled(boolean buildScansEnabled) { + this.buildScansEnabled.setValue(Boolean.valueOf(buildScansEnabled)); + } + + public Property getOfflineMode() { + return this.offlineMode; + } + + public void setOfflineMode(boolean offlineMode) { + this.offlineMode.setValue(Boolean.valueOf(offlineMode)); + } + + public Property getAutoSync() { + return this.autoSync; + } + + public void setAutoSync(boolean autoSync) { + this.autoSync.setValue(Boolean.valueOf(autoSync)); + } + + public Property> getArguments() { + return this.arguments; + } + + public void setArguments(List arguments) { + this.arguments.setValue(arguments); + } + + public Property> getJvmArguments() { + return this.jvmArguments; + } + + public void setJvmArguments(List jvmArguments) { + this.jvmArguments.setValue(jvmArguments); + } + + public Property getShowConsoleView() { + return this.showConsoleView; + } + + public void setShowConsoleView(boolean showConsoleView) { + this.showConsoleView.setValue(Boolean.valueOf(showConsoleView)); + } + + public Property getShowExecutionsView() { + return this.showExecutionsView; + } + + public void setShowExecutionsView(boolean showExecutionsView) { + this.showExecutionsView.setValue(Boolean.valueOf(showExecutionsView)); + } + + public Property getProjectAsCompositeRoot() { + return this.projectAsCompositeRoot; + } + + public void setProjectAsCompositeRoot(boolean overwriteRootProject) { + this.projectAsCompositeRoot.setValue(Boolean.valueOf(overwriteRootProject)); + } + + public Property getRootProject() { + return this.rootProject; + } + + public void setRootProject(File rootProject) { + this.rootProject.setValue(rootProject); + } + + public CompositeProperties toCompositeProperties() { + return CompositeProperties.forRootProjectDirectory(getCompositePreferencesDir().getValue()) + .projectList(getProjectList().getValue()) + .overrideWorkspaceConfiguration(getOverrideWorkspaceConfiguration().getValue()) + .gradleDistribution(getDistribution().getValue().toGradleDistribution()) + .gradleUserHome(getGradleUserHome().getValue()) + .javaHome(getJavaHome().getValue()) + .buildScansEnabled(getBuildScansEnabled().getValue()) + .offlineMode(getOfflineMode().getValue()) + .autoSync(getAutoSync().getValue()) + .arguments(getArguments().getValue()) + .jvmArguments(getJvmArguments().getValue()) + .showConsoleView(getShowConsoleView().getValue()) + .showExecutionsView(getShowExecutionsView().getValue()) + .projectAsCompositeRoot(getProjectAsCompositeRoot().getValue()) + .rootProject(getRootProject().getValue()) + .build(); + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationConfiguration.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationConfiguration.java new file mode 100644 index 0000000000..3484cf8a1b --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationConfiguration.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +import java.util.List; + +import org.eclipse.buildship.core.internal.util.binding.Property; +import org.eclipse.core.runtime.IAdaptable; + +import com.google.common.base.Preconditions; + +public class CompositeCreationConfiguration { + + private final Property compositeName; + private final Property> compositeProjects; + + public CompositeCreationConfiguration(Property compositeName, Property> compositeProjects) { + this.compositeName = Preconditions.checkNotNull(compositeName); + this.compositeProjects = Preconditions.checkNotNull(compositeProjects); + } + + public Property getCompositeName() { + return compositeName; + } + + public void setCompositeName(String compositeName) { + this.compositeName.setValue(compositeName); + } + + public Property> getCompositeProjects() { + return compositeProjects; + } + + public void setCompositeProjects(List compositeProjects) { + this.compositeProjects.setValue(compositeProjects); + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationWizardController.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationWizardController.java new file mode 100644 index 0000000000..e93266e2be --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationWizardController.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2019 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.buildship.core.internal.util.binding.Property; +import org.eclipse.buildship.core.internal.util.binding.Validators; +import org.eclipse.buildship.core.internal.util.collections.CollectionsUtils; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.wizard.IWizard; + +import com.google.common.collect.ImmutableList; + +public class CompositeCreationWizardController { + + private static final String SETTINGS_KEY_COMPOSITE_NAME = "composite_name"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_COMPOSITE_PROJECTS = "composite_projects"; //$NON-NLS-1$ + + private final CompositeCreationConfiguration configuration; + + public CompositeCreationWizardController(IWizard compositeCreationWizard) { + // assemble configuration object that serves as the data model of the wizard + Property compositeNameProperty = Property.create(Validators.uniqueWorkspaceCompositeNameValidator(WorkspaceCompositeWizardMessages.Label_CompositeName)); + Property> compositeProjectsProperty = Property.create(Validators.>nullValidator()); + + this.configuration = new CompositeCreationConfiguration(compositeNameProperty, compositeProjectsProperty); + + IDialogSettings dialogSettings = compositeCreationWizard.getDialogSettings(); + String compositeName = dialogSettings.get(SETTINGS_KEY_COMPOSITE_NAME); + List compositeProjects = ImmutableList.copyOf(getProjects(CollectionsUtils.nullToEmpty(dialogSettings.getArray(SETTINGS_KEY_COMPOSITE_PROJECTS)))); + + this.configuration.setCompositeName(compositeName); + this.configuration.setCompositeProjects(compositeProjects); + } + + public CompositeCreationWizardController(String compositeName, List compositeProjects) { + // assemble configuration object that serves as the data model of the wizard + Property compositeNameProperty = Property.create(Validators.uniqueWorkspaceCompositeNameValidator(WorkspaceCompositeWizardMessages.Label_CompositeName)); + Property> compositeProjectsProperty = Property.create(Validators.>nullValidator()); + + this.configuration = new CompositeCreationConfiguration(compositeNameProperty, compositeProjectsProperty); + + this.configuration.setCompositeName(compositeName); + this.configuration.setCompositeProjects(compositeProjects); + } + + private List getProjects(String[] projectArray) { + List projects = new ArrayList(); + for (String projectName : projectArray) { + projects.add(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName)); + } + return projects; + } + + + public CompositeCreationConfiguration getConfiguration() { + return this.configuration; + } +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java new file mode 100644 index 0000000000..266f6ce658 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2015 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Etienne Studer & Donát Csikós (Gradle Inc.) - initial API and implementation and initial documentation + * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - refactored WizardHelper + */ + +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.eclipse.buildship.core.GradleDistribution; +import org.eclipse.buildship.core.internal.i18n.CoreMessages; +import org.eclipse.buildship.core.internal.util.binding.Property; +import org.eclipse.buildship.core.internal.util.binding.ValidationListener; +import org.eclipse.buildship.core.internal.util.binding.Validator; +import org.eclipse.buildship.core.internal.util.binding.Validators; +import org.eclipse.buildship.core.internal.util.collections.CollectionsUtils; +import org.eclipse.buildship.core.internal.util.file.FileUtils; +import org.eclipse.buildship.ui.internal.UiPlugin; +import org.eclipse.buildship.ui.internal.util.gradle.GradleDistributionViewModel; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.jface.wizard.IWizardContainer; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.IWorkingSetManager; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; + +/** + * Controller class for the {@link WorkspaceCompositeCreationWizard}. Contains all non-UI related calculations + * the wizard has to perform. + */ +public class CompositeImportWizardController { + + private static String PROJECT_CREATION_DIALOG_SETTINGS = "org.eclipse.buildship.ui.wizard.composite.creation"; + + private IWorkingSet workingSet; + + // keys to load/store project properties in the dialog setting + private static final String SETTINGS_KEY_COMPOSITE_DIR = "composite_location"; //$NON-NLS-1$ + //private static final String SETTINGS_KEY_GRADLE_PROJECT_LIST = "gradle_project_list"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_GRADLE_DISTRIBUTION = "gradle_distribution"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_APPLY_WORKING_SETS = "apply_working_sets"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_WORKING_SETS = "working_sets"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_GRADLE_USER_HOME = "gradle_user_home"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_JAVA_HOME = "java_home"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_BUILD_SCANS = "build_scans"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_OFFLINE_MODE = "offline_mode"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_AUTO_SYNC = "auto_sync"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_ARGUMENTS = "arguments"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_JVM_ARGUMENTS = "jvm_arguments"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_SHOW_CONSOLE_VIEW = "show_console_view"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_SHOW_EXECUTIONS_VIEW = "show_executions_view"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_PROJECT_AS_COMPOSITE_ROOT = "project_as_composite_root"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_ROOT_PROJECT = "root_project"; //$NON-NLS-1$ + + private final CompositeConfiguration configuration; + + public CompositeImportWizardController(IWizard compositeImportWizard) { + // assemble configuration object that serves as the data model of the wizard + Validator compositePreferenceDirValidator = Validators.and( + Validators.requiredDirectoryValidator(WorkspaceCompositeWizardMessages.Label_CompositeName), + Validators.nonWorkspaceFolderValidator(WorkspaceCompositeWizardMessages.Label_CompositeName)); + Validator gradleDistributionValidator = GradleDistributionViewModel.validator(); + Validator applyWorkingSetsValidator = Validators.nullValidator(); + Validator> workingSetsValidator = Validators.nullValidator(); + Validator gradleUserHomeValidator = Validators.optionalDirectoryValidator(CoreMessages.Preference_Label_Gradle_User_Home); + Validator javaHomeValidator = Validators.optionalDirectoryValidator(CoreMessages.Preference_Label_Java_Home); + Validator rootProjectValidator = Validators.optionalDirectoryValidator(CoreMessages.Preference_Label_Root_Project); + + this.configuration = new CompositeConfiguration(compositePreferenceDirValidator, gradleDistributionValidator, gradleUserHomeValidator, javaHomeValidator, applyWorkingSetsValidator, workingSetsValidator, rootProjectValidator); + + // initialize values from the persisted dialog settings + IDialogSettings dialogSettings; + + if (compositeImportWizard != null) { + dialogSettings = compositeImportWizard.getDialogSettings(); + } else { + + dialogSettings = getOrCreateDialogSection(UiPlugin.getInstance().getDialogSettings()); + } + + Optional projectDir = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_COMPOSITE_DIR)); + String gradleDistributionString = dialogSettings.get(SETTINGS_KEY_GRADLE_DISTRIBUTION); + Optional gradleUserHome = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_GRADLE_USER_HOME)); + Optional javaHome = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_JAVA_HOME)); + boolean applyWorkingSets = dialogSettings.get(SETTINGS_KEY_APPLY_WORKING_SETS) != null && dialogSettings.getBoolean(SETTINGS_KEY_APPLY_WORKING_SETS); + List workingSets = ImmutableList.copyOf(CollectionsUtils.nullToEmpty(dialogSettings.getArray(SETTINGS_KEY_WORKING_SETS))); + boolean buildScansEnabled = dialogSettings.getBoolean(SETTINGS_KEY_BUILD_SCANS); + boolean offlineMode = dialogSettings.getBoolean(SETTINGS_KEY_OFFLINE_MODE); + boolean autoSync = dialogSettings.getBoolean(SETTINGS_KEY_AUTO_SYNC); + List arguments = ImmutableList.copyOf(CollectionsUtils.nullToEmpty(dialogSettings.getArray(SETTINGS_KEY_ARGUMENTS))); + List jvmArguments = ImmutableList.copyOf(CollectionsUtils.nullToEmpty(dialogSettings.getArray(SETTINGS_KEY_JVM_ARGUMENTS))); + boolean showConsoleView = dialogSettings.getBoolean(SETTINGS_KEY_SHOW_CONSOLE_VIEW); + boolean showExecutionsView = dialogSettings.getBoolean(SETTINGS_KEY_SHOW_EXECUTIONS_VIEW); + boolean projectAsCompositeRoot = dialogSettings.getBoolean(SETTINGS_KEY_PROJECT_AS_COMPOSITE_ROOT); + Optional rootProject = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_ROOT_PROJECT)); + + this.configuration.setCompositePreferencesDir(projectDir.orNull()); + this.configuration.setOverwriteWorkspaceSettings(false); + GradleDistribution distribution; + try { + distribution = GradleDistribution.fromString(gradleDistributionString); + } catch (RuntimeException ignore) { + distribution = GradleDistribution.fromBuild(); + } + this.configuration.setDistribution(GradleDistributionViewModel.from(distribution)); + this.configuration.setGradleUserHome(gradleUserHome.orNull()); + this.configuration.setJavaHomeHome(javaHome.orNull()); + this.configuration.setApplyWorkingSets(applyWorkingSets); + this.configuration.setWorkingSets(workingSets); + this.configuration.setBuildScansEnabled(buildScansEnabled); + this.configuration.setOfflineMode(offlineMode); + this.configuration.setAutoSync(autoSync); + this.configuration.setArguments(arguments); + this.configuration.setJvmArguments(jvmArguments); + this.configuration.setShowConsoleView(showConsoleView); + this.configuration.setShowExecutionsView(showExecutionsView); + this.configuration.setProjectAsCompositeRoot(projectAsCompositeRoot); + this.configuration.setRootProject(rootProject.orNull()); + + // store the values every time they change + saveFilePropertyWhenChanged(dialogSettings, SETTINGS_KEY_COMPOSITE_DIR, this.configuration.getCompositePreferencesDir()); + saveDistributionPropertyWhenChanged(dialogSettings, this.configuration.getDistribution()); + saveFilePropertyWhenChanged(dialogSettings, SETTINGS_KEY_GRADLE_USER_HOME, this.configuration.getGradleUserHome()); + saveFilePropertyWhenChanged(dialogSettings, SETTINGS_KEY_JAVA_HOME, this.configuration.getJavaHome()); + saveBooleanPropertyWhenChanged(dialogSettings, SETTINGS_KEY_APPLY_WORKING_SETS, this.configuration.getApplyWorkingSets()); + saveStringArrayPropertyWhenChanged(dialogSettings, SETTINGS_KEY_WORKING_SETS, this.configuration.getWorkingSets()); + saveBooleanPropertyWhenChanged(dialogSettings, SETTINGS_KEY_BUILD_SCANS, this.configuration.getBuildScansEnabled()); + saveBooleanPropertyWhenChanged(dialogSettings, SETTINGS_KEY_OFFLINE_MODE, this.configuration.getOfflineMode()); + saveBooleanPropertyWhenChanged(dialogSettings, SETTINGS_KEY_AUTO_SYNC, this.configuration.getAutoSync()); + saveStringArrayPropertyWhenChanged(dialogSettings, SETTINGS_KEY_ARGUMENTS, this.configuration.getArguments()); + saveStringArrayPropertyWhenChanged(dialogSettings, SETTINGS_KEY_JVM_ARGUMENTS, this.configuration.getJvmArguments()); + saveBooleanPropertyWhenChanged(dialogSettings, SETTINGS_KEY_SHOW_CONSOLE_VIEW, this.configuration.getShowConsoleView()); + saveBooleanPropertyWhenChanged(dialogSettings, SETTINGS_KEY_SHOW_EXECUTIONS_VIEW, this.configuration.getShowExecutionsView()); + saveBooleanPropertyWhenChanged(dialogSettings, SETTINGS_KEY_PROJECT_AS_COMPOSITE_ROOT, this.configuration.getProjectAsCompositeRoot()); + saveFilePropertyWhenChanged(dialogSettings, SETTINGS_KEY_ROOT_PROJECT, this.configuration.getRootProject()); + } + + private void saveBooleanPropertyWhenChanged(final IDialogSettings settings, final String settingsKey, final Property target) { + target.addValidationListener(new ValidationListener() { + + @Override + public void validationTriggered(Property source, Optional validationErrorMessage) { + settings.put(settingsKey, target.getValue()); + } + }); + } + + private void saveStringArrayPropertyWhenChanged(final IDialogSettings settings, final String settingsKey, final Property> target) { + target.addValidationListener(new ValidationListener() { + + @Override + public void validationTriggered(Property source, Optional validationErrorMessage) { + List value = target.getValue(); + settings.put(settingsKey, value.toArray(new String[value.size()])); + } + }); + } + + private void saveFilePropertyWhenChanged(final IDialogSettings settings, final String settingsKey, final Property target) { + target.addValidationListener(new ValidationListener() { + + @Override + public void validationTriggered(Property source, Optional validationErrorMessage) { + settings.put(settingsKey, FileUtils.getAbsolutePath(target.getValue()).orNull()); + } + }); + } + + private void saveDistributionPropertyWhenChanged(final IDialogSettings settings, final Property target) { + target.addValidationListener(new ValidationListener() { + + @Override + public void validationTriggered(Property source, Optional validationErrorMessage) { + if (!validationErrorMessage.isPresent()) { + settings.put(SETTINGS_KEY_GRADLE_DISTRIBUTION, target.getValue().toGradleDistribution().toString()); + } else { + settings.put(SETTINGS_KEY_GRADLE_DISTRIBUTION, GradleDistribution.fromBuild().toString()); + } + } + }); + } + + public CompositeConfiguration getConfiguration() { + return this.configuration; + } + + public boolean performCreateComposite(IWizardContainer container, IWorkingSetManager workingSetManager) { + try { + File compositePreferenceFile = this.configuration.getCompositePreferencesDir().getValue(); + List projects = new ArrayList(); + for (IAdaptable project : getConfiguration().getProjectList().getValue()) { + projects.add((IProject) project); + } + workingSet = workingSetManager.createWorkingSet(compositePreferenceFile.getName(), projects.toArray(new IProject[projects.size()])); + workingSet.setId(IGradleCompositeIDs.NATURE); + workingSetManager.addWorkingSet(workingSet); + + + FileOutputStream out = new FileOutputStream(compositePreferenceFile.getAbsoluteFile()); + Properties prop = getConfiguration().toCompositeProperties().toProperties(); + prop.store(out, " "); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return true; + } + + private static IDialogSettings getOrCreateDialogSection(IDialogSettings dialogSettings) { + IDialogSettings section = dialogSettings.getSection(PROJECT_CREATION_DIALOG_SETTINGS); + if (section == null) { + section = dialogSettings.addNewSection(PROJECT_CREATION_DIALOG_SETTINGS); + } + return section; + } + + public IWorkingSet getWorkingSet() { + return workingSet; + } +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectConfiguration.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectConfiguration.java new file mode 100644 index 0000000000..9aa68aa56f --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectConfiguration.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2019 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +import java.io.File; + +import org.eclipse.buildship.core.internal.util.binding.Property; +import org.eclipse.buildship.core.internal.util.binding.Validators; + +import com.google.common.base.Preconditions; + +public class CompositeRootProjectConfiguration { + + private final Property useCompositeRoot; + private final Property rootProject; + + public CompositeRootProjectConfiguration(){ + this(Property.create(Validators.noOp()), Property.create(Validators.noOp())); + } + + public CompositeRootProjectConfiguration(Property useCompositeRoot, Property rootProject) { + this.useCompositeRoot = Preconditions.checkNotNull(useCompositeRoot); + this.rootProject = Preconditions.checkNotNull(rootProject); + } + + public Property getUseCompositeRoot() { + return useCompositeRoot; + } + + public void setUseCompositeRoot(Boolean useCompositeRoot) { + this.useCompositeRoot.setValue(useCompositeRoot); + } + + public Property getRootProject() { + return rootProject; + } + + public void setRootProject(File rootProject) { + this.rootProject.setValue(rootProject); + } + + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectWizardController.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectWizardController.java new file mode 100644 index 0000000000..6aeea4a2a0 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectWizardController.java @@ -0,0 +1,39 @@ +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +import java.io.File; + +import org.eclipse.buildship.core.internal.util.binding.Property; +import org.eclipse.buildship.core.internal.util.binding.Validators; +import org.eclipse.buildship.core.internal.util.file.FileUtils; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.wizard.IWizard; + +import com.google.common.base.Optional; + +public class CompositeRootProjectWizardController { + + private static final String SETTINGS_KEY_USE_COMPOSITE_ROOT = "use_composite_root"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_COMPOSITE_ROOT_PROJECT = "composite_root_project"; //$NON-NLS-1$ + + private final CompositeRootProjectConfiguration configuration; + + public CompositeRootProjectWizardController(IWizard compositeCreationWizard) { + // assemble configuration object that serves as the data model of the wizard + Property compositeNameProperty = Property.create(Validators.nullValidator()); + Property compositeProjectsProperty = Property.create(Validators.nonExistentDirectoryValidator(WorkspaceCompositeWizardMessages.Label_RootProject)); + + this.configuration = new CompositeRootProjectConfiguration(compositeNameProperty, compositeProjectsProperty); + + IDialogSettings dialogSettings = compositeCreationWizard.getDialogSettings(); + Boolean useCompositeRoot = dialogSettings.getBoolean(SETTINGS_KEY_USE_COMPOSITE_ROOT); + Optional compositeRootProject = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_COMPOSITE_ROOT_PROJECT)); + + this.configuration.setUseCompositeRoot(useCompositeRoot); + this.configuration.setRootProject(compositeRootProject.orNull()); + } + + public CompositeRootProjectConfiguration getConfiguration() { + return this.configuration; + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProject.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProject.java new file mode 100644 index 0000000000..f1579c3977 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProject.java @@ -0,0 +1,21 @@ +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +public class ExternalGradleProject { + //TODO (kuzniarz) initial implementation needs to be finished + + private String projectName; + private String projectPath; + + public ExternalGradleProject(String name, String path) { + projectName = name; + projectPath = path; + } + + public String getProjectName() { + return this.projectName; + } + + public String getProjectPath() { + return this.projectPath; + } +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProjectAdapter.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProjectAdapter.java new file mode 100644 index 0000000000..e29a9f0f2d --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProjectAdapter.java @@ -0,0 +1,11 @@ +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +public class ExternalGradleProjectAdapter { + + private final ExternalGradleProject gradleProject; + + public ExternalGradleProjectAdapter(ExternalGradleProject project) { + this.gradleProject = project; + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalProjectAdapterFactory.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalProjectAdapterFactory.java new file mode 100644 index 0000000000..e211834e94 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalProjectAdapterFactory.java @@ -0,0 +1,21 @@ +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +import org.eclipse.core.runtime.IAdapterFactory; + +public class ExternalProjectAdapterFactory implements IAdapterFactory { + + @Override + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adaptableObject instanceof ExternalGradleProject){ + return new ExternalGradleProjectAdapter((ExternalGradleProject) adaptableObject); + } + return null; + } + + @Override + public Class[] getAdapterList() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java index a95e79b247..875005fd77 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java @@ -10,34 +10,87 @@ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; + +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.PlatformUI; +import org.eclipse.buildship.core.internal.CorePlugin; +import org.eclipse.buildship.core.internal.util.binding.Property; import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; import org.eclipse.buildship.ui.internal.util.widget.GradleProjectGroup; /** * Page on the {@link WorkspaceCompositeCreationWizard} declaring the workspace composite name and included projects. */ -public final class GradleCreateWorkspaceCompositeWizardPage extends AbstractWizardPage { +public final class GradleCreateWorkspaceCompositeWizardPage extends AbstractCompositeWizardPage { + + private final CompositeCreationConfiguration creationConfiguration; + @SuppressWarnings("unused") private Text workspaceCompositeNameText; private Label compositeName; private GradleProjectGroup gradleProjectCheckboxtreeComposite; + private static IWorkingSet gradleComposite; + private boolean firstCheck; + + public GradleCreateWorkspaceCompositeWizardPage(CompositeConfiguration importConfiguration, CompositeCreationConfiguration creationConfiguration) { + super("NewGradleWorkspaceComposite", WorkspaceCompositeWizardMessages.Title_NewGradleWorkspaceCompositeWizardPage, WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeWizardPageDefault, //$NON-NLS-1$ + importConfiguration, ImmutableList.of(creationConfiguration.getCompositeName(), creationConfiguration.getCompositeProjects())); + + this.creationConfiguration = creationConfiguration; + this.firstCheck = true; + } + public GradleCreateWorkspaceCompositeWizardPage() { - super("NewGradleWorkspaceComposite", WorkspaceCompositeWizardMessages.Title_NewGradleWorkspaceCompositeWizardPage, WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeWizardPageDefault); //$NON-NLS-1$ + this(getCompositeImportConfiguration(), getCompositeCreationConfiguration()); + } + + + private static CompositeCreationConfiguration getCompositeCreationConfiguration() { + CompositeCreationWizardController creationController; + ArrayList compositeElements = new ArrayList<>(); + if (gradleComposite != null) { + creationController = new CompositeCreationWizardController(gradleComposite.getName(), compositeElements); + } else { + creationController = new CompositeCreationWizardController("", compositeElements); + } + return creationController.getConfiguration(); + } + + private static CompositeConfiguration getCompositeImportConfiguration() { + return new CompositeConfiguration(); + } + + protected String getPageId() { + return "org.eclipse.buildship.ui.GradleCompositePage"; //$NON-NLS-1$ } @Override protected void createWidgets(Composite root) { root.setLayout(LayoutUtils.newGridLayout(3)); createContent(root); + bindToConfiguration(); } private void createContent(Composite root) { @@ -56,9 +109,60 @@ private void createContent(Composite root) { this.workspaceCompositeNameText = new Text(workspaceCompositeNameComposite, SWT.BORDER); this.workspaceCompositeNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(root); + this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(root, hasSelectedElement()); GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(3, SWT.DEFAULT).applyTo(this.gradleProjectCheckboxtreeComposite); + getConfiguration().getProjectList().setValue(new IAdaptable[0]); + + if (gradleComposite != null) { + this.workspaceCompositeNameText.setText(gradleComposite.getName()); + } + } + + private void bindToConfiguration() { + this.workspaceCompositeNameText.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + updateLocation(); + } + }); + this.gradleProjectCheckboxtreeComposite.getCheckboxTree().addListener(SWT.Selection, new Listener() { + + @Override + public void handleEvent(Event event) { + updateCompositeProjects(); + } + }); + } + + private void updateLocation() { + File parentLocation = CorePlugin.getInstance().getStateLocation().append("workspace-composites").toFile(); + File projectDir = parentLocation != null ? new File(parentLocation, this.workspaceCompositeNameText.getText()) : null; + + // always update project name last to ensure project name validation errors have precedence in the UI + getConfiguration().getCompositePreferencesDir().setValue(projectDir); + this.creationConfiguration.setCompositeName(this.workspaceCompositeNameText.getText()); + } + + protected void updateCompositeProjects() { + List projectList = new ArrayList<>(); + + for (TreeItem treeElement : this.gradleProjectCheckboxtreeComposite.getCheckboxTree().getItems()) { + if (treeElement.getChecked() == true) { + if (treeElement.getText().contains(" (External): ")) { + //String[] treeValues = treeElement.getText().replace(" (External): ", "$").split("\\$"); + // treeValues[0] contains the project name + // treeValues[1] contains the file path + //File externalFolder = new File(treeValues[1]); + projectList.add(null); + } else { + projectList.add(ResourcesPlugin.getWorkspace().getRoot().getProject(treeElement.getText())); + } + } + } + getConfiguration().getProjectList().setValue(projectList.toArray(new IAdaptable[projectList.size()])); + this.creationConfiguration.setCompositeProjects(projectList); } @Override @@ -66,4 +170,53 @@ protected String getPageContextInformation() { return WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeWizardPageContext; } + /* + * Has to be implemented here because of gradleComposite checks to prevent "name exists" bug while editing + */ + @Override + protected void validateInput(Property source, Optional validationErrorMessage) { + String errorMessage = null; + String infoMessage = null; + String newText= this.workspaceCompositeNameText.getText(); + + if (newText.equals(newText.trim()) == false) { + errorMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_NameWhitespaces; + } + if (newText.isEmpty()) { + if (this.firstCheck) { + setPageComplete(false); + this.firstCheck= false; + return; + } else { + errorMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_NameEmpty; + } + } + + this.firstCheck= false; + + if (errorMessage == null && (gradleComposite == null || newText.equals(gradleComposite.getName()) == false)) { + IWorkingSet[] workingSets= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets(); + for (int i= 0; i < workingSets.length; i++) { + if (newText.equals(workingSets[i].getName())) { + errorMessage= WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_CompositeNameExists; + } + } + } + + if (!hasSelectedElement()) { + infoMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_CompositeEmpty; + setMessage(infoMessage, INFORMATION); + } else { + setMessage(WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeWizardPageDefault); + } + + + setErrorMessage(errorMessage); + setPageComplete(errorMessage == null); + } + + private boolean hasSelectedElement() { + return this.creationConfiguration.getCompositeProjects().getValue().size() > 0; + } + } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleImportOptionsWizardPage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleImportOptionsWizardPage.java index 0ff1207239..f84eacc49d 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleImportOptionsWizardPage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleImportOptionsWizardPage.java @@ -9,34 +9,44 @@ ******************************************************************************/ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; +import com.google.common.collect.ImmutableList; + import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.dialogs.PreferencesUtil; +import org.eclipse.buildship.core.internal.util.binding.Property; import org.eclipse.buildship.ui.internal.preferences.GradleWorkbenchPreferencePage; +import org.eclipse.buildship.ui.internal.util.gradle.GradleDistributionViewModel; +import org.eclipse.buildship.ui.internal.util.widget.GradleDistributionGroup.DistributionChangedListener; import org.eclipse.buildship.ui.internal.util.widget.GradleProjectSettingsComposite; +import org.eclipse.buildship.ui.internal.util.widget.StringListEditor.StringListChangeListener; /** * Page on the {@link WorkspaceCompositeCreationWizard} declaring the used Gradle distribution and other advanced options for the composite projects. */ -public final class GradleImportOptionsWizardPage extends AbstractWizardPage { +public final class GradleImportOptionsWizardPage extends AbstractCompositeWizardPage { private final String pageContextInformation; private GradleProjectSettingsComposite gradleProjectSettingsComposite; - public GradleImportOptionsWizardPage() { - this(WorkspaceCompositeWizardMessages.Title_GradleImportOptionsWizardPage, WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeOptionsWizardPageDefault, + public GradleImportOptionsWizardPage(CompositeConfiguration configuration) { + this(configuration, WorkspaceCompositeWizardMessages.Title_GradleImportOptionsWizardPage, WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeOptionsWizardPageDefault, WorkspaceCompositeWizardMessages.InfoMessage_GradleImportOptionsWizardPageContext); } - public GradleImportOptionsWizardPage(String title, String defaultMessage, String pageContextInformation) { - super("GradleImportOptions", title, defaultMessage); + public GradleImportOptionsWizardPage(CompositeConfiguration configuration, String title, String defaultMessage, String pageContextInformation) { + super("GradleImportOptions", title, defaultMessage, configuration, ImmutableList.>of(configuration.getDistribution(), configuration.getGradleUserHome(), configuration.getJavaHome())); this.pageContextInformation = pageContextInformation; - } + + } @Override protected void createWidgets(Composite root) { @@ -48,6 +58,157 @@ protected void createWidgets(Composite root) { GridDataFactory.fillDefaults().grab(true, false).applyTo(this.gradleProjectSettingsComposite); this.gradleProjectSettingsComposite.getParentPreferenceLink().addSelectionListener(new WorkbenchPreferenceOpeningSelectionListener()); + + initValues(); + addListeners(); + } + + @Override + public IWizardPage getNextPage() { + IWizardPage page = new GradleRootProjectWizardPage(getConfiguration(), new CompositeRootProjectConfiguration()); + page.setWizard(getWizard()); + return page; + } + + private void initValues() { + this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().setSelection(getConfiguration().getOverrideWorkspaceConfiguration().getValue()); + this.gradleProjectSettingsComposite.getGradleDistributionGroup().setDistribution(getConfiguration().getDistribution().getValue()); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setGradleUserHome(getConfiguration().getGradleUserHome().getValue()); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setJavaHome(getConfiguration().getJavaHome().getValue()); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setArguments(getConfiguration().getArguments().getValue()); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setJvmArguments(getConfiguration().getJvmArguments().getValue()); + this.gradleProjectSettingsComposite.getBuildScansCheckbox().setSelection(getConfiguration().getBuildScansEnabled().getValue()); + this.gradleProjectSettingsComposite.getOfflineModeCheckbox().setSelection(getConfiguration().getOfflineMode().getValue()); + this.gradleProjectSettingsComposite.getAutoSyncCheckbox().setSelection(getConfiguration().getAutoSync().getValue()); + this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().setSelection(getConfiguration().getShowConsoleView().getValue()); + this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().setSelection(getConfiguration().getShowExecutionsView().getValue()); + this.gradleProjectSettingsComposite.updateEnablement(); + } + + private void addListeners() { + this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + getConfiguration().getOverrideWorkspaceConfiguration().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().getSelection()); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + getConfiguration().getOverrideWorkspaceConfiguration().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().getSelection()); + } + }); + + this.gradleProjectSettingsComposite.getGradleDistributionGroup().addDistributionChangedListener(new DistributionChangedListener() { + + @Override + public void distributionUpdated(GradleDistributionViewModel distribution) { + getConfiguration().setDistribution(distribution); + } + }); + + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getGradleUserHomeText().addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + getConfiguration().setGradleUserHome(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getGradleUserHome()); + } + }); + + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJavaHomeText().addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + getConfiguration().setJavaHomeHome(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJavaHome()); + } + }); + + + this.gradleProjectSettingsComposite.getBuildScansCheckbox().addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + getConfiguration().getBuildScansEnabled().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getBuildScansCheckbox().getSelection()); + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + getConfiguration().getBuildScansEnabled().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getBuildScansCheckbox().getSelection()); + } + }); + + this.gradleProjectSettingsComposite.getOfflineModeCheckbox().addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + getConfiguration().getOfflineMode().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getOfflineModeCheckbox().getSelection()); + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + getConfiguration().getOfflineMode().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getOfflineModeCheckbox().getSelection()); + } + }); + this.gradleProjectSettingsComposite.getAutoSyncCheckbox().addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + getConfiguration().getAutoSync().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getAutoSyncCheckbox().getSelection()); + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + getConfiguration().getAutoSync().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getAutoSyncCheckbox().getSelection()); + } + }); + + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getArgumentsEditor().addChangeListener(new StringListChangeListener() { + + @Override + public void onChange() { + getConfiguration().getArguments().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getArguments()); + } + }); + + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJvmArgumentsEditor().addChangeListener(new StringListChangeListener() { + + @Override + public void onChange() { + getConfiguration().getJvmArguments().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJvmArguments()); + } + }); + + this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + getConfiguration().getShowConsoleView().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().getSelection()); + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + getConfiguration().getShowConsoleView().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().getSelection()); + } + }); + + this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + getConfiguration().getShowExecutionsView().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().getSelection()); + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + getConfiguration().getShowExecutionsView().setValue(GradleImportOptionsWizardPage.this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().getSelection()); + } + }); + } @Override diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleRootProjectWizardPage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleRootProjectWizardPage.java index a709b48ffc..6e4445ed86 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleRootProjectWizardPage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleRootProjectWizardPage.java @@ -10,10 +10,19 @@ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; +import java.io.File; + +import org.eclipse.buildship.core.internal.util.binding.Property; +import org.eclipse.buildship.ui.internal.util.file.DirectoryDialogSelectionListener; import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.CompositeConfiguration; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -22,33 +31,45 @@ import org.eclipse.swt.widgets.Layout; import org.eclipse.swt.widgets.Text; +import com.google.common.collect.ImmutableList; + /** * Page in the {@link WorkspaceCompositeCreationWizard} for setting a project as composite root. */ @SuppressWarnings("unused") -public final class GradleRootProjectWizardPage extends AbstractWizardPage { +public final class GradleRootProjectWizardPage extends AbstractCompositeWizardPage { + + private final CompositeRootProjectConfiguration rootProjectConfiguration; - private Text workspaceCompositeRootProjectLabel; - private Text overrideCheckboxLabel; - private Button overrideSettingsCheckbox; + private Text workspaceCompositeRootProjectText; + private Text overrideRootProjectCheckboxLabel; + private Button overrideRootProjectCheckbox; private Button selectRootProject; private Label rootProjectLabel; - public GradleRootProjectWizardPage() { + public GradleRootProjectWizardPage(CompositeConfiguration configuration, CompositeRootProjectConfiguration rootProjectConfiguration) { this(WorkspaceCompositeWizardMessages.Title_CompositeRootWizardPage, WorkspaceCompositeWizardMessages.InfoMessage_CompositeRootWizardPageDefault, - WorkspaceCompositeWizardMessages.InfoMessage_CompositeRootWizardPageContext); + WorkspaceCompositeWizardMessages.InfoMessage_CompositeRootWizardPageContext, configuration, rootProjectConfiguration); } public GradleRootProjectWizardPage(String title, String defaultMessage, - String pageContextInformation) { - super("CompositeRootProject", title, defaultMessage); //$NON-NLS-1$ + String pageContextInformation, CompositeConfiguration configuration, CompositeRootProjectConfiguration rootProjectConfiguration) { + super("CompositeRootProject", title, defaultMessage, configuration, ImmutableList.>of(rootProjectConfiguration.getUseCompositeRoot(), rootProjectConfiguration.getRootProject())); //$NON-NLS-1$ + + this.rootProjectConfiguration = rootProjectConfiguration; } @Override protected void createWidgets(Composite root) { root.setLayout(createLayout()); createContent(root); + addListeners(); + } + + private void initValues() { + this.overrideRootProjectCheckbox.setSelection(this.rootProjectConfiguration.getUseCompositeRoot().getValue()); + this.workspaceCompositeRootProjectText.setText(this.rootProjectConfiguration.getRootProject().getValue().getAbsolutePath()); } private Layout createLayout() { @@ -60,8 +81,8 @@ private Layout createLayout() { private void createContent(Composite root) { - this.overrideSettingsCheckbox = new Button(root, SWT.CHECK); - this.overrideSettingsCheckbox.setText("Use project as composite root"); + this.overrideRootProjectCheckbox = new Button(root, SWT.CHECK); + this.overrideRootProjectCheckbox.setText("Use project as composite root"); GridDataFactory.swtDefaults().applyTo(root); Label line = new Label(root, SWT.SEPARATOR | SWT.HORIZONTAL); @@ -77,14 +98,63 @@ private void createContent(Composite root) { this.rootProjectLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); this.rootProjectLabel.setText(WorkspaceCompositeWizardMessages.Label_RootProject); + this.rootProjectLabel.setEnabled(false); + // root project text field - this.workspaceCompositeRootProjectLabel = new Text(workspaceCompositeNameComposite, SWT.BORDER); - this.workspaceCompositeRootProjectLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + this.workspaceCompositeRootProjectText = new Text(workspaceCompositeNameComposite, SWT.BORDER); + this.workspaceCompositeRootProjectText.setEnabled(false); + this.workspaceCompositeRootProjectText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); // root project select button this.selectRootProject = new Button(workspaceCompositeNameComposite, SWT.PUSH); this.selectRootProject.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + this.selectRootProject.setEnabled(false); this.selectRootProject.setText(WorkspaceCompositeWizardMessages.Button_Select_RootProject); + + } + + private File getRootProject() { + String rootProjectString = this.workspaceCompositeRootProjectText.getText(); + return rootProjectString.isEmpty() ? null : new File(rootProjectString); + } + + private void addListeners() { + if (this.overrideRootProjectCheckbox != null) { + this.overrideRootProjectCheckbox.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + getConfiguration().getProjectAsCompositeRoot().setValue(GradleRootProjectWizardPage.this.overrideRootProjectCheckbox.getSelection()); + updateEnablement(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + getConfiguration().getProjectAsCompositeRoot().setValue(GradleRootProjectWizardPage.this.overrideRootProjectCheckbox.getSelection()); + updateEnablement(); + } + }); + + this.workspaceCompositeRootProjectText.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + getConfiguration().getRootProject().setValue(GradleRootProjectWizardPage.this.getRootProject()); + + } + }); + + this.selectRootProject.addSelectionListener(new DirectoryDialogSelectionListener(this.getShell(), this.workspaceCompositeRootProjectText, "Root project")); + } + } + + public void updateEnablement() { + if (this.overrideRootProjectCheckbox != null) { + boolean enabled = this.overrideRootProjectCheckbox.getSelection(); + this.rootProjectLabel.setEnabled(enabled); + this.workspaceCompositeRootProjectText.setEnabled(enabled); + this.selectRootProject.setEnabled(enabled); + } } @Override diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleWorkspaceCompositeUpdater.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleWorkspaceCompositeUpdater.java new file mode 100644 index 0000000000..57acd1933f --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleWorkspaceCompositeUpdater.java @@ -0,0 +1,227 @@ +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jdt.core.ElementChangedEvent; +import org.eclipse.jdt.core.IElementChangedListener; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaElementDelta; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.internal.ui.workingsets.IWorkingSetIDs; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.IWorkingSetUpdater; + + +public class GradleWorkspaceCompositeUpdater implements IWorkingSetUpdater, IElementChangedListener { + + /** + * DO NOT REMOVE, used in a product, see https://bugs.eclipse.org/297529 . + * @deprecated As of 3.5, replaced by {@link IWorkingSetIDs#JAVA} + */ + @Deprecated + public static final String ID= "org.eclipse.buildship.core.gradlecompositenature"; + + + private List fWorkingSets; + + private static class WorkingSetDelta { + private IWorkingSet fWorkingSet; + private List fElements; + private boolean fChanged; + public WorkingSetDelta(IWorkingSet workingSet) { + fWorkingSet= workingSet; + fElements= new ArrayList<>(Arrays.asList(workingSet.getElements())); + } + public int indexOf(Object element) { + return fElements.indexOf(element); + } + public void set(int index, IAdaptable element) { + fElements.set(index, element); + fChanged= true; + } + public void remove(int index) { + if (fElements.remove(index) != null) { + fChanged= true; + } + } + public void process() { + if (fChanged) { + fWorkingSet.setElements(fElements.toArray(new IAdaptable[fElements.size()])); + } + } + } + + public GradleWorkspaceCompositeUpdater() { + fWorkingSets= new ArrayList<>(); + } + + @Override + public void add(IWorkingSet workingSet) { + checkElementExistence(workingSet); + synchronized (fWorkingSets) { + fWorkingSets.add(workingSet); + } + } + + @Override + public boolean remove(IWorkingSet workingSet) { + boolean result; + synchronized(fWorkingSets) { + result= fWorkingSets.remove(workingSet); + } + return result; + } + + @Override + public boolean contains(IWorkingSet workingSet) { + synchronized(fWorkingSets) { + return fWorkingSets.contains(workingSet); + } + } + + @Override + public void dispose() { + synchronized(fWorkingSets) { + fWorkingSets.clear(); + } + } + + @Override + public void elementChanged(ElementChangedEvent event) { + IWorkingSet[] workingSets; + synchronized(fWorkingSets) { + workingSets= fWorkingSets.toArray(new IWorkingSet[fWorkingSets.size()]); + } + for (int w= 0; w < workingSets.length; w++) { + WorkingSetDelta workingSetDelta= new WorkingSetDelta(workingSets[w]); + processJavaDelta(workingSetDelta, event.getDelta()); + IResourceDelta[] resourceDeltas= event.getDelta().getResourceDeltas(); + if (resourceDeltas != null) { + for (int r= 0; r < resourceDeltas.length; r++) { + processResourceDelta(workingSetDelta, resourceDeltas[r]); + } + } + workingSetDelta.process(); + } + } + + private void processJavaDelta(WorkingSetDelta result, IJavaElementDelta delta) { + IJavaElement jElement= delta.getElement(); + int index= result.indexOf(jElement); + int type= jElement.getElementType(); + int kind= delta.getKind(); + int flags= delta.getFlags(); + if (type == IJavaElement.JAVA_PROJECT && kind == IJavaElementDelta.CHANGED) { + if (index != -1 && (flags & IJavaElementDelta.F_CLOSED) != 0) { + result.set(index, ((IJavaProject)jElement).getProject()); + } else if ((flags & IJavaElementDelta.F_OPENED) != 0) { + index= result.indexOf(((IJavaProject)jElement).getProject()); + if (index != -1) + result.set(index, jElement); + } + } + if (index != -1) { + if (kind == IJavaElementDelta.REMOVED) { + if ((flags & IJavaElementDelta.F_MOVED_TO) != 0) { + result.set(index, delta.getMovedToElement()); + } else { + result.remove(index); + } + } + } + IResourceDelta[] resourceDeltas= delta.getResourceDeltas(); + if (resourceDeltas != null) { + for (int i= 0; i < resourceDeltas.length; i++) { + processResourceDelta(result, resourceDeltas[i]); + } + } + IJavaElementDelta[] children= delta.getAffectedChildren(); + for (int i= 0; i < children.length; i++) { + processJavaDelta(result, children[i]); + } + } + + private void processResourceDelta(WorkingSetDelta result, IResourceDelta delta) { + IResource resource= delta.getResource(); + int type= resource.getType(); + int index= result.indexOf(resource); + int kind= delta.getKind(); + int flags= delta.getFlags(); + if (kind == IResourceDelta.CHANGED && type == IResource.PROJECT && index != -1) { + if ((flags & IResourceDelta.OPEN) != 0) { + result.set(index, resource); + } + } + if (index != -1 && kind == IResourceDelta.REMOVED) { + if ((flags & IResourceDelta.MOVED_TO) != 0) { + result.set(index, + ResourcesPlugin.getWorkspace().getRoot().findMember(delta.getMovedToPath())); + } else { + result.remove(index); + } + } + + // Don't dive into closed or opened projects + if (projectGotClosedOrOpened(resource, kind, flags)) + return; + + IResourceDelta[] children= delta.getAffectedChildren(); + for (int i= 0; i < children.length; i++) { + processResourceDelta(result, children[i]); + } + } + + private boolean projectGotClosedOrOpened(IResource resource, int kind, int flags) { + return resource.getType() == IResource.PROJECT + && kind == IResourceDelta.CHANGED + && (flags & IResourceDelta.OPEN) != 0; + } + + private void checkElementExistence(IWorkingSet workingSet) { + List elements= new ArrayList<>(Arrays.asList(workingSet.getElements())); + boolean changed= false; + for (Iterator iter= elements.iterator(); iter.hasNext();) { + IAdaptable element= iter.next(); + boolean remove= false; + if (element instanceof IJavaElement) { + IJavaElement jElement= (IJavaElement)element; + // If we have directly a project then remove it when it + // doesn't exist anymore. However if we have a sub element + // under a project only remove the element if the parent + // project is open. Otherwise we would remove all elements + // in closed projects. + if (jElement instanceof IJavaProject) { + remove= !jElement.exists(); + } else { + final IJavaProject javaProject= jElement.getJavaProject(); + final boolean isProjectOpen= javaProject != null ? javaProject.getProject().isOpen() : true; + remove= isProjectOpen && !jElement.exists(); + } + } else if (element instanceof IResource) { + IResource resource= (IResource)element; + // See comments above + if (resource instanceof IProject) { + remove= !resource.exists(); + } else { + IProject project= resource.getProject(); + remove= (project != null ? project.isOpen() : true) && !resource.exists(); + } + } + if (remove) { + iter.remove(); + changed= true; + } + } + if (changed) { + workingSet.setElements(elements.toArray(new IAdaptable[elements.size()])); + } + } +} \ No newline at end of file diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/IGradleCompositeIDs.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/IGradleCompositeIDs.java new file mode 100644 index 0000000000..f76a7216d0 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/IGradleCompositeIDs.java @@ -0,0 +1,13 @@ +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +/** + * + * @author Sebastian Kuzniarz (kuzniarz) - Diebold Nixdorf Inc. + * + */ + +public interface IGradleCompositeIDs { + + String NATURE = "org.eclipse.buildship.ui.GradleCompositePage"; + +} 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 641a4c9675..0e50c7bd7c 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,8 @@ import org.eclipse.jface.wizard.IWizardContainer; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkingSetManager; +import org.eclipse.ui.PlatformUI; /** * Eclipse wizard for creating Gradle composites in the workspace. @@ -27,17 +29,21 @@ public final class WorkspaceCompositeCreationWizard extends AbstractWorkspaceCom * * @see org.eclipse.jface.dialogs.DialogSettings#getOrCreateSection(IDialogSettings, String) */ - private static final String PROJECT_CREATION_DIALOG_SETTINGS = "org.eclipse.buildship.ui.wizard.project.creation"; //$NON-NLS-1$ - - /** - * Preference key that flags whether the welcome page should be shown as part of the creation wizard. - */ - private static final String PREF_SHOW_WELCOME_PAGE = "org.eclipse.buildship.ui.wizard.project.creation.showWelcomePage"; //$NON-NLS-1$ + private static final String PROJECT_CREATION_DIALOG_SETTINGS = "org.eclipse.buildship.ui.wizard.composite.creation"; //$NON-NLS-1$ // the pages to display in the wizard private final GradleCreateWorkspaceCompositeWizardPage newGradleWorkspaceCompositePage; private final GradleImportOptionsWizardPage compositeImportOptionsPage; private final GradleRootProjectWizardPage compositeRootProjectPage; + + // the controller that contain the wizard logic + private final CompositeImportWizardController importController; + private final CompositeCreationWizardController creationController; + private final CompositeRootProjectWizardController rootProjectController; + + // working set manager + private IWorkingSetManager workingSetManager; + /** * Creates a new instance and uses the {@link org.eclipse.jface.dialogs.DialogSettings} from {@link org.eclipse.buildship.ui.internal.UiPlugin}.. @@ -52,23 +58,26 @@ public WorkspaceCompositeCreationWizard() { * @param dialogSettings the dialog settings to store/retrieve dialog preferences */ public WorkspaceCompositeCreationWizard(IDialogSettings dialogSettings) { - super(PREF_SHOW_WELCOME_PAGE); // store the dialog settings on the wizard and use them to retrieve / persist the most // recent values entered by the user setDialogSettings(dialogSettings); + + this.workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); + + // instantiate the controllers for this wizard + this.importController = new CompositeImportWizardController(this); + this.creationController = new CompositeCreationWizardController(this); + this.rootProjectController = new CompositeRootProjectWizardController(this); // instantiate the pages and pass the configuration objects that serve as // the data models of the wizard - this.newGradleWorkspaceCompositePage = new GradleCreateWorkspaceCompositeWizardPage(); - this.compositeImportOptionsPage = new GradleImportOptionsWizardPage( - WorkspaceCompositeWizardMessages.Title_NewGradleImportOptionsWizardPage, - WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeOptionsWizardPageDefault, - WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeImportOptionsWizardPageContext); - this.compositeRootProjectPage = new GradleRootProjectWizardPage( - WorkspaceCompositeWizardMessages.Title_NewGradleCompositeRootWizardPage, - WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositePreviewWizardPageDefault, - WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeCompositeRootWizardPageContext); + final CompositeConfiguration compositeConfiguration = this.importController.getConfiguration(); + final CompositeCreationConfiguration creationConfiguration = this.creationController.getConfiguration(); + final CompositeRootProjectConfiguration rootProjectConfiguration = this.rootProjectController.getConfiguration(); + this.newGradleWorkspaceCompositePage = new GradleCreateWorkspaceCompositeWizardPage(compositeConfiguration, creationConfiguration); + this.compositeImportOptionsPage = new GradleImportOptionsWizardPage(compositeConfiguration); + this.compositeRootProjectPage = new GradleRootProjectWizardPage(compositeConfiguration, rootProjectConfiguration); } @Override @@ -98,7 +107,7 @@ public void addPages() { @Override public boolean performFinish() { - return false; + return this.importController.performCreateComposite(getContainer(), this.workingSetManager); } @Override diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java index 47024e2a61..c77b957e5d 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java @@ -29,6 +29,11 @@ public final class WorkspaceCompositeWizardMessages extends NLS { public static String Label_CompositeName; public static String InfoMessage_CompositeRootWizardPageDefault; + + public static String WarningMessage_GradleWorkspaceComposite_NameWhitespaces; + public static String WarningMessage_GradleWorkspaceComposite_NameEmpty; + public static String WarningMessage_GradleWorkspaceComposite_CompositeNameExists; + public static String WarningMessage_GradleWorkspaceComposite_CompositeEmpty; public static String InfoMessage_NewGradleWorkspaceCompositeWizardPageDefault; public static String InfoMessage_NewGradleWorkspaceCompositeOptionsWizardPageDefault; diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/CompositePropertyChangeListener.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/CompositePropertyChangeListener.java new file mode 100644 index 0000000000..1ed990e271 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/CompositePropertyChangeListener.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2015 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - initial implemenation + */ + +package org.eclipse.buildship.ui.internal.workspace; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.eclipse.buildship.core.internal.CorePlugin; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.IGradleCompositeIDs; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.IWorkingSetManager; +import org.eclipse.ui.PlatformUI; + +/** + * Listener class for {@link org.eclipse.ui.internal.dialogs.WorkingSetSelectionDialog}. Contains file composite properties file + * deletion algorithm with backup to ensure cancel function for WorkingSetSelectionDialog. + * @author kuzniarz + */ +public class CompositePropertyChangeListener implements IPropertyChangeListener { + + private final Map compositePropertiesBackup = new HashMap(); + IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); + + @Override + public void propertyChange(PropertyChangeEvent event) { + if (compositeRemovalCausedEvent(event)) { + try { + IWorkingSet removed = (IWorkingSet)event.getOldValue(); + if (isNotAggregate(removed) && removed.getId().equals(IGradleCompositeIDs.NATURE)) { + File compositePropertiesFile = CorePlugin.getInstance().getStateLocation().append("workspace-composites").append(removed.getName()).toFile(); + backupCompositeProperties(removed, compositePropertiesFile); + Files.deleteIfExists(compositePropertiesFile.toPath()); + } + } catch (IOException e) { + e.printStackTrace(); + } + } else if (compositeAddingCausedEvent(event)) { + try { + IWorkingSet added = (IWorkingSet)event.getNewValue(); + if (isNotAggregate(added) && added.getId().equals(IGradleCompositeIDs.NATURE)) { + restoreCompositeProperties(added.getName()); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private boolean isNotAggregate(IWorkingSet removed) { + return !removed.getName().contains(":"); + } + + private void restoreCompositeProperties(String compositeName) throws FileNotFoundException, IOException { + if (compositePropertiesBackup.containsKey(compositeName)) { + File compositePropertiesFile = CorePlugin.getInstance().getStateLocation().append("workspace-composites").append(compositeName).toFile(); + FileOutputStream out = new FileOutputStream(compositePropertiesFile.getAbsoluteFile()); + compositePropertiesBackup.get(compositeName).store(out, " "); + compositePropertiesBackup.remove(compositeName); + out.close(); + } else { + //New Composite is being created! + } + } + + private void backupCompositeProperties(IWorkingSet removed, File compositePropertiesFile) + throws FileNotFoundException, IOException { + Properties compositeProperties = new Properties(); + FileInputStream input = new FileInputStream(compositePropertiesFile); + compositeProperties.load(input); + input.close(); + compositePropertiesBackup.put(removed.getName(), compositeProperties); + } + + private boolean compositeAddingCausedEvent(PropertyChangeEvent event) { + return event.getProperty().equals(IWorkingSetManager.CHANGE_WORKING_SET_ADD) && + event.getNewValue() != null; + } + + private boolean compositeRemovalCausedEvent(PropertyChangeEvent event) { + return event.getProperty().equals(IWorkingSetManager.CHANGE_WORKING_SET_REMOVE) && + event.getOldValue() != null; + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/RemoveCompositeHandler.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/RemoveCompositeHandler.java new file mode 100644 index 0000000000..7fe9e2bbac --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/RemoveCompositeHandler.java @@ -0,0 +1,31 @@ +package org.eclipse.buildship.ui.internal.workspace; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; + +public class RemoveCompositeHandler extends AbstractHandler implements IHandler { + + private IStructuredSelection initialSelection; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + // TODO Auto-generated method stub + //HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().close(); + IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().getActiveWorkbenchWindow(); + + if (activeWorkbenchWindow != null) { + ISelection selection= activeWorkbenchWindow.getSelectionService().getSelection(); + if (selection instanceof IStructuredSelection) + initialSelection = (IStructuredSelection)selection; + } + return null; + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/StartupSetup.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/StartupSetup.java new file mode 100644 index 0000000000..35c69a406d --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/StartupSetup.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2015 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - initial implemenation + */ + +package org.eclipse.buildship.ui.internal.workspace; + +import org.eclipse.ui.IStartup; +import org.eclipse.ui.IWorkingSetManager; +import org.eclipse.ui.PlatformUI; + +public class StartupSetup implements IStartup { + + @Override + public void earlyStartup() { + IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); + + manager.addPropertyChangeListener(new CompositePropertyChangeListener()); + } + +} 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 82dcb3f181..7337877a6f 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 @@ -9,18 +9,24 @@ # Sebastian Kuzniarz (Diebold Nixdorf Inc.) - initial API and implementation and initial documentation # +Title_GradleWorkspaceCompositeConfigurationPage=Gradle Composite Title_GradleImportOptionsWizardPage=Import Options Title_CompositeRootWizardPage=Composite Root -Title_NewGradleWorkspaceCompositeWizardPage=Create a Workspace Composite +Title_NewGradleWorkspaceCompositeWizardPage=Gradle Workspace Composite Title_NewGradleImportOptionsWizardPage=Import Options Title_NewGradleCompositeRootWizardPage=Composite Root Label_CompositeName=Composite name +WarningMessage_GradleWorkspaceComposite_NameWhitespaces=Composite names should not contain whitespaces +WarningMessage_GradleWorkspaceComposite_NameEmpty=Please enter a composite name +WarningMessage_GradleWorkspaceComposite_CompositeNameExists=Composite name already exists +WarningMessage_GradleWorkspaceComposite_CompositeEmpty=Gradle Composite does not have any elements + InfoMessage_CompositeRootWizardPageDefault=Specify an optional Root Project to apply when creating and interacting with the Gradle composite. -InfoMessage_NewGradleWorkspaceCompositeWizardPageDefault=Enter a composite name. +InfoMessage_NewGradleWorkspaceCompositeWizardPageDefault=Specify composite name and Gradle projects to be included in Gradle composite. InfoMessage_NewGradleWorkspaceCompositeOptionsWizardPageDefault=Specify optional import options to apply when creating and interacting with the Gradle composite. InfoMessage_NewGradleWorkspaceCompositePreviewWizardPageDefault=Specify an optional Root Project to apply when creating and interacting with the Gradle composite. From 49666ab9d15cc015a8c8e0463ab6bf4893a51b43 Mon Sep 17 00:00:00 2001 From: kuzniarz Date: Thu, 14 May 2020 16:51:49 +0200 Subject: [PATCH 04/15] Fixed first composite creation Composite properties file creation was failing if properties directory was not existent Signed-off-by: kuzniarz --- .../workspacecomposite/CompositeImportWizardController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java index 266f6ce658..9170ad33c7 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java @@ -211,7 +211,8 @@ public boolean performCreateComposite(IWizardContainer container, IWorkingSetMan workingSet.setId(IGradleCompositeIDs.NATURE); workingSetManager.addWorkingSet(workingSet); - + compositePreferenceFile.getParentFile().mkdir(); + compositePreferenceFile.createNewFile(); FileOutputStream out = new FileOutputStream(compositePreferenceFile.getAbsoluteFile()); Properties prop = getConfiguration().toCompositeProperties().toProperties(); prop.store(out, " "); From b562d167357d8cd10095274d9ba98b4fe306eebc Mon Sep 17 00:00:00 2001 From: Donat Csikos Date: Fri, 15 May 2020 17:50:45 +0200 Subject: [PATCH 05/15] Guess fix for possible merge error --- .../preferences/GradleWorkspaceCompositePreferencePage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java index ae35c9a68c..6d81e40074 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java @@ -58,7 +58,7 @@ protected Control createContents(Composite parent) { this.workspaceCompositeNameText = new Text(workspaceCompositeNameComposite, SWT.BORDER); this.workspaceCompositeNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(this.gradleWorkspaceCompositeSettingsComposite, false); // TODO (donat) was this properly merged? + this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(this.gradleWorkspaceCompositeSettingsComposite, true); GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(3, SWT.DEFAULT).applyTo(this.gradleProjectCheckboxtreeComposite); return this.gradleWorkspaceCompositeSettingsComposite; From c9a60c14e892f0fa2cadde4b40166016e4f6f1d1 Mon Sep 17 00:00:00 2001 From: Donat Csikos Date: Fri, 15 May 2020 17:53:59 +0200 Subject: [PATCH 06/15] Make source validation tasks pass --- .../composite/WorkingSetProperyTester.java | 16 +- .../preferences/AbstractPropertiesPage.java | 26 +- ...eCompositeImportOptionsPreferencePage.java | 42 +- ...dleCompositeRootProjectPreferencePage.java | 44 +- ...reateWorkspaceCompositePreferencePage.java | 494 +++++++++--------- ...radleWorkspaceCompositePreferencePage.java | 2 +- ...xternalProjectDialogSelectionListener.java | 121 +++-- .../util/widget/GradleProjectGroup.java | 73 +-- .../internal/view/task/RemoveComposite.java | 66 ++- .../AbstractCompositeWizardPage.java | 28 +- .../CompositeConfiguration.java | 24 +- .../CompositeCreationConfiguration.java | 42 +- .../CompositeCreationWizardController.java | 74 +-- .../CompositeImportWizardController.java | 78 ++- .../CompositeRootProjectConfiguration.java | 74 +-- .../CompositeRootProjectWizardController.java | 58 +- .../ExternalGradleProject.java | 42 +- .../ExternalGradleProjectAdapter.java | 22 +- .../ExternalProjectAdapterFactory.java | 33 +- .../GradleImportOptionsWizardPage.java | 14 +- .../GradleRootProjectWizardPage.java | 68 +-- .../GradleWorkspaceCompositeUpdater.java | 415 ++++++++------- .../IGradleCompositeIDs.java | 16 +- .../WorkspaceCompositeWizardMessages.java | 4 +- .../CompositePropertyChangeListener.java | 133 +++-- .../workspace/RemoveCompositeHandler.java | 41 +- .../ui/internal/workspace/StartupSetup.java | 27 +- 27 files changed, 1082 insertions(+), 995 deletions(-) diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/composite/WorkingSetProperyTester.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/composite/WorkingSetProperyTester.java index 36da6eef8b..f05b3b6d40 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/composite/WorkingSetProperyTester.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/composite/WorkingSetProperyTester.java @@ -1,10 +1,12 @@ -/* - * Copyright (c) 2018 the original author or authors. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.composite; diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/AbstractPropertiesPage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/AbstractPropertiesPage.java index 57372c91c1..ec8b3227a9 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/AbstractPropertiesPage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/AbstractPropertiesPage.java @@ -1,14 +1,12 @@ -/* - * Copyright (c) 2015 the original author or authors. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. * - * Contributors: - * Etienne Studer & Donát Csikós (Gradle Inc.) - initial API and implementation and initial documentation - * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - refactored HelpContextIdProvider - */ + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.preferences; @@ -32,8 +30,8 @@ */ public abstract class AbstractPropertiesPage extends WizardPage { - private final CompositeConfiguration configuration; - + private final CompositeConfiguration configuration; + /** * Constructor setting up the main messages and the validation facility for this wizard page. * @@ -51,10 +49,10 @@ protected AbstractPropertiesPage(String name, String title, String defaultMessag // set the basic message and the attached image setTitle(title); - setDescription(defaultMessage); + setDescription(defaultMessage); setImageDescriptor(ImageDescriptor.createFromFile(GradleCreateWorkspaceCompositeWizardPage.class, "/icons/full/wizban/wizard.png")); //$NON-NLS-1$ } - + protected CompositeConfiguration getConfiguration() { return this.configuration; } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java index f0331fe736..beb840934d 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java @@ -65,8 +65,8 @@ protected Control createContents(Composite parent) { } private void initValues() { - IWorkingSet composite = getTargetComposite(); - + IWorkingSet composite = getTargetComposite(); + BuildConfiguration buildConfig = CorePlugin.configurationManager().loadCompositeConfiguration(composite).getBuildConfiguration(); boolean overrideWorkspaceSettings = buildConfig.isOverrideWorkspaceSettings(); @@ -95,25 +95,25 @@ private void addListeners() { @Override public boolean performOk() { - IWorkingSet composite = getTargetComposite(); - ConfigurationManager manager = CorePlugin.configurationManager(); - CompositeConfiguration currentConfig = manager.loadCompositeConfiguration(composite); - - BuildConfiguration updatedConfig = manager.createBuildConfiguration(currentConfig.getBuildConfiguration().getRootProjectDirectory(), - this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().getSelection(), - this.gradleProjectSettingsComposite.getGradleDistributionGroup().getDistribution().toGradleDistribution(), - this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getGradleUserHome(), - this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJavaHome(), - this.gradleProjectSettingsComposite.getBuildScansCheckbox().getSelection(), - this.gradleProjectSettingsComposite.getOfflineModeCheckbox().getSelection(), - this.gradleProjectSettingsComposite.getAutoSyncCheckbox().getSelection(), - this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getArguments(), - this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJvmArguments(), - this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().getSelection(), - this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().getSelection()); - CompositeConfiguration compConf = new DefaultCompositeConfiguration(currentConfig.getCompositeDir(), composite.getElements(), updatedConfig, currentConfig.projectAsCompositeRoot() ,currentConfig.getRootProject()); - manager.saveCompositeConfiguration(compConf); - return true; + IWorkingSet composite = getTargetComposite(); + ConfigurationManager manager = CorePlugin.configurationManager(); + CompositeConfiguration currentConfig = manager.loadCompositeConfiguration(composite); + + BuildConfiguration updatedConfig = manager.createBuildConfiguration(currentConfig.getBuildConfiguration().getRootProjectDirectory(), + this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getGradleDistributionGroup().getDistribution().toGradleDistribution(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getGradleUserHome(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJavaHome(), + this.gradleProjectSettingsComposite.getBuildScansCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getOfflineModeCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getAutoSyncCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getArguments(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJvmArguments(), + this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().getSelection()); + CompositeConfiguration compConf = new DefaultCompositeConfiguration(currentConfig.getCompositeDir(), composite.getElements(), updatedConfig, currentConfig.projectAsCompositeRoot() ,currentConfig.getRootProject()); + manager.saveCompositeConfiguration(compConf); + return true; } @SuppressWarnings("cast") diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java index 9657c360c7..7ffa553681 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java @@ -68,20 +68,20 @@ private Layout createLayout() { } public GradleCompositeRootProjectPreferencePage() { - this.rootProjectValidator = Validators.optionalDirectoryValidator("Root project"); + this.rootProjectValidator = Validators.optionalDirectoryValidator("Root project"); } @Override protected Control createContents(Composite parent) { - this.rootProjectSettingsComposite = buildRootProjectSettingsComposite(parent); + this.rootProjectSettingsComposite = buildRootProjectSettingsComposite(parent); addListeners(); initValues(); return this.rootProjectSettingsComposite; } - private Composite buildRootProjectSettingsComposite(Composite parent) { - Composite rootProjectComposite = new Composite(parent, SWT.WRAP); - rootProjectComposite.setLayout(createLayout()); + private Composite buildRootProjectSettingsComposite(Composite parent) { + Composite rootProjectComposite = new Composite(parent, SWT.WRAP); + rootProjectComposite.setLayout(createLayout()); this.projectAsCompositeRootCheckbox = new Button(rootProjectComposite, SWT.CHECK); this.projectAsCompositeRootCheckbox.setText("Use project as composite root"); @@ -112,17 +112,17 @@ private Composite buildRootProjectSettingsComposite(Composite parent) { this.selectRootProject.setText(WorkspaceCompositeWizardMessages.Button_Select_RootProject); this.selectRootProject.setEnabled(false); return rootProjectComposite; - } + } private void initValues() { - IWorkingSet composite = getTargetComposite(); + IWorkingSet composite = getTargetComposite(); this.compositeConfig = CorePlugin.configurationManager().loadCompositeConfiguration(composite); boolean useProjectAsCompositeRoot = this.compositeConfig.projectAsCompositeRoot(); this.projectAsCompositeRootCheckbox.setSelection(useProjectAsCompositeRoot); - this.workspaceCompositeRootProjectLabel.setText(this.compositeConfig.getRootProject().toString()); - updateEnablement(); + this.workspaceCompositeRootProjectLabel.setText(this.compositeConfig.getRootProject().toString()); + updateEnablement(); } private void addListeners() { @@ -143,8 +143,8 @@ public void widgetDefaultSelected(SelectionEvent e) { File rootProjectDir = this.workspaceCompositeRootProjectLabel.getText().isEmpty() ? null: new File(this.workspaceCompositeRootProjectLabel.getText()); this.workspaceCompositeRootProjectLabel.addModifyListener(new ValidatingListener<>(this, () -> rootProjectDir, this.rootProjectValidator)); - this.selectRootProject.addSelectionListener(new DirectoryDialogSelectionListener(this.getShell(), this.workspaceCompositeRootProjectLabel, "Root project")); - } + this.selectRootProject.addSelectionListener(new DirectoryDialogSelectionListener(this.getShell(), this.workspaceCompositeRootProjectLabel, "Root project")); + } } public void updateEnablement() { @@ -168,16 +168,16 @@ public void dispose() { @Override public boolean performOk() { - IWorkingSet composite = getTargetComposite(); - ConfigurationManager manager = CorePlugin.configurationManager(); - CompositeConfiguration currentConfig = manager.loadCompositeConfiguration(composite); - - CompositeConfiguration compConf = new DefaultCompositeConfiguration(currentConfig.getCompositeDir(), - composite.getElements(), - currentConfig.getBuildConfiguration(), - this.projectAsCompositeRootCheckbox.getSelection(), - new File(this.workspaceCompositeRootProjectLabel.getText())); - manager.saveCompositeConfiguration(compConf); - return true; + IWorkingSet composite = getTargetComposite(); + ConfigurationManager manager = CorePlugin.configurationManager(); + CompositeConfiguration currentConfig = manager.loadCompositeConfiguration(composite); + + CompositeConfiguration compConf = new DefaultCompositeConfiguration(currentConfig.getCompositeDir(), + composite.getElements(), + currentConfig.getBuildConfiguration(), + this.projectAsCompositeRootCheckbox.getSelection(), + new File(this.workspaceCompositeRootProjectLabel.getText())); + manager.saveCompositeConfiguration(compConf); + return true; } } 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 6ea0fcf741..cee6afe401 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 @@ -1,14 +1,12 @@ -/* - * Copyright (c) 2015 the original author or authors. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. * - * Contributors: - * Simon Scholz (vogella GmbH) - initial API and implementation and initial documentation - * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - adaptation and customization for workspace composite wizard - */ + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.preferences; @@ -58,242 +56,244 @@ * composite name and included projects. */ public final class GradleCreateWorkspaceCompositePreferencePage extends AbstractPropertiesPage - implements IWorkingSetPage { - - private final CompositeCreationConfiguration creationConfiguration; - - @SuppressWarnings("unused") - private Text workspaceCompositeNameText; - private Label compositeName; - private GradleProjectGroup gradleProjectCheckboxtreeComposite; - - private static IWorkingSet gradleComposite; - private boolean firstCheck; - private static CompositeImportWizardController importController; - - public GradleCreateWorkspaceCompositePreferencePage(CompositeConfiguration importConfiguration, - CompositeCreationConfiguration creationConfiguration) { - super("NewGradleWorkspaceComposite", //$NON-NLS-1$ - WorkspaceCompositeWizardMessages.Title_NewGradleWorkspaceCompositeWizardPage, - WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeWizardPageDefault, importConfiguration, ImmutableList.of(creationConfiguration.getCompositeName(), - creationConfiguration.getCompositeProjects())); - gradleComposite = null; - this.creationConfiguration = creationConfiguration; - firstCheck = true; - } - - public GradleCreateWorkspaceCompositePreferencePage() { - this(getCompositeImportConfiguration(), getCompositeCreationConfiguration()); - } - - private IWizardPage buildImportOptionsWizardPage() { - IWizardPage page = new GradleImportOptionsWizardPage(getConfiguration()); - page.setWizard(getWizard()); - return page; - } - - protected String getPageId() { - return "org.eclipse.buildship.ui.GradleCompositePage"; //$NON-NLS-1$ - } - - private static CompositeCreationConfiguration getCompositeCreationConfiguration() { - ArrayList compositeElements = new ArrayList(); - String compositeName = gradleComposite != null ? gradleComposite.getName() : ""; - CompositeCreationWizardController creationController = new CompositeCreationWizardController(compositeName, compositeElements); - return creationController.getConfiguration(); - } - - private static CompositeConfiguration getCompositeImportConfiguration() { - importController = new CompositeImportWizardController(null); - return importController.getConfiguration(); - } - - @Override - public void createControl(Composite parent) { - super.createControl(parent); - } - - @Override - protected void createWidgets(Composite root) { - root.setLayout(LayoutUtils.newGridLayout(3)); - createContent(root); - } - - private void createContent(Composite root) { - - // composite name container - Composite workspaceCompositeNameComposite = new Composite(root, SWT.FILL); - GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 5).numColumns(2) - .applyTo(workspaceCompositeNameComposite); - GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).span(3, SWT.DEFAULT) - .applyTo(workspaceCompositeNameComposite); - - // composite name label - this.compositeName = new Label(workspaceCompositeNameComposite, SWT.NONE); - this.compositeName.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); - this.compositeName.setText(WorkspaceCompositeWizardMessages.Label_CompositeName); - - // composite name text field - this.workspaceCompositeNameText = new Text(workspaceCompositeNameComposite, SWT.BORDER); - this.workspaceCompositeNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - - this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(root, (gradleComposite != null)); - GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(3, SWT.DEFAULT) - .applyTo(this.gradleProjectCheckboxtreeComposite); - - addListeners(); - - if (gradleComposite != null) { - workspaceCompositeNameText.setText(gradleComposite.getName()); - } - } - - private void addListeners() { - this.workspaceCompositeNameText.addModifyListener(new ModifyListener() { - - @Override - public void modifyText(ModifyEvent e) { - updateLocation(); - validateInput(); - } - }); - this.gradleProjectCheckboxtreeComposite.getCheckboxTree().addListener(SWT.Selection, new Listener() { - - @Override - public void handleEvent(Event event) { - updateCompositeProjects(); - validateInput(); - } - }); - } - - protected void updateCompositeProjects() { - List projectList = new ArrayList(); - - for (TreeItem treeElement : gradleProjectCheckboxtreeComposite.getCheckboxTree().getItems()) { - if (treeElement.getChecked() == true) { - if (treeElement.getText().contains(" (External): ")) { - //String[] treeValues = treeElement.getText().replace(" (External): ", "$").split("\\$"); - // treeValues[0] contains the project name - // treeValues[1] contains the file path - //File externalFolder = new File(treeValues[1]); - projectList.add(null); - } else { - projectList.add(ResourcesPlugin.getWorkspace().getRoot().getProject(treeElement.getText())); - } - } - } - getConfiguration().getProjectList().setValue(projectList.toArray(new IAdaptable[projectList.size()])); - this.creationConfiguration.setCompositeProjects(projectList); - } - - private void updateLocation() { - File parentLocation = CorePlugin.getInstance().getStateLocation().append("workspace-composites").toFile(); - File projectDir = parentLocation != null ? new File(parentLocation, this.workspaceCompositeNameText.getText()) - : null; - - // always update project name last to ensure project name validation errors have - // precedence in the UI - getConfiguration().getCompositePreferencesDir().setValue(projectDir); - this.creationConfiguration.setCompositeName(this.workspaceCompositeNameText.getText()); - } - - @Override - protected String getPageContextInformation() { - return WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeWizardPageContext; - } - - @Override - public void finish() { - updateCompositeProjects(); - String workspaceCompositeName = workspaceCompositeNameText.getText(); - IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); - - try { - File compositePreferenceFile = CorePlugin.getInstance().getStateLocation() - .append("workspace-composites").append(workspaceCompositeName).toFile(); - - if (gradleComposite == null) { - gradleComposite = workingSetManager.createWorkingSet(workspaceCompositeName, - getConfiguration().getProjectList().getValue()); - gradleComposite.setId(IGradleCompositeIDs.NATURE); - } else { - IAdaptable[] oldElements = gradleComposite.getElements(); - if (!gradleComposite.getName().equals(workspaceCompositeNameText.getText())) { - gradleComposite.setName(workspaceCompositeNameText.getText()); - } - - if (!oldElements.equals(getConfiguration().getProjectList().getValue())) { - gradleComposite.setElements(getConfiguration().getProjectList().getValue()); - } - } - FileOutputStream out = new FileOutputStream(compositePreferenceFile.getAbsoluteFile()); - Properties prop = getConfiguration().toCompositeProperties().toProperties(); - prop.store(out, " "); - out.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Override - public IWorkingSet getSelection() { - return gradleComposite; - } - - @Override - public void setSelection(IWorkingSet workingSet) { - Assert.isNotNull(workingSet, "Composite must not be null"); //$NON-NLS-1$ - gradleComposite = workingSet; - if (getContainer() == null && getShell() != null && workspaceCompositeNameText != null) { - workspaceCompositeNameText.setText(gradleComposite.getName()); - } - } - - @Override - public IWizardPage getNextPage() { - return buildImportOptionsWizardPage(); - } - - protected void validateInput() { - String errorMessage = null; - String infoMessage = null; - String newText= workspaceCompositeNameText.getText(); - - if (newText.equals(newText.trim()) == false) - errorMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_NameWhitespaces; - if (newText.isEmpty()) { - if (firstCheck) { - setPageComplete(false); - firstCheck= false; - return; - } else - errorMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_NameEmpty; - } - - firstCheck= false; - - if (errorMessage == null && (gradleComposite == null || newText.equals(gradleComposite.getName()) == false)) { - IWorkingSet[] workingSets= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets(); - for (int i= 0; i < workingSets.length; i++) { - if (newText.equals(workingSets[i].getName())) { - errorMessage= WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_CompositeNameExists; - } - } - } - - if (!hasSelectedElement()) { - infoMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_CompositeEmpty; - } - - setMessage(infoMessage, INFORMATION); - setErrorMessage(errorMessage); - setPageComplete(errorMessage == null); - } - - private boolean hasSelectedElement() { - return this.creationConfiguration.getCompositeProjects().getValue().size() > 0; - } + implements IWorkingSetPage { + + private final CompositeCreationConfiguration creationConfiguration; + + @SuppressWarnings("unused") + private Text workspaceCompositeNameText; + private Label compositeName; + private GradleProjectGroup gradleProjectCheckboxtreeComposite; + + private static IWorkingSet gradleComposite; + private boolean firstCheck; + private static CompositeImportWizardController importController; + + public GradleCreateWorkspaceCompositePreferencePage(CompositeConfiguration importConfiguration, + CompositeCreationConfiguration creationConfiguration) { + super("NewGradleWorkspaceComposite", //$NON-NLS-1$ + WorkspaceCompositeWizardMessages.Title_NewGradleWorkspaceCompositeWizardPage, + WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeWizardPageDefault, importConfiguration, ImmutableList.of(creationConfiguration.getCompositeName(), + creationConfiguration.getCompositeProjects())); + gradleComposite = null; + this.creationConfiguration = creationConfiguration; + this.firstCheck = true; + } + + public GradleCreateWorkspaceCompositePreferencePage() { + this(getCompositeImportConfiguration(), getCompositeCreationConfiguration()); + } + + private IWizardPage buildImportOptionsWizardPage() { + IWizardPage page = new GradleImportOptionsWizardPage(getConfiguration()); + page.setWizard(getWizard()); + return page; + } + + protected String getPageId() { + return "org.eclipse.buildship.ui.GradleCompositePage"; //$NON-NLS-1$ + } + + private static CompositeCreationConfiguration getCompositeCreationConfiguration() { + ArrayList compositeElements = new ArrayList<>(); + String compositeName = gradleComposite != null ? gradleComposite.getName() : ""; + CompositeCreationWizardController creationController = new CompositeCreationWizardController(compositeName, compositeElements); + return creationController.getConfiguration(); + } + + private static CompositeConfiguration getCompositeImportConfiguration() { + importController = new CompositeImportWizardController(null); + return importController.getConfiguration(); + } + + @Override + public void createControl(Composite parent) { + super.createControl(parent); + } + + @Override + protected void createWidgets(Composite root) { + root.setLayout(LayoutUtils.newGridLayout(3)); + createContent(root); + } + + private void createContent(Composite root) { + + // composite name container + Composite workspaceCompositeNameComposite = new Composite(root, SWT.FILL); + GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 5).numColumns(2) + .applyTo(workspaceCompositeNameComposite); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).span(3, SWT.DEFAULT) + .applyTo(workspaceCompositeNameComposite); + + // composite name label + this.compositeName = new Label(workspaceCompositeNameComposite, SWT.NONE); + this.compositeName.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + this.compositeName.setText(WorkspaceCompositeWizardMessages.Label_CompositeName); + + // composite name text field + this.workspaceCompositeNameText = new Text(workspaceCompositeNameComposite, SWT.BORDER); + this.workspaceCompositeNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(root, (gradleComposite != null)); + GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(3, SWT.DEFAULT) + .applyTo(this.gradleProjectCheckboxtreeComposite); + + addListeners(); + + if (gradleComposite != null) { + this.workspaceCompositeNameText.setText(gradleComposite.getName()); + } + } + + private void addListeners() { + this.workspaceCompositeNameText.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + updateLocation(); + validateInput(); + } + }); + this.gradleProjectCheckboxtreeComposite.getCheckboxTree().addListener(SWT.Selection, new Listener() { + + @Override + public void handleEvent(Event event) { + updateCompositeProjects(); + validateInput(); + } + }); + } + + protected void updateCompositeProjects() { + List projectList = new ArrayList<>(); + + for (TreeItem treeElement : this.gradleProjectCheckboxtreeComposite.getCheckboxTree().getItems()) { + if (treeElement.getChecked() == true) { + if (treeElement.getText().contains(" (External): ")) { + //String[] treeValues = treeElement.getText().replace(" (External): ", "$").split("\\$"); + // treeValues[0] contains the project name + // treeValues[1] contains the file path + //File externalFolder = new File(treeValues[1]); + projectList.add(null); + } else { + projectList.add(ResourcesPlugin.getWorkspace().getRoot().getProject(treeElement.getText())); + } + } + } + getConfiguration().getProjectList().setValue(projectList.toArray(new IAdaptable[projectList.size()])); + this.creationConfiguration.setCompositeProjects(projectList); + } + + private void updateLocation() { + File parentLocation = CorePlugin.getInstance().getStateLocation().append("workspace-composites").toFile(); + File projectDir = parentLocation != null ? new File(parentLocation, this.workspaceCompositeNameText.getText()) + : null; + + // always update project name last to ensure project name validation errors have + // precedence in the UI + getConfiguration().getCompositePreferencesDir().setValue(projectDir); + this.creationConfiguration.setCompositeName(this.workspaceCompositeNameText.getText()); + } + + @Override + protected String getPageContextInformation() { + return WorkspaceCompositeWizardMessages.InfoMessage_NewGradleWorkspaceCompositeWizardPageContext; + } + + @Override + public void finish() { + updateCompositeProjects(); + String workspaceCompositeName = this.workspaceCompositeNameText.getText(); + IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); + + try { + File compositePreferenceFile = CorePlugin.getInstance().getStateLocation() + .append("workspace-composites").append(workspaceCompositeName).toFile(); + + if (gradleComposite == null) { + gradleComposite = workingSetManager.createWorkingSet(workspaceCompositeName, + getConfiguration().getProjectList().getValue()); + gradleComposite.setId(IGradleCompositeIDs.NATURE); + } else { + IAdaptable[] oldElements = gradleComposite.getElements(); + if (!gradleComposite.getName().equals(this.workspaceCompositeNameText.getText())) { + gradleComposite.setName(this.workspaceCompositeNameText.getText()); + } + + if (!oldElements.equals(getConfiguration().getProjectList().getValue())) { + gradleComposite.setElements(getConfiguration().getProjectList().getValue()); + } + } + FileOutputStream out = new FileOutputStream(compositePreferenceFile.getAbsoluteFile()); + Properties prop = getConfiguration().toCompositeProperties().toProperties(); + prop.store(out, " "); + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + public IWorkingSet getSelection() { + return gradleComposite; + } + + @Override + public void setSelection(IWorkingSet workingSet) { + Assert.isNotNull(workingSet, "Composite must not be null"); //$NON-NLS-1$ + gradleComposite = workingSet; + if (getContainer() == null && getShell() != null && this.workspaceCompositeNameText != null) { + this.workspaceCompositeNameText.setText(gradleComposite.getName()); + } + } + + @Override + public IWizardPage getNextPage() { + return buildImportOptionsWizardPage(); + } + + protected void validateInput() { + String errorMessage = null; + String infoMessage = null; + String newText= this.workspaceCompositeNameText.getText(); + + if (newText.equals(newText.trim()) == false) { + errorMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_NameWhitespaces; + } + if (newText.isEmpty()) { + if (this.firstCheck) { + setPageComplete(false); + this.firstCheck= false; + return; + } else { + errorMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_NameEmpty; + } + } + + this.firstCheck= false; + + if (errorMessage == null && (gradleComposite == null || newText.equals(gradleComposite.getName()) == false)) { + IWorkingSet[] workingSets= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets(); + for (int i= 0; i < workingSets.length; i++) { + if (newText.equals(workingSets[i].getName())) { + errorMessage= WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_CompositeNameExists; + } + } + } + + if (!hasSelectedElement()) { + infoMessage = WorkspaceCompositeWizardMessages.WarningMessage_GradleWorkspaceComposite_CompositeEmpty; + } + + setMessage(infoMessage, INFORMATION); + setErrorMessage(errorMessage); + setPageComplete(errorMessage == null); + } + + private boolean hasSelectedElement() { + return this.creationConfiguration.getCompositeProjects().getValue().size() > 0; + } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java index 6d81e40074..70495b84a2 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java @@ -66,6 +66,6 @@ protected Control createContents(Composite parent) { @Override public boolean performOk() { - return true; + return true; } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/file/ExternalProjectDialogSelectionListener.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/file/ExternalProjectDialogSelectionListener.java index 21447250cb..4a5e611311 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/file/ExternalProjectDialogSelectionListener.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/file/ExternalProjectDialogSelectionListener.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ + package org.eclipse.buildship.ui.internal.util.file; import java.io.File; @@ -7,9 +17,8 @@ import java.util.Map; import java.util.Properties; -import org.eclipse.buildship.ui.internal.i18n.UiMessages; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; +import com.google.common.base.Preconditions; + import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; import org.eclipse.jface.viewers.TreeViewer; @@ -22,26 +31,24 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.TreeItem; -import com.google.common.base.Preconditions; +import org.eclipse.buildship.ui.internal.i18n.UiMessages; public class ExternalProjectDialogSelectionListener extends SelectionAdapter { - - - + private final Shell shell; private final TreeViewer projectTreeViewer; private final String title; private final Map externalProjectPaths; - - public ExternalProjectDialogSelectionListener(Shell shell, TreeViewer treeViewer, String entity) { + + public ExternalProjectDialogSelectionListener(Shell shell, TreeViewer treeViewer, String entity) { this.shell = Preconditions.checkNotNull(shell); this.projectTreeViewer = treeViewer; this.title = NLS.bind(UiMessages.Title_Select_0, entity); - ColumnViewerToolTipSupport.enableFor(projectTreeViewer); - externalProjectPaths = new HashMap(); - } - + ColumnViewerToolTipSupport.enableFor(this.projectTreeViewer); + this.externalProjectPaths = new HashMap<>(); + } + @Override public void widgetSelected(SelectionEvent e) { DirectoryDialog directoryDialog = new DirectoryDialog(this.shell, SWT.SHEET); @@ -56,52 +63,52 @@ public void widgetSelected(SelectionEvent e) { } } - private void addExternalProjectToProjectTree(String selectedDirectory) { - String projectDir = selectedDirectory; - File gradleSettingsFile = getGradleSettings(projectDir); - if (gradleSettingsFile.isFile()) { - try { - FileInputStream inputStream = new FileInputStream(gradleSettingsFile); - Properties gradleSettings = new Properties(); - gradleSettings.load(inputStream); - String projectName = getProjectName(gradleSettings); + private void addExternalProjectToProjectTree(String selectedDirectory) { + String projectDir = selectedDirectory; + File gradleSettingsFile = getGradleSettings(projectDir); + if (gradleSettingsFile.isFile()) { + try { + FileInputStream inputStream = new FileInputStream(gradleSettingsFile); + Properties gradleSettings = new Properties(); + gradleSettings.load(inputStream); + String projectName = getProjectName(gradleSettings); TreeItem jItem = new TreeItem(this.projectTreeViewer.getTree(), 0); jItem.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT)); jItem.setChecked(true); - jItem.setText(projectName + " (External): " + gradleSettingsFile.getParentFile().getPath()); - if (!externalProjectPaths.containsKey(gradleSettingsFile.getParentFile().getPath())) { - externalProjectPaths.put(gradleSettingsFile.getParentFile().getPath(), projectName); - } - } catch (IOException e) { - e.printStackTrace(); - } - } else { - MessageBox dialog = new MessageBox(this.shell, SWT.ICON_ERROR | SWT.OK); - dialog.setText("Error"); - dialog.setMessage("The selected directory is not a gradle project dir!"); - dialog.open(); - } - } - - private String getProjectName(Properties gradleSettings) { - //Refactored method to include String cleaning - return gradleSettings.get("rootProject.name").toString().replaceAll("'", "").replaceAll("\"", ""); - } - - private File getGradleSettings(String projectDir) { - File groovyFile = new File(projectDir + "\\settings.gradle"); - File kotlinFile = new File(projectDir + "\\settings.gradle.kts"); - if (groovyFile.exists()) { - return groovyFile; - } else if (kotlinFile.exists()) { - return kotlinFile; - } else { - return new File(""); - } - } - - public Map getExternalProjectPaths() { - return externalProjectPaths; - } + jItem.setText(projectName + " (External): " + gradleSettingsFile.getParentFile().getPath()); + if (!this.externalProjectPaths.containsKey(gradleSettingsFile.getParentFile().getPath())) { + this.externalProjectPaths.put(gradleSettingsFile.getParentFile().getPath(), projectName); + } + } catch (IOException e) { + e.printStackTrace(); + } + } else { + MessageBox dialog = new MessageBox(this.shell, SWT.ICON_ERROR | SWT.OK); + dialog.setText("Error"); + dialog.setMessage("The selected directory is not a gradle project dir!"); + dialog.open(); + } + } + + private String getProjectName(Properties gradleSettings) { + //Refactored method to include String cleaning + return gradleSettings.get("rootProject.name").toString().replaceAll("'", "").replaceAll("\"", ""); + } + + private File getGradleSettings(String projectDir) { + File groovyFile = new File(projectDir + "\\settings.gradle"); + File kotlinFile = new File(projectDir + "\\settings.gradle.kts"); + if (groovyFile.exists()) { + return groovyFile; + } else if (kotlinFile.exists()) { + return kotlinFile; + } else { + return new File(""); + } + } + + public Map getExternalProjectPaths() { + return this.externalProjectPaths; + } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java index fc33586146..b2094deda1 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java @@ -74,7 +74,9 @@ public void createWidgets() { fillCheckboxTreeWithProjects(); if (this.editMode) { configureTree(); - }this.gradleProjectTree.setUseHashlookup(true); + } + + this.gradleProjectTree.setUseHashlookup(true); this.buttonComposite = new Composite(this, SWT.NONE); this.buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1)); @@ -93,13 +95,14 @@ public void createWidgets() { private void addListener() { this.newGradleProject.addSelectionListener(new SelectionAdapter() { + @Override public void widgetSelected(SelectionEvent e) { WizardDialog wizard = new WizardDialog(getShell(), new ProjectCreationWizard()); if (wizard.open() == WizardDialog.OK) { fillCheckboxTreeWithProjects(); configureTree(); - }; + } } }); this.externalProjectListener = new ExternalProjectDialogSelectionListener(getShell(), this.gradleProjectTree, ""); @@ -130,34 +133,33 @@ public boolean hasSelectedItems() { private ArrayList getInitialTreeSelection() { ArrayList projectNames = new ArrayList<>(); BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { + @Override public void run() { IStructuredSelection projectSelection = null; - IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - if (page == null) { - return; - } + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + if (page == null) { + return; + } - IWorkbenchPart part= page.getActivePart(); - if (part == null) { - return; - } + IWorkbenchPart part = page.getActivePart(); + if (part == null) { + return; + } - try { - ISelectionProvider provider= part.getSite().getSelectionProvider(); - if (provider != null) { - ISelection selection = provider.getSelection(); - projectSelection = selection instanceof IStructuredSelection ? (IStructuredSelection) selection : StructuredSelection.EMPTY; - } - } catch (Exception e) { - return; + try { + ISelectionProvider provider = part.getSite().getSelectionProvider(); + if (provider != null) { + ISelection selection = provider.getSelection(); + projectSelection = selection instanceof IStructuredSelection ? (IStructuredSelection) selection : StructuredSelection.EMPTY; } + } catch (Exception e) { + return; + } + Object[] elements = projectSelection.toArray(); - Object[] elements= projectSelection.toArray(); - - - for (int i=0; i < elements.length; i++) { + for (int i = 0; i < elements.length; i++) { if (elements[i] instanceof IWorkingSet) { IWorkingSet ge = ((IWorkingSet) elements[i]); if (ge != null && ge.getId().equals(IGradleCompositeIDs.NATURE)) { @@ -173,24 +175,23 @@ public void run() { }); return projectNames; -} + } private void fillCheckboxTreeWithProjects() { this.gradleProjectTree.getTree().removeAll(); - try { - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - IProject[] projects = workspaceRoot.getProjects(); - for(int i = 0; i < projects.length; i++) { - IProject project = projects[i]; - if(project.hasNature(GradleProjectNature.ID)) { + try { + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + IProject[] projects = workspaceRoot.getProjects(); + for (int i = 0; i < projects.length; i++) { + IProject project = projects[i]; + if (project.hasNature(GradleProjectNature.ID)) { TreeItem jItem = new TreeItem(this.gradleProjectTree.getTree(), 0); jItem.setText(project.getName()); - } - } - } - catch(CoreException ce) { - ce.printStackTrace(); - } + } + } + } catch (CoreException ce) { + ce.printStackTrace(); + } } public Tree getCheckboxTree() { @@ -206,7 +207,7 @@ public Map getExternalProjectPathList() { } @Override - protected void checkSubclass() { + protected void checkSubclass() { // Disable the check that prevents subclassing of SWT components } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/RemoveComposite.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/RemoveComposite.java index 2af0ec4a98..0baf576549 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/RemoveComposite.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/RemoveComposite.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ + package org.eclipse.buildship.ui.internal.view.task; import org.eclipse.core.commands.ExecutionEvent; @@ -7,41 +17,41 @@ public class RemoveComposite implements IHandler { - @Override - public void addHandlerListener(IHandlerListener handlerListener) { - // TODO Auto-generated method stub + @Override + public void addHandlerListener(IHandlerListener handlerListener) { + // TODO Auto-generated method stub + + } - } + @Override + public void dispose() { + // TODO Auto-generated method stub - @Override - public void dispose() { - // TODO Auto-generated method stub + } - } + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - - // TODO Auto-generated method stub - return null; - } + // TODO Auto-generated method stub + return null; + } - @Override - public boolean isEnabled() { - // TODO Auto-generated method stub - return false; - } + @Override + public boolean isEnabled() { + // TODO Auto-generated method stub + return false; + } - @Override - public boolean isHandled() { - // TODO Auto-generated method stub - return false; - } + @Override + public boolean isHandled() { + // TODO Auto-generated method stub + return false; + } - @Override - public void removeHandlerListener(IHandlerListener handlerListener) { - // TODO Auto-generated method stub + @Override + public void removeHandlerListener(IHandlerListener handlerListener) { + // TODO Auto-generated method stub - } + } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeWizardPage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeWizardPage.java index f5bde8ac49..f5cf0082df 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeWizardPage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeWizardPage.java @@ -1,14 +1,12 @@ -/* - * Copyright (c) 2015 the original author or authors. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. * - * Contributors: - * Etienne Studer & Donát Csikós (Gradle Inc.) - initial API and implementation and initial documentation - * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - refactored HelpContextIdProvider - */ + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; @@ -39,9 +37,9 @@ */ public abstract class AbstractCompositeWizardPage extends WizardPage { - private final CompositeConfiguration configuration; + private final CompositeConfiguration configuration; private final List> observedProperties; - private final String defaultMessage; + private final String defaultMessage; /** * Constructor setting up the main messages and the validation facility for this wizard page. @@ -70,7 +68,7 @@ protected AbstractCompositeWizardPage(String name, String title, String defaultM ValidationListener listener = new ValidationListener() { @Override public void validationTriggered(Property source, Optional validationErrorMessage) { - validateInput(source, validationErrorMessage); + validateInput(source, validationErrorMessage); // we set the page to completed if all its properties are valid setPageComplete(isPageComplete()); } @@ -82,7 +80,7 @@ public void validationTriggered(Property source, Optional validationE } } /** - * This method is overided by the main composite creation page due to a different validation machanism + * This method is overided by the main composite creation page due to a different validation machanism. * @param source * @param validationErrorMessage */ @@ -117,7 +115,7 @@ protected CompositeConfiguration getConfiguration() { } protected List> getObservedProperties() { - return this.observedProperties; + return this.observedProperties; } @Override diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeConfiguration.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeConfiguration.java index bef3613aee..1335f86147 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeConfiguration.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeConfiguration.java @@ -78,11 +78,11 @@ public void setCompositePreferencesDir(File compositePreferencesDir) { } public Property getProjectList() { - return this.projectList; + return this.projectList; } public void setProjectList(IAdaptable[] projectList) { - this.projectList.setValue(projectList); + this.projectList.setValue(projectList); } public Property getOverrideWorkspaceConfiguration() { @@ -206,22 +206,22 @@ public void setRootProject(File rootProject) { } public CompositeProperties toCompositeProperties() { - return CompositeProperties.forRootProjectDirectory(getCompositePreferencesDir().getValue()) - .projectList(getProjectList().getValue()) - .overrideWorkspaceConfiguration(getOverrideWorkspaceConfiguration().getValue()) - .gradleDistribution(getDistribution().getValue().toGradleDistribution()) - .gradleUserHome(getGradleUserHome().getValue()) - .javaHome(getJavaHome().getValue()) - .buildScansEnabled(getBuildScansEnabled().getValue()) - .offlineMode(getOfflineMode().getValue()) - .autoSync(getAutoSync().getValue()) + return CompositeProperties.forRootProjectDirectory(getCompositePreferencesDir().getValue()) + .projectList(getProjectList().getValue()) + .overrideWorkspaceConfiguration(getOverrideWorkspaceConfiguration().getValue()) + .gradleDistribution(getDistribution().getValue().toGradleDistribution()) + .gradleUserHome(getGradleUserHome().getValue()) + .javaHome(getJavaHome().getValue()) + .buildScansEnabled(getBuildScansEnabled().getValue()) + .offlineMode(getOfflineMode().getValue()) + .autoSync(getAutoSync().getValue()) .arguments(getArguments().getValue()) .jvmArguments(getJvmArguments().getValue()) .showConsoleView(getShowConsoleView().getValue()) .showExecutionsView(getShowExecutionsView().getValue()) .projectAsCompositeRoot(getProjectAsCompositeRoot().getValue()) .rootProject(getRootProject().getValue()) - .build(); + .build(); } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationConfiguration.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationConfiguration.java index 3484cf8a1b..3c3e5bc3b2 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationConfiguration.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationConfiguration.java @@ -1,10 +1,12 @@ -/* - * Copyright (c) 2019 the original author or authors. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; @@ -16,29 +18,29 @@ import com.google.common.base.Preconditions; public class CompositeCreationConfiguration { - - private final Property compositeName; - private final Property> compositeProjects; + + private final Property compositeName; + private final Property> compositeProjects; public CompositeCreationConfiguration(Property compositeName, Property> compositeProjects) { this.compositeName = Preconditions.checkNotNull(compositeName); this.compositeProjects = Preconditions.checkNotNull(compositeProjects); } - public Property getCompositeName() { - return compositeName; - } - + public Property getCompositeName() { + return this.compositeName; + } + public void setCompositeName(String compositeName) { - this.compositeName.setValue(compositeName); + this.compositeName.setValue(compositeName); } - + public Property> getCompositeProjects() { - return compositeProjects; + return this.compositeProjects; } - + public void setCompositeProjects(List compositeProjects) { - this.compositeProjects.setValue(compositeProjects); + this.compositeProjects.setValue(compositeProjects); } - + } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationWizardController.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationWizardController.java index e93266e2be..9bf52530f2 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationWizardController.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationWizardController.java @@ -1,10 +1,12 @@ -/* - * Copyright (c) 2019 the original author or authors. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; @@ -26,43 +28,43 @@ public class CompositeCreationWizardController { private static final String SETTINGS_KEY_COMPOSITE_NAME = "composite_name"; //$NON-NLS-1$ private static final String SETTINGS_KEY_COMPOSITE_PROJECTS = "composite_projects"; //$NON-NLS-1$ - private final CompositeCreationConfiguration configuration; - - public CompositeCreationWizardController(IWizard compositeCreationWizard) { + private final CompositeCreationConfiguration configuration; + + public CompositeCreationWizardController(IWizard compositeCreationWizard) { // assemble configuration object that serves as the data model of the wizard Property compositeNameProperty = Property.create(Validators.uniqueWorkspaceCompositeNameValidator(WorkspaceCompositeWizardMessages.Label_CompositeName)); Property> compositeProjectsProperty = Property.create(Validators.>nullValidator()); - this.configuration = new CompositeCreationConfiguration(compositeNameProperty, compositeProjectsProperty); - - IDialogSettings dialogSettings = compositeCreationWizard.getDialogSettings(); - String compositeName = dialogSettings.get(SETTINGS_KEY_COMPOSITE_NAME); - List compositeProjects = ImmutableList.copyOf(getProjects(CollectionsUtils.nullToEmpty(dialogSettings.getArray(SETTINGS_KEY_COMPOSITE_PROJECTS)))); - - this.configuration.setCompositeName(compositeName); - this.configuration.setCompositeProjects(compositeProjects); - } - - public CompositeCreationWizardController(String compositeName, List compositeProjects) { + this.configuration = new CompositeCreationConfiguration(compositeNameProperty, compositeProjectsProperty); + + IDialogSettings dialogSettings = compositeCreationWizard.getDialogSettings(); + String compositeName = dialogSettings.get(SETTINGS_KEY_COMPOSITE_NAME); + List compositeProjects = ImmutableList.copyOf(getProjects(CollectionsUtils.nullToEmpty(dialogSettings.getArray(SETTINGS_KEY_COMPOSITE_PROJECTS)))); + + this.configuration.setCompositeName(compositeName); + this.configuration.setCompositeProjects(compositeProjects); + } + + public CompositeCreationWizardController(String compositeName, List compositeProjects) { // assemble configuration object that serves as the data model of the wizard Property compositeNameProperty = Property.create(Validators.uniqueWorkspaceCompositeNameValidator(WorkspaceCompositeWizardMessages.Label_CompositeName)); Property> compositeProjectsProperty = Property.create(Validators.>nullValidator()); - this.configuration = new CompositeCreationConfiguration(compositeNameProperty, compositeProjectsProperty); - - this.configuration.setCompositeName(compositeName); - this.configuration.setCompositeProjects(compositeProjects); - } - - private List getProjects(String[] projectArray) { - List projects = new ArrayList(); - for (String projectName : projectArray) { - projects.add(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName)); - } - return projects; - } - - + this.configuration = new CompositeCreationConfiguration(compositeNameProperty, compositeProjectsProperty); + + this.configuration.setCompositeName(compositeName); + this.configuration.setCompositeProjects(compositeProjects); + } + + private List getProjects(String[] projectArray) { + List projects = new ArrayList<>(); + for (String projectName : projectArray) { + projects.add(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName)); + } + return projects; + } + + public CompositeCreationConfiguration getConfiguration() { return this.configuration; } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java index 9170ad33c7..816cb2e00a 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java @@ -1,14 +1,12 @@ -/* - * Copyright (c) 2015 the original author or authors. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. * - * Contributors: - * Etienne Studer & Donát Csikós (Gradle Inc.) - initial API and implementation and initial documentation - * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - refactored WizardHelper - */ + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; @@ -45,10 +43,10 @@ * the wizard has to perform. */ public class CompositeImportWizardController { - - private static String PROJECT_CREATION_DIALOG_SETTINGS = "org.eclipse.buildship.ui.wizard.composite.creation"; - private IWorkingSet workingSet; + private static String PROJECT_CREATION_DIALOG_SETTINGS = "org.eclipse.buildship.ui.wizard.composite.creation"; + + private IWorkingSet workingSet; // keys to load/store project properties in the dialog setting private static final String SETTINGS_KEY_COMPOSITE_DIR = "composite_location"; //$NON-NLS-1$ @@ -86,14 +84,14 @@ public CompositeImportWizardController(IWizard compositeImportWizard) { // initialize values from the persisted dialog settings IDialogSettings dialogSettings; - + if (compositeImportWizard != null) { - dialogSettings = compositeImportWizard.getDialogSettings(); + dialogSettings = compositeImportWizard.getDialogSettings(); } else { - dialogSettings = getOrCreateDialogSection(UiPlugin.getInstance().getDialogSettings()); + dialogSettings = getOrCreateDialogSection(UiPlugin.getInstance().getDialogSettings()); } - + Optional projectDir = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_COMPOSITE_DIR)); String gradleDistributionString = dialogSettings.get(SETTINGS_KEY_GRADLE_DISTRIBUTION); Optional gradleUserHome = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_GRADLE_USER_HOME)); @@ -199,30 +197,30 @@ public void validationTriggered(Property source, Optional validationE public CompositeConfiguration getConfiguration() { return this.configuration; } - + public boolean performCreateComposite(IWizardContainer container, IWorkingSetManager workingSetManager) { - try { - File compositePreferenceFile = this.configuration.getCompositePreferencesDir().getValue(); - List projects = new ArrayList(); + try { + File compositePreferenceFile = this.configuration.getCompositePreferencesDir().getValue(); + List projects = new ArrayList<>(); for (IAdaptable project : getConfiguration().getProjectList().getValue()) { - projects.add((IProject) project); - } - workingSet = workingSetManager.createWorkingSet(compositePreferenceFile.getName(), projects.toArray(new IProject[projects.size()])); - workingSet.setId(IGradleCompositeIDs.NATURE); - workingSetManager.addWorkingSet(workingSet); - - compositePreferenceFile.getParentFile().mkdir(); - compositePreferenceFile.createNewFile(); - FileOutputStream out = new FileOutputStream(compositePreferenceFile.getAbsoluteFile()); - Properties prop = getConfiguration().toCompositeProperties().toProperties(); - prop.store(out, " "); - out.close(); - } catch (IOException e) { - e.printStackTrace(); - } - return true; + projects.add((IProject) project); + } + this.workingSet = workingSetManager.createWorkingSet(compositePreferenceFile.getName(), projects.toArray(new IProject[projects.size()])); + this.workingSet.setId(IGradleCompositeIDs.NATURE); + workingSetManager.addWorkingSet(this.workingSet); + + compositePreferenceFile.getParentFile().mkdir(); + compositePreferenceFile.createNewFile(); + FileOutputStream out = new FileOutputStream(compositePreferenceFile.getAbsoluteFile()); + Properties prop = getConfiguration().toCompositeProperties().toProperties(); + prop.store(out, " "); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return true; } - + private static IDialogSettings getOrCreateDialogSection(IDialogSettings dialogSettings) { IDialogSettings section = dialogSettings.getSection(PROJECT_CREATION_DIALOG_SETTINGS); if (section == null) { @@ -230,8 +228,8 @@ private static IDialogSettings getOrCreateDialogSection(IDialogSettings dialogSe } return section; } - + public IWorkingSet getWorkingSet() { - return workingSet; + return this.workingSet; } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectConfiguration.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectConfiguration.java index 9aa68aa56f..bfba41f604 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectConfiguration.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectConfiguration.java @@ -1,10 +1,12 @@ -/* - * Copyright (c) 2019 the original author or authors. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; @@ -16,34 +18,34 @@ import com.google.common.base.Preconditions; public class CompositeRootProjectConfiguration { - - private final Property useCompositeRoot; - private final Property rootProject; - - public CompositeRootProjectConfiguration(){ - this(Property.create(Validators.noOp()), Property.create(Validators.noOp())); - } - - public CompositeRootProjectConfiguration(Property useCompositeRoot, Property rootProject) { - this.useCompositeRoot = Preconditions.checkNotNull(useCompositeRoot); - this.rootProject = Preconditions.checkNotNull(rootProject); - } - - public Property getUseCompositeRoot() { - return useCompositeRoot; - } - - public void setUseCompositeRoot(Boolean useCompositeRoot) { - this.useCompositeRoot.setValue(useCompositeRoot); - } - - public Property getRootProject() { - return rootProject; - } - - public void setRootProject(File rootProject) { - this.rootProject.setValue(rootProject); - } - + + private final Property useCompositeRoot; + private final Property rootProject; + + public CompositeRootProjectConfiguration(){ + this(Property.create(Validators.noOp()), Property.create(Validators.noOp())); + } + + public CompositeRootProjectConfiguration(Property useCompositeRoot, Property rootProject) { + this.useCompositeRoot = Preconditions.checkNotNull(useCompositeRoot); + this.rootProject = Preconditions.checkNotNull(rootProject); + } + + public Property getUseCompositeRoot() { + return this.useCompositeRoot; + } + + public void setUseCompositeRoot(Boolean useCompositeRoot) { + this.useCompositeRoot.setValue(useCompositeRoot); + } + + public Property getRootProject() { + return this.rootProject; + } + + public void setRootProject(File rootProject) { + this.rootProject.setValue(rootProject); + } + } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectWizardController.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectWizardController.java index 6aeea4a2a0..b30f302052 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectWizardController.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeRootProjectWizardController.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ + package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; import java.io.File; @@ -12,28 +22,28 @@ public class CompositeRootProjectWizardController { - private static final String SETTINGS_KEY_USE_COMPOSITE_ROOT = "use_composite_root"; //$NON-NLS-1$ - private static final String SETTINGS_KEY_COMPOSITE_ROOT_PROJECT = "composite_root_project"; //$NON-NLS-1$ - - private final CompositeRootProjectConfiguration configuration; - - public CompositeRootProjectWizardController(IWizard compositeCreationWizard) { - // assemble configuration object that serves as the data model of the wizard - Property compositeNameProperty = Property.create(Validators.nullValidator()); - Property compositeProjectsProperty = Property.create(Validators.nonExistentDirectoryValidator(WorkspaceCompositeWizardMessages.Label_RootProject)); - - this.configuration = new CompositeRootProjectConfiguration(compositeNameProperty, compositeProjectsProperty); - - IDialogSettings dialogSettings = compositeCreationWizard.getDialogSettings(); - Boolean useCompositeRoot = dialogSettings.getBoolean(SETTINGS_KEY_USE_COMPOSITE_ROOT); - Optional compositeRootProject = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_COMPOSITE_ROOT_PROJECT)); - - this.configuration.setUseCompositeRoot(useCompositeRoot); - this.configuration.setRootProject(compositeRootProject.orNull()); - } - - public CompositeRootProjectConfiguration getConfiguration() { - return this.configuration; - } - + private static final String SETTINGS_KEY_USE_COMPOSITE_ROOT = "use_composite_root"; //$NON-NLS-1$ + private static final String SETTINGS_KEY_COMPOSITE_ROOT_PROJECT = "composite_root_project"; //$NON-NLS-1$ + + private final CompositeRootProjectConfiguration configuration; + + public CompositeRootProjectWizardController(IWizard compositeCreationWizard) { + // assemble configuration object that serves as the data model of the wizard + Property compositeNameProperty = Property.create(Validators.nullValidator()); + Property compositeProjectsProperty = Property.create(Validators.nonExistentDirectoryValidator(WorkspaceCompositeWizardMessages.Label_RootProject)); + + this.configuration = new CompositeRootProjectConfiguration(compositeNameProperty, compositeProjectsProperty); + + IDialogSettings dialogSettings = compositeCreationWizard.getDialogSettings(); + Boolean useCompositeRoot = dialogSettings.getBoolean(SETTINGS_KEY_USE_COMPOSITE_ROOT); + Optional compositeRootProject = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_COMPOSITE_ROOT_PROJECT)); + + this.configuration.setUseCompositeRoot(useCompositeRoot); + this.configuration.setRootProject(compositeRootProject.orNull()); + } + + public CompositeRootProjectConfiguration getConfiguration() { + return this.configuration; + } + } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProject.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProject.java index f1579c3977..e635e97ddd 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProject.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProject.java @@ -1,21 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ + package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; public class ExternalGradleProject { - //TODO (kuzniarz) initial implementation needs to be finished - - private String projectName; - private String projectPath; - - public ExternalGradleProject(String name, String path) { - projectName = name; - projectPath = path; - } - - public String getProjectName() { - return this.projectName; - } + //TODO (kuzniarz) initial implementation needs to be finished + + private String projectName; + private String projectPath; + + public ExternalGradleProject(String name, String path) { + this.projectName = name; + this.projectPath = path; + } + + public String getProjectName() { + return this.projectName; + } - public String getProjectPath() { - return this.projectPath; - } + public String getProjectPath() { + return this.projectPath; + } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProjectAdapter.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProjectAdapter.java index e29a9f0f2d..05aeb109c6 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProjectAdapter.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalGradleProjectAdapter.java @@ -1,11 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ + package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; public class ExternalGradleProjectAdapter { - private final ExternalGradleProject gradleProject; - - public ExternalGradleProjectAdapter(ExternalGradleProject project) { - this.gradleProject = project; - } - + private final ExternalGradleProject gradleProject; + + public ExternalGradleProjectAdapter(ExternalGradleProject project) { + this.gradleProject = project; + } + } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalProjectAdapterFactory.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalProjectAdapterFactory.java index e211834e94..8b779da96c 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalProjectAdapterFactory.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/ExternalProjectAdapterFactory.java @@ -1,21 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; import org.eclipse.core.runtime.IAdapterFactory; public class ExternalProjectAdapterFactory implements IAdapterFactory { - @Override - public Object getAdapter(Object adaptableObject, Class adapterType) { - if (adaptableObject instanceof ExternalGradleProject){ - return new ExternalGradleProjectAdapter((ExternalGradleProject) adaptableObject); - } - return null; - } + @Override + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adaptableObject instanceof ExternalGradleProject){ + return new ExternalGradleProjectAdapter((ExternalGradleProject) adaptableObject); + } + return null; + } - @Override - public Class[] getAdapterList() { - // TODO Auto-generated method stub - return null; - } + @Override + public Class[] getAdapterList() { + // TODO Auto-generated method stub + return null; + } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleImportOptionsWizardPage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleImportOptionsWizardPage.java index f84eacc49d..33cc8b229e 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleImportOptionsWizardPage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleImportOptionsWizardPage.java @@ -43,10 +43,10 @@ public GradleImportOptionsWizardPage(CompositeConfiguration configuration) { } public GradleImportOptionsWizardPage(CompositeConfiguration configuration, String title, String defaultMessage, String pageContextInformation) { - super("GradleImportOptions", title, defaultMessage, configuration, ImmutableList.>of(configuration.getDistribution(), configuration.getGradleUserHome(), configuration.getJavaHome())); + super("GradleImportOptions", title, defaultMessage, configuration, ImmutableList.>of(configuration.getDistribution(), configuration.getGradleUserHome(), configuration.getJavaHome())); this.pageContextInformation = pageContextInformation; - } + } @Override protected void createWidgets(Composite root) { @@ -63,12 +63,12 @@ protected void createWidgets(Composite root) { addListeners(); } - @Override - public IWizardPage getNextPage() { - IWizardPage page = new GradleRootProjectWizardPage(getConfiguration(), new CompositeRootProjectConfiguration()); + @Override + public IWizardPage getNextPage() { + IWizardPage page = new GradleRootProjectWizardPage(getConfiguration(), new CompositeRootProjectConfiguration()); page.setWizard(getWizard()); - return page; - } + return page; + } private void initValues() { this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().setSelection(getConfiguration().getOverrideWorkspaceConfiguration().getValue()); diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleRootProjectWizardPage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleRootProjectWizardPage.java index 6e4445ed86..54cdc0e37e 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleRootProjectWizardPage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleRootProjectWizardPage.java @@ -12,10 +12,8 @@ import java.io.File; -import org.eclipse.buildship.core.internal.util.binding.Property; -import org.eclipse.buildship.ui.internal.util.file.DirectoryDialogSelectionListener; -import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; -import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.CompositeConfiguration; +import com.google.common.collect.ImmutableList; + import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; @@ -31,7 +29,9 @@ import org.eclipse.swt.widgets.Layout; import org.eclipse.swt.widgets.Text; -import com.google.common.collect.ImmutableList; +import org.eclipse.buildship.core.internal.util.binding.Property; +import org.eclipse.buildship.ui.internal.util.file.DirectoryDialogSelectionListener; +import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; /** * Page in the {@link WorkspaceCompositeCreationWizard} for setting a project as composite root. @@ -39,7 +39,7 @@ @SuppressWarnings("unused") public final class GradleRootProjectWizardPage extends AbstractCompositeWizardPage { - private final CompositeRootProjectConfiguration rootProjectConfiguration; + private final CompositeRootProjectConfiguration rootProjectConfiguration; private Text workspaceCompositeRootProjectText; private Text overrideRootProjectCheckboxLabel; @@ -68,8 +68,8 @@ protected void createWidgets(Composite root) { } private void initValues() { - this.overrideRootProjectCheckbox.setSelection(this.rootProjectConfiguration.getUseCompositeRoot().getValue()); - this.workspaceCompositeRootProjectText.setText(this.rootProjectConfiguration.getRootProject().getValue().getAbsolutePath()); + this.overrideRootProjectCheckbox.setSelection(this.rootProjectConfiguration.getUseCompositeRoot().getValue()); + this.workspaceCompositeRootProjectText.setText(this.rootProjectConfiguration.getRootProject().getValue().getAbsolutePath()); } private Layout createLayout() { @@ -119,42 +119,42 @@ private File getRootProject() { } private void addListeners() { - if (this.overrideRootProjectCheckbox != null) { - this.overrideRootProjectCheckbox.addSelectionListener(new SelectionListener() { + if (this.overrideRootProjectCheckbox != null) { + this.overrideRootProjectCheckbox.addSelectionListener(new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent e) { - getConfiguration().getProjectAsCompositeRoot().setValue(GradleRootProjectWizardPage.this.overrideRootProjectCheckbox.getSelection()); - updateEnablement(); - } + @Override + public void widgetSelected(SelectionEvent e) { + getConfiguration().getProjectAsCompositeRoot().setValue(GradleRootProjectWizardPage.this.overrideRootProjectCheckbox.getSelection()); + updateEnablement(); + } - @Override - public void widgetDefaultSelected(SelectionEvent e) { - getConfiguration().getProjectAsCompositeRoot().setValue(GradleRootProjectWizardPage.this.overrideRootProjectCheckbox.getSelection()); - updateEnablement(); - } - }); + @Override + public void widgetDefaultSelected(SelectionEvent e) { + getConfiguration().getProjectAsCompositeRoot().setValue(GradleRootProjectWizardPage.this.overrideRootProjectCheckbox.getSelection()); + updateEnablement(); + } + }); - this.workspaceCompositeRootProjectText.addModifyListener(new ModifyListener() { + this.workspaceCompositeRootProjectText.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - getConfiguration().getRootProject().setValue(GradleRootProjectWizardPage.this.getRootProject()); + @Override + public void modifyText(ModifyEvent e) { + getConfiguration().getRootProject().setValue(GradleRootProjectWizardPage.this.getRootProject()); - } - }); + } + }); - this.selectRootProject.addSelectionListener(new DirectoryDialogSelectionListener(this.getShell(), this.workspaceCompositeRootProjectText, "Root project")); - } + this.selectRootProject.addSelectionListener(new DirectoryDialogSelectionListener(this.getShell(), this.workspaceCompositeRootProjectText, "Root project")); + } } public void updateEnablement() { - if (this.overrideRootProjectCheckbox != null) { - boolean enabled = this.overrideRootProjectCheckbox.getSelection(); + if (this.overrideRootProjectCheckbox != null) { + boolean enabled = this.overrideRootProjectCheckbox.getSelection(); this.rootProjectLabel.setEnabled(enabled); - this.workspaceCompositeRootProjectText.setEnabled(enabled); - this.selectRootProject.setEnabled(enabled); - } + this.workspaceCompositeRootProjectText.setEnabled(enabled); + this.selectRootProject.setEnabled(enabled); + } } @Override diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleWorkspaceCompositeUpdater.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleWorkspaceCompositeUpdater.java index 57acd1933f..768f584c8c 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleWorkspaceCompositeUpdater.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleWorkspaceCompositeUpdater.java @@ -1,3 +1,12 @@ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; import java.util.ArrayList; @@ -22,206 +31,208 @@ public class GradleWorkspaceCompositeUpdater implements IWorkingSetUpdater, IElementChangedListener { - /** - * DO NOT REMOVE, used in a product, see https://bugs.eclipse.org/297529 . - * @deprecated As of 3.5, replaced by {@link IWorkingSetIDs#JAVA} - */ - @Deprecated - public static final String ID= "org.eclipse.buildship.core.gradlecompositenature"; - - - private List fWorkingSets; - - private static class WorkingSetDelta { - private IWorkingSet fWorkingSet; - private List fElements; - private boolean fChanged; - public WorkingSetDelta(IWorkingSet workingSet) { - fWorkingSet= workingSet; - fElements= new ArrayList<>(Arrays.asList(workingSet.getElements())); - } - public int indexOf(Object element) { - return fElements.indexOf(element); - } - public void set(int index, IAdaptable element) { - fElements.set(index, element); - fChanged= true; - } - public void remove(int index) { - if (fElements.remove(index) != null) { - fChanged= true; - } - } - public void process() { - if (fChanged) { - fWorkingSet.setElements(fElements.toArray(new IAdaptable[fElements.size()])); - } - } - } - - public GradleWorkspaceCompositeUpdater() { - fWorkingSets= new ArrayList<>(); - } - - @Override - public void add(IWorkingSet workingSet) { - checkElementExistence(workingSet); - synchronized (fWorkingSets) { - fWorkingSets.add(workingSet); - } - } - - @Override - public boolean remove(IWorkingSet workingSet) { - boolean result; - synchronized(fWorkingSets) { - result= fWorkingSets.remove(workingSet); - } - return result; - } - - @Override - public boolean contains(IWorkingSet workingSet) { - synchronized(fWorkingSets) { - return fWorkingSets.contains(workingSet); - } - } - - @Override - public void dispose() { - synchronized(fWorkingSets) { - fWorkingSets.clear(); - } - } - - @Override - public void elementChanged(ElementChangedEvent event) { - IWorkingSet[] workingSets; - synchronized(fWorkingSets) { - workingSets= fWorkingSets.toArray(new IWorkingSet[fWorkingSets.size()]); - } - for (int w= 0; w < workingSets.length; w++) { - WorkingSetDelta workingSetDelta= new WorkingSetDelta(workingSets[w]); - processJavaDelta(workingSetDelta, event.getDelta()); - IResourceDelta[] resourceDeltas= event.getDelta().getResourceDeltas(); - if (resourceDeltas != null) { - for (int r= 0; r < resourceDeltas.length; r++) { - processResourceDelta(workingSetDelta, resourceDeltas[r]); - } - } - workingSetDelta.process(); - } - } - - private void processJavaDelta(WorkingSetDelta result, IJavaElementDelta delta) { - IJavaElement jElement= delta.getElement(); - int index= result.indexOf(jElement); - int type= jElement.getElementType(); - int kind= delta.getKind(); - int flags= delta.getFlags(); - if (type == IJavaElement.JAVA_PROJECT && kind == IJavaElementDelta.CHANGED) { - if (index != -1 && (flags & IJavaElementDelta.F_CLOSED) != 0) { - result.set(index, ((IJavaProject)jElement).getProject()); - } else if ((flags & IJavaElementDelta.F_OPENED) != 0) { - index= result.indexOf(((IJavaProject)jElement).getProject()); - if (index != -1) - result.set(index, jElement); - } - } - if (index != -1) { - if (kind == IJavaElementDelta.REMOVED) { - if ((flags & IJavaElementDelta.F_MOVED_TO) != 0) { - result.set(index, delta.getMovedToElement()); - } else { - result.remove(index); - } - } - } - IResourceDelta[] resourceDeltas= delta.getResourceDeltas(); - if (resourceDeltas != null) { - for (int i= 0; i < resourceDeltas.length; i++) { - processResourceDelta(result, resourceDeltas[i]); - } - } - IJavaElementDelta[] children= delta.getAffectedChildren(); - for (int i= 0; i < children.length; i++) { - processJavaDelta(result, children[i]); - } - } - - private void processResourceDelta(WorkingSetDelta result, IResourceDelta delta) { - IResource resource= delta.getResource(); - int type= resource.getType(); - int index= result.indexOf(resource); - int kind= delta.getKind(); - int flags= delta.getFlags(); - if (kind == IResourceDelta.CHANGED && type == IResource.PROJECT && index != -1) { - if ((flags & IResourceDelta.OPEN) != 0) { - result.set(index, resource); - } - } - if (index != -1 && kind == IResourceDelta.REMOVED) { - if ((flags & IResourceDelta.MOVED_TO) != 0) { - result.set(index, - ResourcesPlugin.getWorkspace().getRoot().findMember(delta.getMovedToPath())); - } else { - result.remove(index); - } - } - - // Don't dive into closed or opened projects - if (projectGotClosedOrOpened(resource, kind, flags)) - return; - - IResourceDelta[] children= delta.getAffectedChildren(); - for (int i= 0; i < children.length; i++) { - processResourceDelta(result, children[i]); - } - } - - private boolean projectGotClosedOrOpened(IResource resource, int kind, int flags) { - return resource.getType() == IResource.PROJECT - && kind == IResourceDelta.CHANGED - && (flags & IResourceDelta.OPEN) != 0; - } - - private void checkElementExistence(IWorkingSet workingSet) { - List elements= new ArrayList<>(Arrays.asList(workingSet.getElements())); - boolean changed= false; - for (Iterator iter= elements.iterator(); iter.hasNext();) { - IAdaptable element= iter.next(); - boolean remove= false; - if (element instanceof IJavaElement) { - IJavaElement jElement= (IJavaElement)element; - // If we have directly a project then remove it when it - // doesn't exist anymore. However if we have a sub element - // under a project only remove the element if the parent - // project is open. Otherwise we would remove all elements - // in closed projects. - if (jElement instanceof IJavaProject) { - remove= !jElement.exists(); - } else { - final IJavaProject javaProject= jElement.getJavaProject(); - final boolean isProjectOpen= javaProject != null ? javaProject.getProject().isOpen() : true; - remove= isProjectOpen && !jElement.exists(); - } - } else if (element instanceof IResource) { - IResource resource= (IResource)element; - // See comments above - if (resource instanceof IProject) { - remove= !resource.exists(); - } else { - IProject project= resource.getProject(); - remove= (project != null ? project.isOpen() : true) && !resource.exists(); - } - } - if (remove) { - iter.remove(); - changed= true; - } - } - if (changed) { - workingSet.setElements(elements.toArray(new IAdaptable[elements.size()])); - } - } + /** + * DO NOT REMOVE, used in a product, see https://bugs.eclipse.org/297529 . + * @deprecated As of 3.5, replaced by {@link IWorkingSetIDs#JAVA} + */ + @Deprecated + public static final String ID= "org.eclipse.buildship.core.gradlecompositenature"; + + + private List fWorkingSets; + + private static class WorkingSetDelta { + private IWorkingSet fWorkingSet; + private List fElements; + private boolean fChanged; + public WorkingSetDelta(IWorkingSet workingSet) { + this.fWorkingSet= workingSet; + this.fElements= new ArrayList<>(Arrays.asList(workingSet.getElements())); + } + public int indexOf(Object element) { + return this.fElements.indexOf(element); + } + public void set(int index, IAdaptable element) { + this.fElements.set(index, element); + this.fChanged= true; + } + public void remove(int index) { + if (this.fElements.remove(index) != null) { + this.fChanged= true; + } + } + public void process() { + if (this.fChanged) { + this.fWorkingSet.setElements(this.fElements.toArray(new IAdaptable[this.fElements.size()])); + } + } + } + + public GradleWorkspaceCompositeUpdater() { + this.fWorkingSets= new ArrayList<>(); + } + + @Override + public void add(IWorkingSet workingSet) { + checkElementExistence(workingSet); + synchronized (this.fWorkingSets) { + this.fWorkingSets.add(workingSet); + } + } + + @Override + public boolean remove(IWorkingSet workingSet) { + boolean result; + synchronized(this.fWorkingSets) { + result= this.fWorkingSets.remove(workingSet); + } + return result; + } + + @Override + public boolean contains(IWorkingSet workingSet) { + synchronized(this.fWorkingSets) { + return this.fWorkingSets.contains(workingSet); + } + } + + @Override + public void dispose() { + synchronized(this.fWorkingSets) { + this.fWorkingSets.clear(); + } + } + + @Override + public void elementChanged(ElementChangedEvent event) { + IWorkingSet[] workingSets; + synchronized(this.fWorkingSets) { + workingSets= this.fWorkingSets.toArray(new IWorkingSet[this.fWorkingSets.size()]); + } + for (int w= 0; w < workingSets.length; w++) { + WorkingSetDelta workingSetDelta= new WorkingSetDelta(workingSets[w]); + processJavaDelta(workingSetDelta, event.getDelta()); + IResourceDelta[] resourceDeltas= event.getDelta().getResourceDeltas(); + if (resourceDeltas != null) { + for (int r= 0; r < resourceDeltas.length; r++) { + processResourceDelta(workingSetDelta, resourceDeltas[r]); + } + } + workingSetDelta.process(); + } + } + + private void processJavaDelta(WorkingSetDelta result, IJavaElementDelta delta) { + IJavaElement jElement= delta.getElement(); + int index= result.indexOf(jElement); + int type= jElement.getElementType(); + int kind= delta.getKind(); + int flags= delta.getFlags(); + if (type == IJavaElement.JAVA_PROJECT && kind == IJavaElementDelta.CHANGED) { + if (index != -1 && (flags & IJavaElementDelta.F_CLOSED) != 0) { + result.set(index, ((IJavaProject)jElement).getProject()); + } else if ((flags & IJavaElementDelta.F_OPENED) != 0) { + index= result.indexOf(((IJavaProject)jElement).getProject()); + if (index != -1) { + result.set(index, jElement); + } + } + } + if (index != -1) { + if (kind == IJavaElementDelta.REMOVED) { + if ((flags & IJavaElementDelta.F_MOVED_TO) != 0) { + result.set(index, delta.getMovedToElement()); + } else { + result.remove(index); + } + } + } + IResourceDelta[] resourceDeltas= delta.getResourceDeltas(); + if (resourceDeltas != null) { + for (int i= 0; i < resourceDeltas.length; i++) { + processResourceDelta(result, resourceDeltas[i]); + } + } + IJavaElementDelta[] children= delta.getAffectedChildren(); + for (int i= 0; i < children.length; i++) { + processJavaDelta(result, children[i]); + } + } + + private void processResourceDelta(WorkingSetDelta result, IResourceDelta delta) { + IResource resource= delta.getResource(); + int type= resource.getType(); + int index= result.indexOf(resource); + int kind= delta.getKind(); + int flags= delta.getFlags(); + if (kind == IResourceDelta.CHANGED && type == IResource.PROJECT && index != -1) { + if ((flags & IResourceDelta.OPEN) != 0) { + result.set(index, resource); + } + } + if (index != -1 && kind == IResourceDelta.REMOVED) { + if ((flags & IResourceDelta.MOVED_TO) != 0) { + result.set(index, + ResourcesPlugin.getWorkspace().getRoot().findMember(delta.getMovedToPath())); + } else { + result.remove(index); + } + } + + // Don't dive into closed or opened projects + if (projectGotClosedOrOpened(resource, kind, flags)) { + return; + } + + IResourceDelta[] children= delta.getAffectedChildren(); + for (int i= 0; i < children.length; i++) { + processResourceDelta(result, children[i]); + } + } + + private boolean projectGotClosedOrOpened(IResource resource, int kind, int flags) { + return resource.getType() == IResource.PROJECT + && kind == IResourceDelta.CHANGED + && (flags & IResourceDelta.OPEN) != 0; + } + + private void checkElementExistence(IWorkingSet workingSet) { + List elements= new ArrayList<>(Arrays.asList(workingSet.getElements())); + boolean changed= false; + for (Iterator iter= elements.iterator(); iter.hasNext();) { + IAdaptable element= iter.next(); + boolean remove= false; + if (element instanceof IJavaElement) { + IJavaElement jElement= (IJavaElement)element; + // If we have directly a project then remove it when it + // doesn't exist anymore. However if we have a sub element + // under a project only remove the element if the parent + // project is open. Otherwise we would remove all elements + // in closed projects. + if (jElement instanceof IJavaProject) { + remove= !jElement.exists(); + } else { + final IJavaProject javaProject= jElement.getJavaProject(); + final boolean isProjectOpen= javaProject != null ? javaProject.getProject().isOpen() : true; + remove= isProjectOpen && !jElement.exists(); + } + } else if (element instanceof IResource) { + IResource resource= (IResource)element; + // See comments above + if (resource instanceof IProject) { + remove= !resource.exists(); + } else { + IProject project= resource.getProject(); + remove= (project != null ? project.isOpen() : true) && !resource.exists(); + } + } + if (remove) { + iter.remove(); + changed= true; + } + } + if (changed) { + workingSet.setElements(elements.toArray(new IAdaptable[elements.size()])); + } + } } \ No newline at end of file diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/IGradleCompositeIDs.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/IGradleCompositeIDs.java index f76a7216d0..fa12eb509c 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/IGradleCompositeIDs.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/IGradleCompositeIDs.java @@ -1,13 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ + package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; /** - * + * * @author Sebastian Kuzniarz (kuzniarz) - Diebold Nixdorf Inc. * */ public interface IGradleCompositeIDs { - - String NATURE = "org.eclipse.buildship.ui.GradleCompositePage"; + + String NATURE = "org.eclipse.buildship.ui.GradleCompositePage"; } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java index c77b957e5d..fcf15f45eb 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java @@ -32,8 +32,8 @@ public final class WorkspaceCompositeWizardMessages extends NLS { public static String WarningMessage_GradleWorkspaceComposite_NameWhitespaces; public static String WarningMessage_GradleWorkspaceComposite_NameEmpty; - public static String WarningMessage_GradleWorkspaceComposite_CompositeNameExists; - public static String WarningMessage_GradleWorkspaceComposite_CompositeEmpty; + public static String WarningMessage_GradleWorkspaceComposite_CompositeNameExists; + public static String WarningMessage_GradleWorkspaceComposite_CompositeEmpty; public static String InfoMessage_NewGradleWorkspaceCompositeWizardPageDefault; public static String InfoMessage_NewGradleWorkspaceCompositeOptionsWizardPageDefault; diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/CompositePropertyChangeListener.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/CompositePropertyChangeListener.java index 1ed990e271..ea76c4d5b3 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/CompositePropertyChangeListener.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/CompositePropertyChangeListener.java @@ -1,13 +1,12 @@ -/* - * Copyright (c) 2015 the original author or authors. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. * - * Contributors: - * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - initial implemenation - */ + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.workspace; @@ -30,73 +29,73 @@ import org.eclipse.ui.PlatformUI; /** - * Listener class for {@link org.eclipse.ui.internal.dialogs.WorkingSetSelectionDialog}. Contains file composite properties file + * Listener class for {@link org.eclipse.ui.internal.dialogs.WorkingSetSelectionDialog}. Contains file composite properties file * deletion algorithm with backup to ensure cancel function for WorkingSetSelectionDialog. * @author kuzniarz */ public class CompositePropertyChangeListener implements IPropertyChangeListener { - - private final Map compositePropertiesBackup = new HashMap(); - IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); - @Override - public void propertyChange(PropertyChangeEvent event) { - if (compositeRemovalCausedEvent(event)) { - try { - IWorkingSet removed = (IWorkingSet)event.getOldValue(); - if (isNotAggregate(removed) && removed.getId().equals(IGradleCompositeIDs.NATURE)) { - File compositePropertiesFile = CorePlugin.getInstance().getStateLocation().append("workspace-composites").append(removed.getName()).toFile(); - backupCompositeProperties(removed, compositePropertiesFile); - Files.deleteIfExists(compositePropertiesFile.toPath()); - } - } catch (IOException e) { - e.printStackTrace(); - } - } else if (compositeAddingCausedEvent(event)) { - try { - IWorkingSet added = (IWorkingSet)event.getNewValue(); - if (isNotAggregate(added) && added.getId().equals(IGradleCompositeIDs.NATURE)) { - restoreCompositeProperties(added.getName()); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - } + private final Map compositePropertiesBackup = new HashMap<>(); + IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); + + @Override + public void propertyChange(PropertyChangeEvent event) { + if (compositeRemovalCausedEvent(event)) { + try { + IWorkingSet removed = (IWorkingSet)event.getOldValue(); + if (isNotAggregate(removed) && removed.getId().equals(IGradleCompositeIDs.NATURE)) { + File compositePropertiesFile = CorePlugin.getInstance().getStateLocation().append("workspace-composites").append(removed.getName()).toFile(); + backupCompositeProperties(removed, compositePropertiesFile); + Files.deleteIfExists(compositePropertiesFile.toPath()); + } + } catch (IOException e) { + e.printStackTrace(); + } + } else if (compositeAddingCausedEvent(event)) { + try { + IWorkingSet added = (IWorkingSet)event.getNewValue(); + if (isNotAggregate(added) && added.getId().equals(IGradleCompositeIDs.NATURE)) { + restoreCompositeProperties(added.getName()); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } - private boolean isNotAggregate(IWorkingSet removed) { - return !removed.getName().contains(":"); - } + private boolean isNotAggregate(IWorkingSet removed) { + return !removed.getName().contains(":"); + } - private void restoreCompositeProperties(String compositeName) throws FileNotFoundException, IOException { - if (compositePropertiesBackup.containsKey(compositeName)) { - File compositePropertiesFile = CorePlugin.getInstance().getStateLocation().append("workspace-composites").append(compositeName).toFile(); - FileOutputStream out = new FileOutputStream(compositePropertiesFile.getAbsoluteFile()); - compositePropertiesBackup.get(compositeName).store(out, " "); - compositePropertiesBackup.remove(compositeName); - out.close(); - } else { - //New Composite is being created! - } - } + private void restoreCompositeProperties(String compositeName) throws FileNotFoundException, IOException { + if (this.compositePropertiesBackup.containsKey(compositeName)) { + File compositePropertiesFile = CorePlugin.getInstance().getStateLocation().append("workspace-composites").append(compositeName).toFile(); + FileOutputStream out = new FileOutputStream(compositePropertiesFile.getAbsoluteFile()); + this.compositePropertiesBackup.get(compositeName).store(out, " "); + this.compositePropertiesBackup.remove(compositeName); + out.close(); + } else { + //New Composite is being created! + } + } - private void backupCompositeProperties(IWorkingSet removed, File compositePropertiesFile) - throws FileNotFoundException, IOException { - Properties compositeProperties = new Properties(); - FileInputStream input = new FileInputStream(compositePropertiesFile); - compositeProperties.load(input); - input.close(); - compositePropertiesBackup.put(removed.getName(), compositeProperties); - } + private void backupCompositeProperties(IWorkingSet removed, File compositePropertiesFile) + throws FileNotFoundException, IOException { + Properties compositeProperties = new Properties(); + FileInputStream input = new FileInputStream(compositePropertiesFile); + compositeProperties.load(input); + input.close(); + this.compositePropertiesBackup.put(removed.getName(), compositeProperties); + } - private boolean compositeAddingCausedEvent(PropertyChangeEvent event) { - return event.getProperty().equals(IWorkingSetManager.CHANGE_WORKING_SET_ADD) && - event.getNewValue() != null; - } + private boolean compositeAddingCausedEvent(PropertyChangeEvent event) { + return event.getProperty().equals(IWorkingSetManager.CHANGE_WORKING_SET_ADD) && + event.getNewValue() != null; + } - private boolean compositeRemovalCausedEvent(PropertyChangeEvent event) { - return event.getProperty().equals(IWorkingSetManager.CHANGE_WORKING_SET_REMOVE) && - event.getOldValue() != null; - } + private boolean compositeRemovalCausedEvent(PropertyChangeEvent event) { + return event.getProperty().equals(IWorkingSetManager.CHANGE_WORKING_SET_REMOVE) && + event.getOldValue() != null; + } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/RemoveCompositeHandler.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/RemoveCompositeHandler.java index 7fe9e2bbac..5f1f0fc904 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/RemoveCompositeHandler.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/RemoveCompositeHandler.java @@ -1,3 +1,12 @@ +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.workspace; import org.eclipse.core.commands.AbstractHandler; @@ -7,25 +16,25 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; import org.eclipse.ui.handlers.HandlerUtil; public class RemoveCompositeHandler extends AbstractHandler implements IHandler { - - private IStructuredSelection initialSelection; - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - // TODO Auto-generated method stub - //HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().close(); - IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().getActiveWorkbenchWindow(); - - if (activeWorkbenchWindow != null) { - ISelection selection= activeWorkbenchWindow.getSelectionService().getSelection(); - if (selection instanceof IStructuredSelection) - initialSelection = (IStructuredSelection)selection; - } - return null; - } + private IStructuredSelection initialSelection; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + // TODO Auto-generated method stub + //HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().close(); + IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().getActiveWorkbenchWindow(); + + if (activeWorkbenchWindow != null) { + ISelection selection= activeWorkbenchWindow.getSelectionService().getSelection(); + if (selection instanceof IStructuredSelection) { + this.initialSelection = (IStructuredSelection)selection; + } + } + return null; + } } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/StartupSetup.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/StartupSetup.java index 35c69a406d..f63432dd21 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/StartupSetup.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/workspace/StartupSetup.java @@ -1,13 +1,12 @@ -/* - * Copyright (c) 2015 the original author or authors. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html +/******************************************************************************* + * Copyright (c) 2020 Gradle Inc. * - * Contributors: - * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - initial implemenation - */ + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ package org.eclipse.buildship.ui.internal.workspace; @@ -17,11 +16,11 @@ public class StartupSetup implements IStartup { - @Override - public void earlyStartup() { - IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); + @Override + public void earlyStartup() { + IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); - manager.addPropertyChangeListener(new CompositePropertyChangeListener()); - } + manager.addPropertyChangeListener(new CompositePropertyChangeListener()); + } } From 76cbf8f9ac8a1f147ea7a14cace70b25aef4378e Mon Sep 17 00:00:00 2001 From: Sebastian Kuzniarz Date: Fri, 29 May 2020 17:20:53 +0200 Subject: [PATCH 07/15] Delete GradleWorkspaceCompositeUpdater.java Commited by accident Signed-off-by: kuzniarz --- .../GradleWorkspaceCompositeUpdater.java | 238 ------------------ 1 file changed, 238 deletions(-) delete mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleWorkspaceCompositeUpdater.java diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleWorkspaceCompositeUpdater.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleWorkspaceCompositeUpdater.java deleted file mode 100644 index 768f584c8c..0000000000 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleWorkspaceCompositeUpdater.java +++ /dev/null @@ -1,238 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020 Gradle Inc. - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - ******************************************************************************/ -package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.IElementChangedListener; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaElementDelta; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.internal.ui.workingsets.IWorkingSetIDs; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.IWorkingSetUpdater; - - -public class GradleWorkspaceCompositeUpdater implements IWorkingSetUpdater, IElementChangedListener { - - /** - * DO NOT REMOVE, used in a product, see https://bugs.eclipse.org/297529 . - * @deprecated As of 3.5, replaced by {@link IWorkingSetIDs#JAVA} - */ - @Deprecated - public static final String ID= "org.eclipse.buildship.core.gradlecompositenature"; - - - private List fWorkingSets; - - private static class WorkingSetDelta { - private IWorkingSet fWorkingSet; - private List fElements; - private boolean fChanged; - public WorkingSetDelta(IWorkingSet workingSet) { - this.fWorkingSet= workingSet; - this.fElements= new ArrayList<>(Arrays.asList(workingSet.getElements())); - } - public int indexOf(Object element) { - return this.fElements.indexOf(element); - } - public void set(int index, IAdaptable element) { - this.fElements.set(index, element); - this.fChanged= true; - } - public void remove(int index) { - if (this.fElements.remove(index) != null) { - this.fChanged= true; - } - } - public void process() { - if (this.fChanged) { - this.fWorkingSet.setElements(this.fElements.toArray(new IAdaptable[this.fElements.size()])); - } - } - } - - public GradleWorkspaceCompositeUpdater() { - this.fWorkingSets= new ArrayList<>(); - } - - @Override - public void add(IWorkingSet workingSet) { - checkElementExistence(workingSet); - synchronized (this.fWorkingSets) { - this.fWorkingSets.add(workingSet); - } - } - - @Override - public boolean remove(IWorkingSet workingSet) { - boolean result; - synchronized(this.fWorkingSets) { - result= this.fWorkingSets.remove(workingSet); - } - return result; - } - - @Override - public boolean contains(IWorkingSet workingSet) { - synchronized(this.fWorkingSets) { - return this.fWorkingSets.contains(workingSet); - } - } - - @Override - public void dispose() { - synchronized(this.fWorkingSets) { - this.fWorkingSets.clear(); - } - } - - @Override - public void elementChanged(ElementChangedEvent event) { - IWorkingSet[] workingSets; - synchronized(this.fWorkingSets) { - workingSets= this.fWorkingSets.toArray(new IWorkingSet[this.fWorkingSets.size()]); - } - for (int w= 0; w < workingSets.length; w++) { - WorkingSetDelta workingSetDelta= new WorkingSetDelta(workingSets[w]); - processJavaDelta(workingSetDelta, event.getDelta()); - IResourceDelta[] resourceDeltas= event.getDelta().getResourceDeltas(); - if (resourceDeltas != null) { - for (int r= 0; r < resourceDeltas.length; r++) { - processResourceDelta(workingSetDelta, resourceDeltas[r]); - } - } - workingSetDelta.process(); - } - } - - private void processJavaDelta(WorkingSetDelta result, IJavaElementDelta delta) { - IJavaElement jElement= delta.getElement(); - int index= result.indexOf(jElement); - int type= jElement.getElementType(); - int kind= delta.getKind(); - int flags= delta.getFlags(); - if (type == IJavaElement.JAVA_PROJECT && kind == IJavaElementDelta.CHANGED) { - if (index != -1 && (flags & IJavaElementDelta.F_CLOSED) != 0) { - result.set(index, ((IJavaProject)jElement).getProject()); - } else if ((flags & IJavaElementDelta.F_OPENED) != 0) { - index= result.indexOf(((IJavaProject)jElement).getProject()); - if (index != -1) { - result.set(index, jElement); - } - } - } - if (index != -1) { - if (kind == IJavaElementDelta.REMOVED) { - if ((flags & IJavaElementDelta.F_MOVED_TO) != 0) { - result.set(index, delta.getMovedToElement()); - } else { - result.remove(index); - } - } - } - IResourceDelta[] resourceDeltas= delta.getResourceDeltas(); - if (resourceDeltas != null) { - for (int i= 0; i < resourceDeltas.length; i++) { - processResourceDelta(result, resourceDeltas[i]); - } - } - IJavaElementDelta[] children= delta.getAffectedChildren(); - for (int i= 0; i < children.length; i++) { - processJavaDelta(result, children[i]); - } - } - - private void processResourceDelta(WorkingSetDelta result, IResourceDelta delta) { - IResource resource= delta.getResource(); - int type= resource.getType(); - int index= result.indexOf(resource); - int kind= delta.getKind(); - int flags= delta.getFlags(); - if (kind == IResourceDelta.CHANGED && type == IResource.PROJECT && index != -1) { - if ((flags & IResourceDelta.OPEN) != 0) { - result.set(index, resource); - } - } - if (index != -1 && kind == IResourceDelta.REMOVED) { - if ((flags & IResourceDelta.MOVED_TO) != 0) { - result.set(index, - ResourcesPlugin.getWorkspace().getRoot().findMember(delta.getMovedToPath())); - } else { - result.remove(index); - } - } - - // Don't dive into closed or opened projects - if (projectGotClosedOrOpened(resource, kind, flags)) { - return; - } - - IResourceDelta[] children= delta.getAffectedChildren(); - for (int i= 0; i < children.length; i++) { - processResourceDelta(result, children[i]); - } - } - - private boolean projectGotClosedOrOpened(IResource resource, int kind, int flags) { - return resource.getType() == IResource.PROJECT - && kind == IResourceDelta.CHANGED - && (flags & IResourceDelta.OPEN) != 0; - } - - private void checkElementExistence(IWorkingSet workingSet) { - List elements= new ArrayList<>(Arrays.asList(workingSet.getElements())); - boolean changed= false; - for (Iterator iter= elements.iterator(); iter.hasNext();) { - IAdaptable element= iter.next(); - boolean remove= false; - if (element instanceof IJavaElement) { - IJavaElement jElement= (IJavaElement)element; - // If we have directly a project then remove it when it - // doesn't exist anymore. However if we have a sub element - // under a project only remove the element if the parent - // project is open. Otherwise we would remove all elements - // in closed projects. - if (jElement instanceof IJavaProject) { - remove= !jElement.exists(); - } else { - final IJavaProject javaProject= jElement.getJavaProject(); - final boolean isProjectOpen= javaProject != null ? javaProject.getProject().isOpen() : true; - remove= isProjectOpen && !jElement.exists(); - } - } else if (element instanceof IResource) { - IResource resource= (IResource)element; - // See comments above - if (resource instanceof IProject) { - remove= !resource.exists(); - } else { - IProject project= resource.getProject(); - remove= (project != null ? project.isOpen() : true) && !resource.exists(); - } - } - if (remove) { - iter.remove(); - changed= true; - } - } - if (changed) { - workingSet.setElements(elements.toArray(new IAdaptable[elements.size()])); - } - } -} \ No newline at end of file From c31e786f255ddf3acf54c2dc67f21640294abb0c Mon Sep 17 00:00:00 2001 From: kuzniarz Date: Tue, 16 Jun 2020 11:31:36 +0200 Subject: [PATCH 08/15] Pull Request Fixes + CompositeDialog - Fixed all requested PR changes - Started implementing new CompositeSelectionDialog Signed-off-by: kuzniarz --- .../META-INF/MANIFEST.MF | 1 - .../buildship/core/CompositeProperties.java | 68 ++----- .../BuildConfigurationPersistence.java | 40 +++- .../configuration/CompositeConfiguration.java | 9 +- .../configuration/ConfigurationManager.java | 3 +- .../DefaultCompositeConfiguration.java | 32 ++-- .../DefaultConfigurationManager.java | 25 +-- .../internal/util/binding/Validators.java | 11 +- org.eclipse.buildship.ui/META-INF/MANIFEST.MF | 4 +- org.eclipse.buildship.ui/plugin.xml | 22 ++- ...eCompositeImportOptionsPreferencePage.java | 23 ++- ...dleCompositeRootProjectPreferencePage.java | 62 +++++-- ...reateWorkspaceCompositePreferencePage.java | 64 +++++-- ...xternalProjectDialogSelectionListener.java | 4 +- .../CompositeConfigurationDialogHandler.java | 20 ++ .../AbstractCompositeDialog.java | 174 ++++++++++++++++++ .../CompositeConfiguration.java | 33 ++-- .../CompositeCreationConfiguration.java | 10 +- .../CompositeCreationWizardController.java | 25 ++- .../CompositeImportWizardController.java | 36 ++-- .../CompositeSelectionDialog.java | 45 +++++ ...dleCreateWorkspaceCompositeWizardPage.java | 36 ++-- .../WorkspaceCompositeWizardMessages.java | 2 + ...orkspaceCompositeWizardMessages.properties | 2 + 24 files changed, 540 insertions(+), 211 deletions(-) create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/CompositeConfigurationDialogHandler.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeDialog.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeSelectionDialog.java diff --git a/org.eclipse.buildship.core/META-INF/MANIFEST.MF b/org.eclipse.buildship.core/META-INF/MANIFEST.MF index 20b809c9a3..72191217f9 100644 --- a/org.eclipse.buildship.core/META-INF/MANIFEST.MF +++ b/org.eclipse.buildship.core/META-INF/MANIFEST.MF @@ -16,7 +16,6 @@ Require-Bundle: org.eclipse.core.expressions, org.eclipse.jdt.junit.core, org.eclipse.jdt.launching, org.eclipse.debug.core, - org.eclipse.ui, org.gradle.toolingapi;bundle-version="[6.3.0,6.4.0)";visibility:=reexport, com.google.guava;bundle-version="[27.0.0,28.0.0)", com.google.gson;bundle-version="[2.7.0,3.0.0)" diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/CompositeProperties.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/CompositeProperties.java index 6ac50ac3e9..e2532dfa5e 100644 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/CompositeProperties.java +++ b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/CompositeProperties.java @@ -13,25 +13,16 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Properties; -import com.google.common.base.Preconditions; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdaptable; - +import org.eclipse.buildship.core.internal.CorePlugin; import org.eclipse.buildship.core.internal.configuration.CompositeConfiguration; public class CompositeProperties { - private final File compositePreferencesDir; - - private final IAdaptable[] projectList; + private final List projectList; private final Boolean overwriteWorkspaceSettings; private final GradleDistribution distribution; private final File gradleUserHome; @@ -62,7 +53,6 @@ public class CompositeProperties { private static final String KEY_ROOT_PROJECT = "root.project"; private CompositeProperties(CompositePropertiesBuilder builder) { - this.compositePreferencesDir = Preconditions.checkNotNull(builder.compositeDirectory); this.projectList = builder.projectList; this.overwriteWorkspaceSettings = builder.overrideWorkspaceConfiguration; this.distribution = builder.gradleDistribution == null ? GradleDistribution.fromBuild() : builder.gradleDistribution; @@ -77,16 +67,14 @@ private CompositeProperties(CompositePropertiesBuilder builder) { this.showExecutionsView = builder.showExecutionsView; this.useProjectAsRoot = builder.projectAsCompositeRoot; this.rootProject = builder.rootProject == null ? null: builder.rootProject; - - } - public static CompositePropertiesReader getCompositeReaderForFile(File compositeProperties) { - return new CompositePropertiesReader(compositeProperties); + public static CompositePropertiesReader getCompositeReaderForFile(String compositeName) { + return new CompositePropertiesReader(compositeName); } - public static CompositePropertiesBuilder forRootProjectDirectory(File rootProjectDirectory) { - return new CompositePropertiesBuilder(rootProjectDirectory); + public static CompositePropertiesBuilder create() { + return new CompositePropertiesBuilder(); } public static CompositePropertiesBuilder forCompositeConfiguration(CompositeConfiguration compositeConf) { @@ -96,7 +84,7 @@ public static CompositePropertiesBuilder forCompositeConfiguration(CompositeConf public Properties toProperties() { Properties prop = new Properties(); - prop.put(KEY_COMPOSITE_PROJECTS, getProjectString(this.projectList)); + prop.put(KEY_COMPOSITE_PROJECTS, this.projectList.toString()); prop.put(KEY_OVERWRITE_WORKSPACE_SETTINGS, this.overwriteWorkspaceSettings.toString()); prop.put(KEY_DISTRIBUTION, this.distribution == null ? GradleDistribution.fromBuild() : this.distribution.toString()); prop.put(KEY_GRADLE_USER_HOME, this.gradleUserHome == null ? "" : this.gradleUserHome.getAbsolutePath()); @@ -113,32 +101,13 @@ public Properties toProperties() { return prop; } - private String getProjectString(IAdaptable[] projects) { - StringBuilder sb = new StringBuilder(); - for (Iterator it = Arrays.asList(projects).iterator(); it.hasNext();) { - IAdaptable project = it.next(); - if (project instanceof IProject) { - if (it.hasNext()) { - sb.append(((IProject) project).getName() + ", "); - } else { - sb.append(((IProject) project).getName()); - } - } else if (project instanceof IResource) { - IResource externalProject = (IResource) project; - System.out.println(externalProject.getName()); - } - } - return sb.toString(); - } - private String removeBrackets(String arguments) { return arguments.replace("[", "").replace("]", "").replace(",", ""); } public static final class CompositePropertiesBuilder { - private final File compositeDirectory; - public IAdaptable[] projectList; + public List projectList; private boolean overrideWorkspaceConfiguration = false; private GradleDistribution gradleDistribution; private File gradleUserHome = null; @@ -153,13 +122,11 @@ public static final class CompositePropertiesBuilder { private boolean projectAsCompositeRoot = false; private File rootProject = null; - private CompositePropertiesBuilder(File compositeDirectory) { - this.compositeDirectory = compositeDirectory; + private CompositePropertiesBuilder() { } public CompositePropertiesBuilder(CompositeConfiguration compositeConf) { - this.compositeDirectory = compositeConf.getCompositeDir(); - this.projectList = compositeConf.getProjectList(); + this.projectList = compositeConf.getIncludedBuilds(); this.overrideWorkspaceConfiguration = compositeConf.getBuildConfiguration().isOverrideWorkspaceSettings(); this.gradleDistribution = compositeConf.getBuildConfiguration().getGradleDistribution(); this.gradleUserHome = compositeConf.getBuildConfiguration().getGradleUserHome(); @@ -172,11 +139,11 @@ public CompositePropertiesBuilder(CompositeConfiguration compositeConf) { this.showConsoleView = compositeConf.getBuildConfiguration().isShowConsoleView(); this.showExecutionsView = compositeConf.getBuildConfiguration().isShowExecutionsView(); this.projectAsCompositeRoot = compositeConf.projectAsCompositeRoot(); - this.rootProject = compositeConf.getRootProject(); + this.rootProject = compositeConf.getBuildConfiguration().getRootProjectDirectory(); } - public CompositePropertiesBuilder projectList(IAdaptable[] projectList) { + public CompositePropertiesBuilder projectList(List projectList) { this.projectList = projectList; return this; } @@ -252,13 +219,12 @@ public CompositeProperties build() { } public static final class CompositePropertiesReader { - private final File compositeDirectory; private Properties compositeProperties = new Properties(); - private CompositePropertiesReader(File compositeDirectory) { - this.compositeDirectory = compositeDirectory; + private CompositePropertiesReader(String compositeName) { + File compositeDirectory = CorePlugin.getInstance().getStateLocation().append("workspace-composites").append(compositeName).toFile(); try { - FileInputStream input= new FileInputStream(this.compositeDirectory); + FileInputStream input= new FileInputStream(compositeDirectory); this.compositeProperties = new Properties(); this.compositeProperties.load(input); } catch (IOException e) { @@ -270,10 +236,6 @@ public boolean getProjectAsCompositeRoot() { return Boolean.valueOf(this.compositeProperties.get(KEY_USE_PROJECT_AS_ROOT).toString()); } - public File getRootProject() { - return new File(this.compositeProperties.get(KEY_ROOT_PROJECT).toString()); - } - //If needed implement reader for other properties } diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/BuildConfigurationPersistence.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/BuildConfigurationPersistence.java index a4ae4be075..21e9cff30a 100644 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/BuildConfigurationPersistence.java +++ b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/BuildConfigurationPersistence.java @@ -45,6 +45,8 @@ final class BuildConfigurationPersistence { private static final String PREF_KEY_JVM_ARGUMENTS = "jvm.arguments"; private static final String PREF_KEY_SHOW_CONSOLE_VIEW = "show.console.view"; private static final String PREF_KEY_SHOW_EXECUTIONS_VIEW = "show.executions.view"; + private static final String PREF_KEY_USE_PROJECT_AS_ROOT = "project.as.root"; + private static final String PREF_KEY_ROOT_PROJECT = "root.project"; public DefaultBuildConfigurationProperties readBuildConfiguratonProperties(IProject project) { Preconditions.checkNotNull(project); @@ -61,10 +63,10 @@ public DefaultBuildConfigurationProperties readBuildConfiguratonProperties(File public DefaultBuildConfigurationProperties readCompositeBuildProperties(File compositeDir) { Preconditions.checkNotNull(compositeDir); PreferenceStore preferences = PreferenceStore.forPreferenceFile(compositeDir); - return readPreferences(preferences, compositeDir); + return readCompositePreferences(preferences, compositeDir); } - public void saveBuildConfiguration(IProject project, DefaultBuildConfigurationProperties properties) { + public void saveBuildConfiguration(IProject project, DefaultBuildConfigurationProperties properties) { Preconditions.checkNotNull(project); Preconditions.checkNotNull(properties); PreferenceStore preferences = PreferenceStore.forProjectScope(project, PREF_NODE); @@ -155,6 +157,40 @@ private static DefaultBuildConfigurationProperties readPreferences(PreferenceSto return new DefaultBuildConfigurationProperties(rootDir, distribution, gradleUserHome, javaHome, overrideWorkspaceSettings, buildScansEnabled, offlineMode, autoSync, arguments, jvmArguments, showConsoleView, showExecutionsView); } + + private DefaultBuildConfigurationProperties readCompositePreferences(PreferenceStore preferences, + File compositePreferencesDir) { + boolean overrideWorkspaceSettings = preferences.readBoolean(PREF_KEY_OVERRIDE_WORKSPACE_SETTINGS, false); + + String distributionString = preferences.readString(PREF_KEY_CONNECTION_GRADLE_DISTRIBUTION, null); + GradleDistribution distribution; + try { + distribution = GradleDistribution.fromString(distributionString); + } catch (RuntimeException ignore) { + distribution = GradleDistribution.fromBuild(); + } + + String gradleUserHomeString = preferences.readString(PREF_KEY_GRADLE_USER_HOME, ""); + File gradleUserHome = gradleUserHomeString.isEmpty() + ? null + : new File(gradleUserHomeString); + String javaHomeString = preferences.readString(PREF_KEY_JAVA_HOME, ""); + File javaHome = javaHomeString.isEmpty() + ? null + : new File(javaHomeString); + + boolean buildScansEnabled = preferences.readBoolean(PREF_KEY_BUILD_SCANS_ENABLED, false); + boolean offlineMode = preferences.readBoolean(PREF_KEY_OFFLINE_MODE, false); + boolean autoSync = preferences.readBoolean(PREF_KEY_AUTO_SYNC, false); + List arguments = Lists.newArrayList(Splitter.on(' ').omitEmptyStrings().split(preferences.readString(PREF_KEY_ARGUMENTS, ""))); + List jvmArguments = Lists.newArrayList(Splitter.on(' ').omitEmptyStrings().split(preferences.readString(PREF_KEY_JVM_ARGUMENTS, ""))); + boolean showConsoleView = preferences.readBoolean(PREF_KEY_SHOW_CONSOLE_VIEW, false); + boolean showExecutionsView = preferences.readBoolean(PREF_KEY_SHOW_EXECUTIONS_VIEW, false); + + File rootDir = new File(preferences.readString(PREF_KEY_ROOT_PROJECT, compositePreferencesDir.getAbsolutePath())); + + return new DefaultBuildConfigurationProperties(rootDir, distribution, gradleUserHome, javaHome, overrideWorkspaceSettings, buildScansEnabled, offlineMode, autoSync, arguments, jvmArguments, showConsoleView, showExecutionsView); + } private static void savePreferences(DefaultBuildConfigurationProperties properties, PreferenceStore preferences) { if (properties.isOverrideWorkspaceSettings()) { diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/CompositeConfiguration.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/CompositeConfiguration.java index 3d9c50961d..d89b1e1139 100644 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/CompositeConfiguration.java +++ b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/CompositeConfiguration.java @@ -11,8 +11,7 @@ package org.eclipse.buildship.core.internal.configuration; import java.io.File; - -import org.eclipse.core.runtime.IAdaptable; +import java.util.List; /** * Configuration for a workspace composite in a Gradle build. @@ -21,13 +20,11 @@ */ public interface CompositeConfiguration { - File getCompositeDir(); + String getCompositeName(); - IAdaptable[] getProjectList(); + List getIncludedBuilds(); BuildConfiguration getBuildConfiguration(); Boolean projectAsCompositeRoot(); - - File getRootProject(); } diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/ConfigurationManager.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/ConfigurationManager.java index c7332bfd54..a4754995d2 100644 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/ConfigurationManager.java +++ b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/ConfigurationManager.java @@ -14,7 +14,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.ui.IWorkingSet; import org.eclipse.buildship.core.GradleDistribution; @@ -50,7 +49,7 @@ BuildConfiguration createBuildConfiguration(File rootProjectDirectory, boolean o void deleteProjectConfiguration(IProject project); - CompositeConfiguration loadCompositeConfiguration(IWorkingSet workingSet); + CompositeConfiguration loadCompositeConfiguration(String workingSetName); void saveCompositeConfiguration(CompositeConfiguration compConf); diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultCompositeConfiguration.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultCompositeConfiguration.java index 867571fb4c..661d054c52 100644 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultCompositeConfiguration.java +++ b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultCompositeConfiguration.java @@ -11,35 +11,32 @@ package org.eclipse.buildship.core.internal.configuration; import java.io.File; +import java.util.List; import com.google.common.base.Objects; import com.google.common.base.Preconditions; -import org.eclipse.core.runtime.IAdaptable; - public class DefaultCompositeConfiguration implements CompositeConfiguration { - private final File compositeDir; - private final IAdaptable[] projectList; + private final String compositeName; + private final List projectList; private final BuildConfiguration buildConfiguration; private final Boolean projectAsCompositeRoot; - private final File rootProject; - public DefaultCompositeConfiguration(File compositeDir, IAdaptable[] projectList, BuildConfiguration buildConfiguration, Boolean projectAsCompositeRoot, File rootProject) { - this.compositeDir = Preconditions.checkNotNull(compositeDir); + public DefaultCompositeConfiguration(String compositeName, List projectList, BuildConfiguration buildConfiguration, Boolean projectAsCompositeRoot) { + this.compositeName = Preconditions.checkNotNull(compositeName); this.projectList = Preconditions.checkNotNull(projectList); this.buildConfiguration = Preconditions.checkNotNull(buildConfiguration); this.projectAsCompositeRoot = Preconditions.checkNotNull(projectAsCompositeRoot); - this.rootProject = Preconditions.checkNotNull(rootProject); } @Override - public File getCompositeDir() { - return this.compositeDir; + public String getCompositeName() { + return this.compositeName; } @Override - public IAdaptable[] getProjectList() { + public List getIncludedBuilds() { return this.projectList; } @@ -48,11 +45,6 @@ public BuildConfiguration getBuildConfiguration() { return this.buildConfiguration; } - @Override - public File getRootProject() { - return this.rootProject; - } - @Override public Boolean projectAsCompositeRoot() { return this.projectAsCompositeRoot; @@ -62,15 +54,17 @@ public Boolean projectAsCompositeRoot() { public boolean equals(Object obj) { if (obj instanceof DefaultCompositeConfiguration) { DefaultCompositeConfiguration other = (DefaultCompositeConfiguration) obj; - return Objects.equal(this.compositeDir, other.compositeDir) - && Objects.equal(this.buildConfiguration, other.buildConfiguration); + return Objects.equal(this.compositeName, other.compositeName) + && Objects.equal(this.projectList, other.projectList) + && Objects.equal(this.buildConfiguration, other.buildConfiguration) + && Objects.equal(this.projectAsCompositeRoot, other.projectAsCompositeRoot); } return false; } @Override public int hashCode() { - return Objects.hashCode(this.compositeDir, + return Objects.hashCode(this.compositeName, this.buildConfiguration); } diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultConfigurationManager.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultConfigurationManager.java index 3c2444602c..17ab25a15c 100644 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultConfigurationManager.java +++ b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultConfigurationManager.java @@ -13,6 +13,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Properties; @@ -28,11 +29,9 @@ import org.eclipse.buildship.core.internal.launch.GradleTestRunConfigurationAttributes; import org.eclipse.buildship.core.internal.util.file.RelativePathUtils; import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.ui.IWorkingSet; import com.google.common.base.Optional; import com.google.common.base.Preconditions; @@ -171,20 +170,24 @@ public void deleteProjectConfiguration(IProject project) { this.buildConfigurationPersistence.deletePathToRoot(project.getLocation().toFile()); } } + + private File getCompositePropertiesFile(String compositeName) { + return CorePlugin.getInstance().getStateLocation().append("workspace-composites").append(compositeName).toFile(); + } @Override - public CompositeConfiguration loadCompositeConfiguration(IWorkingSet workingSet) { - File compositePropertiesFile = CorePlugin.getInstance().getStateLocation().append("workspace-composites").append(workingSet.getName()).toFile(); + public CompositeConfiguration loadCompositeConfiguration(String workingSetName) { + File compositePropertiesFile = getCompositePropertiesFile(workingSetName); BuildConfiguration buildConfig = loadBuildConfigurationForComposite(compositePropertiesFile); - IAdaptable[] projectList = loadCompositeProjects(workingSet); - CompositePropertiesReader compositeReader = CompositeProperties.getCompositeReaderForFile(compositePropertiesFile); + List projectList = loadCompositeProjects(compositePropertiesFile); + CompositePropertiesReader compositeReader = CompositeProperties.getCompositeReaderForFile(workingSetName); boolean projectAsCompositeRoot = compositeReader.getProjectAsCompositeRoot(); - File rootProject = compositeReader.getRootProject(); - return new DefaultCompositeConfiguration(canonicalize(compositePropertiesFile), projectList, buildConfig, projectAsCompositeRoot, rootProject); + return new DefaultCompositeConfiguration(workingSetName, projectList, buildConfig, projectAsCompositeRoot); } - private IAdaptable[] loadCompositeProjects(IWorkingSet workingSet) { - IAdaptable[] projects = workingSet.getElements(); + private List loadCompositeProjects(File compositePropertiesFile) { + List projects = new ArrayList(); + //TODO (kuzniarz) add File read loop for project list creation //TODO (kuzniarz) implement load mechanism that reads external gradle projects from properties file. Needs a save mechanism first... return projects; } @@ -192,7 +195,7 @@ private IAdaptable[] loadCompositeProjects(IWorkingSet workingSet) { @Override public void saveCompositeConfiguration(CompositeConfiguration compConf) { try { - FileOutputStream out = new FileOutputStream(compConf.getCompositeDir()); + FileOutputStream out = new FileOutputStream(getCompositePropertiesFile(compConf.getCompositeName())); Properties prop = CompositeProperties.forCompositeConfiguration(compConf).build().toProperties(); prop.store(out, ""); } catch (FileNotFoundException e) { diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/binding/Validators.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/binding/Validators.java index 60eec83b52..bf8954841d 100644 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/binding/Validators.java +++ b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/binding/Validators.java @@ -20,9 +20,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.osgi.util.NLS; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.IWorkingSetManager; -import org.eclipse.ui.PlatformUI; import org.eclipse.buildship.core.internal.CorePlugin; import org.eclipse.buildship.core.internal.i18n.CoreMessages; @@ -165,11 +162,9 @@ private boolean compositePropertiesFileDoesNotExist(String compositeName) { } private boolean compositeNameAlreadyExistsinWorkspace(String compositeName) { - - IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); - IWorkingSet[] workingSets = workingSetManager.getAllWorkingSets(); - for (IWorkingSet workingSet : workingSets) { - if (workingSet.getName().equals(compositeName)) { + File compositePreferencesFolder = CorePlugin.getInstance().getStateLocation().append("workspace-composites").toFile(); + for (File workingSetPreferences : compositePreferencesFolder.listFiles()) { + if (workingSetPreferences.getName().equals(compositeName)) { return true; } } diff --git a/org.eclipse.buildship.ui/META-INF/MANIFEST.MF b/org.eclipse.buildship.ui/META-INF/MANIFEST.MF index 6e68e43e38..56b942275d 100644 --- a/org.eclipse.buildship.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.buildship.ui/META-INF/MANIFEST.MF @@ -20,9 +20,11 @@ Require-Bundle: org.eclipse.buildship.core, org.eclipse.jdt.ui, org.eclipse.jface.databinding, org.eclipse.jface.text, + org.eclipse.jface, com.ibm.icu, com.google.guava;bundle-version="[27.0.0,28.0.0)", org.gradle.toolingapi;bundle-version="[6.3.0,6.4.0)", - org.eclipse.ui.workbench.texteditor + org.eclipse.ui.workbench.texteditor, + org.eclipse.jface Bundle-ActivationPolicy: lazy Bundle-ClassPath: . diff --git a/org.eclipse.buildship.ui/plugin.xml b/org.eclipse.buildship.ui/plugin.xml index 17d7b8eab3..90cb2de691 100644 --- a/org.eclipse.buildship.ui/plugin.xml +++ b/org.eclipse.buildship.ui/plugin.xml @@ -165,6 +165,12 @@ name="Add Gradle Nature" description="Adds the Gradle nature and synchronizes this project as if the Gradle Import wizard had been run on its location."> + + + + @@ -297,6 +307,11 @@ icon="icons/full/elcl16/refresh.png" disabledIcon="icons/full/dlcl16/refresh.png"> + + @@ -468,6 +483,10 @@ commandId="org.eclipse.buildship.ui.commands.refreshproject" style="push"> + + + pageClass="org.eclipse.buildship.ui.internal.preferences.GradleCreateWorkspaceCompositePreferencePage"> compositeBuilds = getIncludedBuildsList(composite); ConfigurationManager manager = CorePlugin.configurationManager(); - CompositeConfiguration currentConfig = manager.loadCompositeConfiguration(composite); + CompositeConfiguration currentConfig = manager.loadCompositeConfiguration(composite.getName()); BuildConfiguration updatedConfig = manager.createBuildConfiguration(currentConfig.getBuildConfiguration().getRootProjectDirectory(), this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().getSelection(), @@ -111,12 +117,21 @@ public boolean performOk() { this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJvmArguments(), this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().getSelection(), this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().getSelection()); - CompositeConfiguration compConf = new DefaultCompositeConfiguration(currentConfig.getCompositeDir(), composite.getElements(), updatedConfig, currentConfig.projectAsCompositeRoot() ,currentConfig.getRootProject()); + CompositeConfiguration compConf = new DefaultCompositeConfiguration(composite.getName(), compositeBuilds, updatedConfig, currentConfig.projectAsCompositeRoot()); manager.saveCompositeConfiguration(compConf); return true; } - @SuppressWarnings("cast") + private List getIncludedBuildsList(IWorkingSet composite) { + List includedBuildsList = new ArrayList(); + for (IAdaptable element : composite.getElements()) { + InternalGradleBuild gradleBuild = (InternalGradleBuild) CorePlugin.internalGradleWorkspace().getBuild(((IProject) element)).get(); + includedBuildsList.add(gradleBuild.getBuildConfig().getRootProjectDirectory()); + } + return includedBuildsList; + } + + @SuppressWarnings("cast") private IWorkingSet getTargetComposite() { return (IWorkingSet) Platform.getAdapterManager().getAdapter(getElement(), IWorkingSet.class); } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java index 7ffa553681..bddba5753b 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java @@ -11,7 +11,22 @@ package org.eclipse.buildship.ui.internal.preferences; import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.buildship.core.internal.CorePlugin; +import org.eclipse.buildship.core.internal.configuration.BuildConfiguration; +import org.eclipse.buildship.core.internal.configuration.CompositeConfiguration; +import org.eclipse.buildship.core.internal.configuration.ConfigurationManager; +import org.eclipse.buildship.core.internal.configuration.DefaultCompositeConfiguration; +import org.eclipse.buildship.core.internal.util.binding.Validator; +import org.eclipse.buildship.core.internal.util.binding.Validators; +import org.eclipse.buildship.core.internal.workspace.InternalGradleBuild; +import org.eclipse.buildship.ui.internal.util.file.DirectoryDialogSelectionListener; +import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; @@ -30,16 +45,6 @@ import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.dialogs.PropertyPage; -import org.eclipse.buildship.core.internal.CorePlugin; -import org.eclipse.buildship.core.internal.configuration.CompositeConfiguration; -import org.eclipse.buildship.core.internal.configuration.ConfigurationManager; -import org.eclipse.buildship.core.internal.configuration.DefaultCompositeConfiguration; -import org.eclipse.buildship.core.internal.util.binding.Validator; -import org.eclipse.buildship.core.internal.util.binding.Validators; -import org.eclipse.buildship.ui.internal.util.file.DirectoryDialogSelectionListener; -import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; -import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; - /** * Preference page for composite root project. * @@ -117,11 +122,11 @@ private Composite buildRootProjectSettingsComposite(Composite parent) { private void initValues() { IWorkingSet composite = getTargetComposite(); - this.compositeConfig = CorePlugin.configurationManager().loadCompositeConfiguration(composite); + this.compositeConfig = CorePlugin.configurationManager().loadCompositeConfiguration(composite.getName()); boolean useProjectAsCompositeRoot = this.compositeConfig.projectAsCompositeRoot(); this.projectAsCompositeRootCheckbox.setSelection(useProjectAsCompositeRoot); - this.workspaceCompositeRootProjectLabel.setText(this.compositeConfig.getRootProject().toString()); + this.workspaceCompositeRootProjectLabel.setText(this.compositeConfig.getBuildConfiguration().getRootProjectDirectory().toString()); updateEnablement(); } @@ -170,14 +175,33 @@ public void dispose() { public boolean performOk() { IWorkingSet composite = getTargetComposite(); ConfigurationManager manager = CorePlugin.configurationManager(); - CompositeConfiguration currentConfig = manager.loadCompositeConfiguration(composite); - - CompositeConfiguration compConf = new DefaultCompositeConfiguration(currentConfig.getCompositeDir(), - composite.getElements(), - currentConfig.getBuildConfiguration(), - this.projectAsCompositeRootCheckbox.getSelection(), - new File(this.workspaceCompositeRootProjectLabel.getText())); + CompositeConfiguration currentConfig = manager.loadCompositeConfiguration(composite.getName()); + BuildConfiguration updatedConfig = manager.createBuildConfiguration(new File(this.workspaceCompositeRootProjectLabel.getText()), + currentConfig.getBuildConfiguration().isOverrideWorkspaceSettings(), + currentConfig.getBuildConfiguration().getGradleDistribution(), + currentConfig.getBuildConfiguration().getGradleUserHome(), + currentConfig.getBuildConfiguration().getJavaHome(), + currentConfig.getBuildConfiguration().isBuildScansEnabled(), + currentConfig.getBuildConfiguration().isOfflineMode(), + currentConfig.getBuildConfiguration().isAutoSync(), + currentConfig.getBuildConfiguration().getArguments(), + currentConfig.getBuildConfiguration().getJvmArguments(), + currentConfig.getBuildConfiguration().isShowConsoleView(), + currentConfig.getBuildConfiguration().isShowExecutionsView()); + CompositeConfiguration compConf = new DefaultCompositeConfiguration(currentConfig.getCompositeName(), + getIncludedBuildsList(composite), + updatedConfig, + this.projectAsCompositeRootCheckbox.getSelection()); manager.saveCompositeConfiguration(compConf); return true; } + + private List getIncludedBuildsList(IWorkingSet composite) { + List includedBuildsList = new ArrayList(); + for (IAdaptable element : composite.getElements()) { + InternalGradleBuild gradleBuild = (InternalGradleBuild) CorePlugin.internalGradleWorkspace().getBuild(((IProject) element)).get(); + includedBuildsList.add(gradleBuild.getBuildConfig().getRootProjectDirectory()); + } + return includedBuildsList; + } } 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 cee6afe401..0eec4be7ce 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 @@ -17,7 +17,10 @@ import java.util.List; import java.util.Properties; +import org.eclipse.buildship.core.GradleBuild; import org.eclipse.buildship.core.internal.CorePlugin; +import org.eclipse.buildship.core.internal.configuration.GradleProjectNature; +import org.eclipse.buildship.core.internal.workspace.InternalGradleBuild; import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; import org.eclipse.buildship.ui.internal.util.widget.GradleProjectGroup; import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.CompositeConfiguration; @@ -28,6 +31,7 @@ import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.IGradleCompositeIDs; import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeCreationWizard; import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; @@ -94,8 +98,9 @@ protected String getPageId() { return "org.eclipse.buildship.ui.GradleCompositePage"; //$NON-NLS-1$ } + //TODO (kuzniarz) This will definitely need rework IAdaptable -> File private static CompositeCreationConfiguration getCompositeCreationConfiguration() { - ArrayList compositeElements = new ArrayList<>(); + List compositeElements = new ArrayList<>(); String compositeName = gradleComposite != null ? gradleComposite.getName() : ""; CompositeCreationWizardController creationController = new CompositeCreationWizardController(compositeName, compositeElements); return creationController.getConfiguration(); @@ -166,33 +171,34 @@ public void handleEvent(Event event) { } protected void updateCompositeProjects() { - List projectList = new ArrayList<>(); + List projectList = new ArrayList<>(); for (TreeItem treeElement : this.gradleProjectCheckboxtreeComposite.getCheckboxTree().getItems()) { if (treeElement.getChecked() == true) { if (treeElement.getText().contains(" (External): ")) { - //String[] treeValues = treeElement.getText().replace(" (External): ", "$").split("\\$"); + String[] treeValues = treeElement.getText().replace(" (External): ", "$").split("\\$"); // treeValues[0] contains the project name // treeValues[1] contains the file path - //File externalFolder = new File(treeValues[1]); - projectList.add(null); + File externalFolder = new File(treeValues[1]); + projectList.add(externalFolder); } else { - projectList.add(ResourcesPlugin.getWorkspace().getRoot().getProject(treeElement.getText())); + projectList.add(getGradleRootFor(ResourcesPlugin.getWorkspace().getRoot().getProject(treeElement.getText()))); } } } - getConfiguration().getProjectList().setValue(projectList.toArray(new IAdaptable[projectList.size()])); + getConfiguration().getIncludedBuildsList().setValue(projectList); this.creationConfiguration.setCompositeProjects(projectList); } + + protected File getGradleRootFor(IProject project) { + InternalGradleBuild gradleBuild = (InternalGradleBuild) CorePlugin.internalGradleWorkspace().getBuild(project).get(); + return gradleBuild.getBuildConfig().getRootProjectDirectory(); + } private void updateLocation() { - File parentLocation = CorePlugin.getInstance().getStateLocation().append("workspace-composites").toFile(); - File projectDir = parentLocation != null ? new File(parentLocation, this.workspaceCompositeNameText.getText()) - : null; - // always update project name last to ensure project name validation errors have // precedence in the UI - getConfiguration().getCompositePreferencesDir().setValue(projectDir); + getConfiguration().getCompositeName().setValue(this.workspaceCompositeNameText.getText()); this.creationConfiguration.setCompositeName(this.workspaceCompositeNameText.getText()); } @@ -205,15 +211,14 @@ protected String getPageContextInformation() { public void finish() { updateCompositeProjects(); String workspaceCompositeName = this.workspaceCompositeNameText.getText(); + String oldWorkspaceCompositeName = gradleComposite.getName(); IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); try { - File compositePreferenceFile = CorePlugin.getInstance().getStateLocation() - .append("workspace-composites").append(workspaceCompositeName).toFile(); - + File compositePreferenceFile = getWorkspaceCompositesPropertiesFile(workspaceCompositeName); + IAdaptable[] compositeElements = getCompositeElements(getConfiguration().getIncludedBuildsList().getValue()); if (gradleComposite == null) { - gradleComposite = workingSetManager.createWorkingSet(workspaceCompositeName, - getConfiguration().getProjectList().getValue()); + gradleComposite = workingSetManager.createWorkingSet(workspaceCompositeName, compositeElements); gradleComposite.setId(IGradleCompositeIDs.NATURE); } else { IAdaptable[] oldElements = gradleComposite.getElements(); @@ -221,21 +226,40 @@ public void finish() { gradleComposite.setName(this.workspaceCompositeNameText.getText()); } - if (!oldElements.equals(getConfiguration().getProjectList().getValue())) { - gradleComposite.setElements(getConfiguration().getProjectList().getValue()); + if (!oldElements.equals(compositeElements)) { + gradleComposite.setElements(compositeElements); } } FileOutputStream out = new FileOutputStream(compositePreferenceFile.getAbsoluteFile()); Properties prop = getConfiguration().toCompositeProperties().toProperties(); prop.store(out, " "); out.close(); + if (!workspaceCompositeName.equals(oldWorkspaceCompositeName)) { + File oldCompositeProperties = getWorkspaceCompositesPropertiesFile(oldWorkspaceCompositeName); + oldCompositeProperties.delete(); + } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } + + private File getWorkspaceCompositesPropertiesFile(String compositeName) { + return CorePlugin.getInstance().getStateLocation() + .append("workspace-composites").append(compositeName).toFile(); + } - @Override + private IAdaptable[] getCompositeElements(List includedBuildsList) { + List compositeElements = new ArrayList<>(); + for (File includedBuild : includedBuildsList) { + //TODO (kuzniarz) Fix: NoSuchElementException for external builds + //TODO (kuzniarz) Check if this gets tricky due to (FolderName != GradleProjectName)? + compositeElements.add(ResourcesPlugin.getWorkspace().getRoot().getProject(includedBuild.getName())); + } + return compositeElements.toArray(new IAdaptable[includedBuildsList.size()]); + } + + @Override public IWorkingSet getSelection() { return gradleComposite; } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/file/ExternalProjectDialogSelectionListener.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/file/ExternalProjectDialogSelectionListener.java index 4a5e611311..862fd0e777 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/file/ExternalProjectDialogSelectionListener.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/file/ExternalProjectDialogSelectionListener.java @@ -96,8 +96,8 @@ private String getProjectName(Properties gradleSettings) { } private File getGradleSettings(String projectDir) { - File groovyFile = new File(projectDir + "\\settings.gradle"); - File kotlinFile = new File(projectDir + "\\settings.gradle.kts"); + File groovyFile = new File(projectDir + "/settings.gradle"); + File kotlinFile = new File(projectDir + "/settings.gradle.kts"); if (groovyFile.exists()) { return groovyFile; } else if (kotlinFile.exists()) { 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 new file mode 100644 index 0000000000..c8910e602c --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/view/task/CompositeConfigurationDialogHandler.java @@ -0,0 +1,20 @@ +package org.eclipse.buildship.ui.internal.view.task; + +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.CompositeSelectionDialog; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.*; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +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 new file mode 100644 index 0000000000..9b81bad30d --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractCompositeDialog.java @@ -0,0 +1,174 @@ +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.SelectionDialog; + +public abstract class AbstractCompositeDialog extends SelectionDialog { + + private Button newButton; + private Button editButton; + private Button removeButton; + private Button selectAllButton; + private Button deselectAllButton; + private CheckboxTableViewer compositeSelectionListViewer; + private ColumnLabelProvider labelProvider = new ColumnLabelProvider() { + private Map icons = new Hashtable<>(); + @Override + public String getText(Object element) { + Assert.isTrue(element instanceof IWorkingSet); + return ((IWorkingSet) element).getName(); + } + + @Override + public Image getImage(Object element) { + Assert.isTrue(element instanceof IWorkingSet); + ImageDescriptor imgDescriptor= ((IWorkingSet) element).getImageDescriptor(); + if (imgDescriptor == null) + return null; + Image icon= icons.get(imgDescriptor); + if (icon == null) { + icon= imgDescriptor.createImage(); + icons.put(imgDescriptor, icon); + } + return icon; + } + }; + + protected AbstractCompositeDialog(Shell parentShell) { + super(parentShell); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite container = createComponents(parent); + addListeners(); + loadCompositeNames(); + //initial composite selection + return container; + } + + private void loadCompositeNames() { + compositeSelectionListViewer.setLabelProvider(labelProvider); + compositeSelectionListViewer.setContentProvider(ArrayContentProvider.getInstance()); + IWorkingSet[] workingSetArray = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets(); + List composites = new ArrayList(); + for (IWorkingSet workingSet : workingSetArray) { + if (workingSet.getId().equals(IGradleCompositeIDs.NATURE)) { + composites.add(workingSet); + } + } + compositeSelectionListViewer.setInput(composites); + } + + private Composite createComponents(Composite parent) { + Composite container = (Composite) super.createDialogArea(parent); + container.setLayout(LayoutUtils.newGridLayout(4)); + createCompositeCheckboxList(container); + createSideButtonContainer(container); + createBottomButtonContainer(container); + return container; + } + + 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)); + 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.removeButton = new Button(buttonContainer, SWT.PUSH); + this.removeButton.setText("Remove"); + this.removeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + } + + private void createSideButtonContainer(Composite container) { + Composite sideButtonContainer = new Composite(container, SWT.NONE); + sideButtonContainer.setLayout(LayoutUtils.newGridLayout(1)); + sideButtonContainer.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1)); + this.selectAllButton = new Button(sideButtonContainer, SWT.PUSH); + this.selectAllButton.setText("Select All"); + this.selectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + this.deselectAllButton = new Button(sideButtonContainer, SWT.PUSH); + this.deselectAllButton.setText("Deselect All"); + this.deselectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + } + + 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)); + } + + private void addListeners() { + // TODO Auto-generated method stub + this.newButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + createNewWorkspaceComposite(); + } + }); + this.editButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + editWorkspaceComposite(); + } + }); + this.removeButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + removeWorkspaceComposite(); + } + }); + this.selectAllButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + selectAllWorkspaceComposites(); + } + }); + this.deselectAllButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + deselectAllWorkspaceComposites(); + } + }); + } + + protected void deselectAllWorkspaceComposites() { + compositeSelectionListViewer.setCheckedElements(new Object[0]); + } + + protected void selectAllWorkspaceComposites() { + compositeSelectionListViewer.setCheckedElements(PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets()); + } + + protected abstract void createNewWorkspaceComposite(); + protected abstract void editWorkspaceComposite(); + protected abstract void removeWorkspaceComposite(); + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeConfiguration.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeConfiguration.java index 1335f86147..84513048b3 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeConfiguration.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeConfiguration.java @@ -18,15 +18,14 @@ import org.eclipse.buildship.core.internal.util.binding.Validator; import org.eclipse.buildship.core.internal.util.binding.Validators; import org.eclipse.buildship.ui.internal.util.gradle.GradleDistributionViewModel; -import org.eclipse.core.runtime.IAdaptable; /** * Serves as the data model of the composite import wizard. */ public final class CompositeConfiguration { - private final Property compositePreferencesDir; - private final Property projectList; + private final Property compositeName; + private final Property> includedBuildsList; private final Property overwriteWorkspaceSettings; private final Property distribution; private final Property gradleUserHome; @@ -44,13 +43,13 @@ public final class CompositeConfiguration { private final Property rootProject; public CompositeConfiguration() { - this(Validators.noOp(), Validators.noOp(), Validators.noOp(), Validators.noOp(), Validators.noOp(), Validators.>noOp(), Validators.noOp()); + this(Validators.noOp(), Validators.noOp(), Validators.noOp(), Validators.noOp(), Validators.noOp(), Validators.>noOp(), Validators.noOp()); } - public CompositeConfiguration(Validator compositePreferencesDirValidator, Validator distributionValidator, + public CompositeConfiguration(Validator compositeNameValidator, Validator distributionValidator, Validator gradleUserHomeValidator, Validator javaHomeValidator, Validator applyWorkingSetsValidator, Validator> workingSetsValidators, Validator rootProjectValidator) { - this.compositePreferencesDir = Property.create(compositePreferencesDirValidator); - this.projectList = Property.create(Validators.noOp()); + this.compositeName = Property.create(compositeNameValidator); + this.includedBuildsList = Property.>create(Validators.>noOp()); this.overwriteWorkspaceSettings = Property.create(Validators.noOp()); this.distribution = Property.create(distributionValidator); this.gradleUserHome = Property.create(gradleUserHomeValidator); @@ -69,20 +68,20 @@ public CompositeConfiguration(Validator compositePreferencesDirValidator, } - public Property getCompositePreferencesDir() { - return this.compositePreferencesDir; + public Property getCompositeName() { + return this.compositeName; } - public void setCompositePreferencesDir(File compositePreferencesDir) { - this.compositePreferencesDir.setValue(compositePreferencesDir); + public void setCompositeName(String compositeName) { + this.compositeName.setValue(compositeName); } - public Property getProjectList() { - return this.projectList; + public Property> getIncludedBuildsList() { + return this.includedBuildsList; } - public void setProjectList(IAdaptable[] projectList) { - this.projectList.setValue(projectList); + public void setProjectList(List includedBuildsList) { + this.includedBuildsList.setValue(includedBuildsList); } public Property getOverrideWorkspaceConfiguration() { @@ -206,8 +205,8 @@ public void setRootProject(File rootProject) { } public CompositeProperties toCompositeProperties() { - return CompositeProperties.forRootProjectDirectory(getCompositePreferencesDir().getValue()) - .projectList(getProjectList().getValue()) + return CompositeProperties.create() + .projectList(getIncludedBuildsList().getValue()) .overrideWorkspaceConfiguration(getOverrideWorkspaceConfiguration().getValue()) .gradleDistribution(getDistribution().getValue().toGradleDistribution()) .gradleUserHome(getGradleUserHome().getValue()) diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationConfiguration.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationConfiguration.java index 3c3e5bc3b2..64178ed662 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationConfiguration.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationConfiguration.java @@ -10,19 +10,19 @@ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; +import java.io.File; import java.util.List; import org.eclipse.buildship.core.internal.util.binding.Property; -import org.eclipse.core.runtime.IAdaptable; import com.google.common.base.Preconditions; public class CompositeCreationConfiguration { private final Property compositeName; - private final Property> compositeProjects; + private final Property> compositeProjects; - public CompositeCreationConfiguration(Property compositeName, Property> compositeProjects) { + public CompositeCreationConfiguration(Property compositeName, Property> compositeProjects) { this.compositeName = Preconditions.checkNotNull(compositeName); this.compositeProjects = Preconditions.checkNotNull(compositeProjects); } @@ -35,11 +35,11 @@ public void setCompositeName(String compositeName) { this.compositeName.setValue(compositeName); } - public Property> getCompositeProjects() { + public Property> getCompositeProjects() { return this.compositeProjects; } - public void setCompositeProjects(List compositeProjects) { + public void setCompositeProjects(List compositeProjects) { this.compositeProjects.setValue(compositeProjects); } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationWizardController.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationWizardController.java index 9bf52530f2..c7715e8892 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationWizardController.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeCreationWizardController.java @@ -10,14 +10,17 @@ package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; +import java.io.File; import java.util.ArrayList; import java.util.List; +import org.eclipse.buildship.core.internal.CorePlugin; import org.eclipse.buildship.core.internal.util.binding.Property; import org.eclipse.buildship.core.internal.util.binding.Validators; import org.eclipse.buildship.core.internal.util.collections.CollectionsUtils; +import org.eclipse.buildship.core.internal.workspace.InternalGradleBuild; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.wizard.IWizard; @@ -33,22 +36,22 @@ public class CompositeCreationWizardController { public CompositeCreationWizardController(IWizard compositeCreationWizard) { // assemble configuration object that serves as the data model of the wizard Property compositeNameProperty = Property.create(Validators.uniqueWorkspaceCompositeNameValidator(WorkspaceCompositeWizardMessages.Label_CompositeName)); - Property> compositeProjectsProperty = Property.create(Validators.>nullValidator()); + Property> compositeProjectsProperty = Property.create(Validators.>nullValidator()); this.configuration = new CompositeCreationConfiguration(compositeNameProperty, compositeProjectsProperty); IDialogSettings dialogSettings = compositeCreationWizard.getDialogSettings(); String compositeName = dialogSettings.get(SETTINGS_KEY_COMPOSITE_NAME); - List compositeProjects = ImmutableList.copyOf(getProjects(CollectionsUtils.nullToEmpty(dialogSettings.getArray(SETTINGS_KEY_COMPOSITE_PROJECTS)))); + List compositeProjects = ImmutableList.copyOf(getIncludedBuildsList(CollectionsUtils.nullToEmpty(dialogSettings.getArray(SETTINGS_KEY_COMPOSITE_PROJECTS)))); this.configuration.setCompositeName(compositeName); this.configuration.setCompositeProjects(compositeProjects); } - public CompositeCreationWizardController(String compositeName, List compositeProjects) { + public CompositeCreationWizardController(String compositeName, List compositeProjects) { // assemble configuration object that serves as the data model of the wizard Property compositeNameProperty = Property.create(Validators.uniqueWorkspaceCompositeNameValidator(WorkspaceCompositeWizardMessages.Label_CompositeName)); - Property> compositeProjectsProperty = Property.create(Validators.>nullValidator()); + Property> compositeProjectsProperty = Property.create(Validators.>nullValidator()); this.configuration = new CompositeCreationConfiguration(compositeNameProperty, compositeProjectsProperty); @@ -56,14 +59,18 @@ public CompositeCreationWizardController(String compositeName, List this.configuration.setCompositeProjects(compositeProjects); } - private List getProjects(String[] projectArray) { - List projects = new ArrayList<>(); + private List getIncludedBuildsList(String[] projectArray) { + List includedBuilds = new ArrayList<>(); for (String projectName : projectArray) { - projects.add(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName)); + includedBuilds.add(getGradleRootFor(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName))); } - return projects; + return includedBuilds; } + protected File getGradleRootFor(IProject project) { + InternalGradleBuild gradleBuild = (InternalGradleBuild) CorePlugin.internalGradleWorkspace().getBuild(project).get(); + return gradleBuild.getBuildConfig().getRootProjectDirectory(); + } public CompositeCreationConfiguration getConfiguration() { return this.configuration; diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java index 816cb2e00a..4096268966 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeImportWizardController.java @@ -18,6 +18,7 @@ import java.util.Properties; import org.eclipse.buildship.core.GradleDistribution; +import org.eclipse.buildship.core.internal.CorePlugin; import org.eclipse.buildship.core.internal.i18n.CoreMessages; import org.eclipse.buildship.core.internal.util.binding.Property; import org.eclipse.buildship.core.internal.util.binding.ValidationListener; @@ -28,7 +29,7 @@ import org.eclipse.buildship.ui.internal.UiPlugin; import org.eclipse.buildship.ui.internal.util.gradle.GradleDistributionViewModel; import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.wizard.IWizard; import org.eclipse.jface.wizard.IWizardContainer; @@ -48,8 +49,8 @@ public class CompositeImportWizardController { private IWorkingSet workingSet; - // keys to load/store project properties in the dialog setting - private static final String SETTINGS_KEY_COMPOSITE_DIR = "composite_location"; //$NON-NLS-1$ + // keys to load/store composite properties in the dialog setting + private static final String SETTINGS_KEY_COMPOSITE_NAME = "composite_location"; //$NON-NLS-1$ //private static final String SETTINGS_KEY_GRADLE_PROJECT_LIST = "gradle_project_list"; //$NON-NLS-1$ private static final String SETTINGS_KEY_GRADLE_DISTRIBUTION = "gradle_distribution"; //$NON-NLS-1$ private static final String SETTINGS_KEY_APPLY_WORKING_SETS = "apply_working_sets"; //$NON-NLS-1$ @@ -70,9 +71,7 @@ public class CompositeImportWizardController { public CompositeImportWizardController(IWizard compositeImportWizard) { // assemble configuration object that serves as the data model of the wizard - Validator compositePreferenceDirValidator = Validators.and( - Validators.requiredDirectoryValidator(WorkspaceCompositeWizardMessages.Label_CompositeName), - Validators.nonWorkspaceFolderValidator(WorkspaceCompositeWizardMessages.Label_CompositeName)); + Validator compositePreferenceDirValidator = Validators.nullValidator(); Validator gradleDistributionValidator = GradleDistributionViewModel.validator(); Validator applyWorkingSetsValidator = Validators.nullValidator(); Validator> workingSetsValidator = Validators.nullValidator(); @@ -92,7 +91,7 @@ public CompositeImportWizardController(IWizard compositeImportWizard) { dialogSettings = getOrCreateDialogSection(UiPlugin.getInstance().getDialogSettings()); } - Optional projectDir = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_COMPOSITE_DIR)); + String compositeName = dialogSettings.get(SETTINGS_KEY_COMPOSITE_NAME); String gradleDistributionString = dialogSettings.get(SETTINGS_KEY_GRADLE_DISTRIBUTION); Optional gradleUserHome = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_GRADLE_USER_HOME)); Optional javaHome = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_JAVA_HOME)); @@ -108,7 +107,7 @@ public CompositeImportWizardController(IWizard compositeImportWizard) { boolean projectAsCompositeRoot = dialogSettings.getBoolean(SETTINGS_KEY_PROJECT_AS_COMPOSITE_ROOT); Optional rootProject = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_ROOT_PROJECT)); - this.configuration.setCompositePreferencesDir(projectDir.orNull()); + this.configuration.setCompositeName(compositeName); this.configuration.setOverwriteWorkspaceSettings(false); GradleDistribution distribution; try { @@ -132,7 +131,7 @@ public CompositeImportWizardController(IWizard compositeImportWizard) { this.configuration.setRootProject(rootProject.orNull()); // store the values every time they change - saveFilePropertyWhenChanged(dialogSettings, SETTINGS_KEY_COMPOSITE_DIR, this.configuration.getCompositePreferencesDir()); + saveStringPropertyWhenChanged(dialogSettings, SETTINGS_KEY_COMPOSITE_NAME, this.configuration.getCompositeName()); saveDistributionPropertyWhenChanged(dialogSettings, this.configuration.getDistribution()); saveFilePropertyWhenChanged(dialogSettings, SETTINGS_KEY_GRADLE_USER_HOME, this.configuration.getGradleUserHome()); saveFilePropertyWhenChanged(dialogSettings, SETTINGS_KEY_JAVA_HOME, this.configuration.getJavaHome()); @@ -149,7 +148,16 @@ public CompositeImportWizardController(IWizard compositeImportWizard) { saveFilePropertyWhenChanged(dialogSettings, SETTINGS_KEY_ROOT_PROJECT, this.configuration.getRootProject()); } - private void saveBooleanPropertyWhenChanged(final IDialogSettings settings, final String settingsKey, final Property target) { + private void saveStringPropertyWhenChanged(IDialogSettings settings, String settingsKey, Property target) { + target.addValidationListener(new ValidationListener() { + @Override + public void validationTriggered(Property source, Optional validationErrorMessage) { + settings.put(settingsKey, target.getValue()); + } + }); + } + + private void saveBooleanPropertyWhenChanged(final IDialogSettings settings, final String settingsKey, final Property target) { target.addValidationListener(new ValidationListener() { @Override @@ -200,10 +208,12 @@ public CompositeConfiguration getConfiguration() { public boolean performCreateComposite(IWizardContainer container, IWorkingSetManager workingSetManager) { try { - File compositePreferenceFile = this.configuration.getCompositePreferencesDir().getValue(); + File compositePreferenceFile = CorePlugin.getInstance().getStateLocation() + .append("workspace-composites").append(this.configuration.getCompositeName().getValue()).toFile(); List projects = new ArrayList<>(); - for (IAdaptable project : getConfiguration().getProjectList().getValue()) { - projects.add((IProject) project); + for (File includedBuild : getConfiguration().getIncludedBuildsList().getValue()) { + //TODO (kuzniarz) check if this can cause problems bc (FolderName != GradleProjectName)? + projects.add(ResourcesPlugin.getWorkspace().getRoot().getProject(includedBuild.getName())); } this.workingSet = workingSetManager.createWorkingSet(compositePreferenceFile.getName(), projects.toArray(new IProject[projects.size()])); this.workingSet.setId(IGradleCompositeIDs.NATURE); 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 new file mode 100644 index 0000000000..cc28071f2e --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/CompositeSelectionDialog.java @@ -0,0 +1,45 @@ +package org.eclipse.buildship.ui.internal.wizard.workspacecomposite; + +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Shell; + +public class CompositeSelectionDialog extends AbstractCompositeDialog { + + + public CompositeSelectionDialog(Shell parentShell) { + super(parentShell); + this.setTitle(WorkspaceCompositeWizardMessages.Title_ConfigureGradleWorkspaceCompositeDialog); + } + + @Override + protected void createNewWorkspaceComposite() { + // TODO (kuzniarz) Open composite creation wizard + WizardDialog dialog = new WizardDialog(this.getShell(), new WorkspaceCompositeCreationWizard()); + dialog.open(); + } + + @Override + protected void editWorkspaceComposite() { + // TODO (kuzniarz) Composite properties for selected composite should be opened + + } + + @Override + protected void removeWorkspaceComposite() { + // TODO Auto-generated method stub + + } + + @Override + protected void okPressed() { + // TODO Auto-generated method stub + super.okPressed(); + } + + @Override + protected void cancelPressed() { + // TODO Auto-generated method stub + super.cancelPressed(); + } + +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java index 875005fd77..a6ecbac683 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java @@ -14,11 +14,13 @@ import java.util.ArrayList; import java.util.List; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; - +import org.eclipse.buildship.core.internal.CorePlugin; +import org.eclipse.buildship.core.internal.util.binding.Property; +import org.eclipse.buildship.core.internal.workspace.InternalGradleBuild; +import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; +import org.eclipse.buildship.ui.internal.util.widget.GradleProjectGroup; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; @@ -34,10 +36,8 @@ import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.PlatformUI; -import org.eclipse.buildship.core.internal.CorePlugin; -import org.eclipse.buildship.core.internal.util.binding.Property; -import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; -import org.eclipse.buildship.ui.internal.util.widget.GradleProjectGroup; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; /** * Page on the {@link WorkspaceCompositeCreationWizard} declaring the workspace composite name and included projects. @@ -69,7 +69,7 @@ public GradleCreateWorkspaceCompositeWizardPage() { private static CompositeCreationConfiguration getCompositeCreationConfiguration() { CompositeCreationWizardController creationController; - ArrayList compositeElements = new ArrayList<>(); + List compositeElements = new ArrayList<>(); if (gradleComposite != null) { creationController = new CompositeCreationWizardController(gradleComposite.getName(), compositeElements); } else { @@ -112,7 +112,7 @@ private void createContent(Composite root) { this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(root, hasSelectedElement()); GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(3, SWT.DEFAULT).applyTo(this.gradleProjectCheckboxtreeComposite); - getConfiguration().getProjectList().setValue(new IAdaptable[0]); + getConfiguration().getIncludedBuildsList().setValue(new ArrayList<>()); if (gradleComposite != null) { this.workspaceCompositeNameText.setText(gradleComposite.getName()); @@ -137,16 +137,13 @@ public void handleEvent(Event event) { } private void updateLocation() { - File parentLocation = CorePlugin.getInstance().getStateLocation().append("workspace-composites").toFile(); - File projectDir = parentLocation != null ? new File(parentLocation, this.workspaceCompositeNameText.getText()) : null; - // always update project name last to ensure project name validation errors have precedence in the UI - getConfiguration().getCompositePreferencesDir().setValue(projectDir); + getConfiguration().getCompositeName().setValue(this.workspaceCompositeNameText.getText()); this.creationConfiguration.setCompositeName(this.workspaceCompositeNameText.getText()); } protected void updateCompositeProjects() { - List projectList = new ArrayList<>(); + List projectList = new ArrayList<>(); for (TreeItem treeElement : this.gradleProjectCheckboxtreeComposite.getCheckboxTree().getItems()) { if (treeElement.getChecked() == true) { @@ -157,13 +154,18 @@ protected void updateCompositeProjects() { //File externalFolder = new File(treeValues[1]); projectList.add(null); } else { - projectList.add(ResourcesPlugin.getWorkspace().getRoot().getProject(treeElement.getText())); + projectList.add(getGradleRootFor(ResourcesPlugin.getWorkspace().getRoot().getProject(treeElement.getText()))); } } } - getConfiguration().getProjectList().setValue(projectList.toArray(new IAdaptable[projectList.size()])); + getConfiguration().getIncludedBuildsList().setValue(projectList); this.creationConfiguration.setCompositeProjects(projectList); } + + protected File getGradleRootFor(IProject project) { + InternalGradleBuild gradleBuild = (InternalGradleBuild) CorePlugin.internalGradleWorkspace().getBuild(project).get(); + return gradleBuild.getBuildConfig().getRootProjectDirectory(); + } @Override protected String getPageContextInformation() { diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java index fcf15f45eb..5c5de71196 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java @@ -25,6 +25,8 @@ public final class WorkspaceCompositeWizardMessages extends NLS { public static String Title_NewGradleWorkspaceCompositeWizardPage; public static String Title_NewGradleImportOptionsWizardPage; public static String Title_NewGradleCompositeRootWizardPage; + + public static String Title_ConfigureGradleWorkspaceCompositeDialog; public static String Label_CompositeName; 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 7337877a6f..a986b5264d 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,6 +17,8 @@ Title_NewGradleWorkspaceCompositeWizardPage=Gradle Workspace Composite Title_NewGradleImportOptionsWizardPage=Import Options Title_NewGradleCompositeRootWizardPage=Composite Root +Title_ConfigureGradleWorkspaceCompositeDialog=Configure Composite + Label_CompositeName=Composite name WarningMessage_GradleWorkspaceComposite_NameWhitespaces=Composite names should not contain whitespaces From 85ba1cd0384a5faad8a683f7885195cd61bfb3a8 Mon Sep 17 00:00:00 2001 From: kuzniarz Date: Tue, 23 Jun 2020 15:47:13 +0200 Subject: [PATCH 09/15] 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 0eec4be7ce..96ea1e2d87 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 c8910e602c..9b3413f17e 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 9b81bad30d..fd1a79f1cb 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 cc28071f2e..69f03d8014 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 0e50c7bd7c..cb534e63d6 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 a986b5264d..816ce8bc66 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 From a1fdf4dc66d89b5ac3eefc97a3b6a195abd35aa0 Mon Sep 17 00:00:00 2001 From: kuzniarz Date: Thu, 20 Aug 2020 15:58:55 +0200 Subject: [PATCH 10/15] Configuration GUI Fix - Changed GUI functionality and fixed several configuration bugs - Added GUI-Strings to messages class Signed-off-by: kuzniarz --- .../DefaultConfigurationManager.java | 1 - ...eCompositeImportOptionsPreferencePage.java | 21 +++++- ...reateWorkspaceCompositePreferencePage.java | 22 ++++-- .../util/widget/GradleProjectGroup.java | 20 ++++-- .../AbstractCompositeDialog.java | 71 ++----------------- .../CompositeSelectionDialog.java | 35 ++++----- ...dleCreateWorkspaceCompositeWizardPage.java | 1 - .../WorkspaceCompositeWizardMessages.java | 4 ++ ...orkspaceCompositeWizardMessages.properties | 4 ++ 9 files changed, 80 insertions(+), 99 deletions(-) diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultConfigurationManager.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultConfigurationManager.java index 17ab25a15c..ecc8e7f050 100644 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultConfigurationManager.java +++ b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/configuration/DefaultConfigurationManager.java @@ -75,7 +75,6 @@ public BuildConfiguration createBuildConfiguration(File rootProjectDirectory, bo @Override public BuildConfiguration loadBuildConfiguration(File rootDir) { - System.out.println(rootDir); Preconditions.checkNotNull(rootDir); Preconditions.checkArgument(rootDir.exists()); Optional projectCandidate = CorePlugin.workspaceOperations().findProjectByLocation(rootDir); diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java index 3c312d0c50..5a1fb0cefa 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java @@ -27,9 +27,13 @@ import org.eclipse.buildship.ui.internal.util.widget.GradleProjectSettingsComposite; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbenchPropertyPage; @@ -42,6 +46,7 @@ * * @author Sebastian Kuzniarz */ + public final class GradleCompositeImportOptionsPreferencePage extends PropertyPage implements IWorkbenchPropertyPage{ public static final String PAGE_ID = "org.eclipse.buildship.ui.compositeImportOptionsProperties"; @@ -64,11 +69,20 @@ protected Control createContents(Composite parent) { .withAutoSyncCheckbox() .withOverrideCheckbox("Override workspace settings", "Configure Workspace Settings") .build(); + this.gradleProjectSettingsComposite.setVisible(true); + initValues(); addListeners(); return this.gradleProjectSettingsComposite; } + @Override + public void applyData(Object data) { + // TODO Auto-generated method stub + super.applyData(data); + + } + private void initValues() { IWorkingSet composite = getTargetComposite(); @@ -124,9 +138,12 @@ public boolean performOk() { private List getIncludedBuildsList(IWorkingSet composite) { List includedBuildsList = new ArrayList(); + InternalGradleBuild gradleBuild = null; for (IAdaptable element : composite.getElements()) { - InternalGradleBuild gradleBuild = (InternalGradleBuild) CorePlugin.internalGradleWorkspace().getBuild(((IProject) element)).get(); - includedBuildsList.add(gradleBuild.getBuildConfig().getRootProjectDirectory()); + if (CorePlugin.internalGradleWorkspace().getBuild(((IProject) element)).isPresent()) { + gradleBuild = (InternalGradleBuild) CorePlugin.internalGradleWorkspace().getBuild(((IProject) element)).get(); + includedBuildsList.add(gradleBuild.getBuildConfig().getRootProjectDirectory()); + } } return includedBuildsList; } 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 96ea1e2d87..aa4b7c0ff1 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 @@ -17,9 +17,11 @@ import java.util.List; import java.util.Properties; +import org.eclipse.buildship.core.BuildConfiguration; import org.eclipse.buildship.core.GradleBuild; import org.eclipse.buildship.core.internal.CorePlugin; import org.eclipse.buildship.core.internal.configuration.GradleProjectNature; +import org.eclipse.buildship.core.internal.configuration.ProjectConfiguration; import org.eclipse.buildship.core.internal.workspace.InternalGradleBuild; import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; import org.eclipse.buildship.ui.internal.util.widget.GradleProjectGroup; @@ -35,6 +37,8 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Plugin; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.wizard.IWizardPage; @@ -144,11 +148,12 @@ private void createContent(Composite root) { GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(3, SWT.DEFAULT) .applyTo(this.gradleProjectCheckboxtreeComposite); - addListeners(); - if (gradleComposite != null) { this.workspaceCompositeNameText.setText(gradleComposite.getName()); + this.gradleProjectCheckboxtreeComposite.setCheckboxTreeSelection(gradleComposite.getElements()); } + + addListeners(); } private void addListeners() { @@ -252,13 +257,20 @@ private File getWorkspaceCompositesPropertiesFile(String compositeName) { private IAdaptable[] getCompositeElements(List includedBuildsList) { List compositeElements = new ArrayList<>(); for (File includedBuild : includedBuildsList) { - //TODO (kuzniarz) Fix: NoSuchElementException for external builds - //TODO (kuzniarz) Check if this gets tricky due to (FolderName != GradleProjectName)? - compositeElements.add(ResourcesPlugin.getWorkspace().getRoot().getProject(includedBuild.getName())); + //TODO (kuzniarz) Files need to be added to composite to be viewed in ProjectExplorer + if (isExternalProject(includedBuild)) { + //compositeElements.add(ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromOSString(includedBuild.getAbsolutePath()))); + } else { + compositeElements.add(ResourcesPlugin.getWorkspace().getRoot().getProject(includedBuild.getName())); + } } return compositeElements.toArray(new IAdaptable[includedBuildsList.size()]); } + private boolean isExternalProject(File includedBuild) { + return !ResourcesPlugin.getWorkspace().getRoot().getProject(includedBuild.getName()).exists(); + } + @Override public IWorkingSet getSelection() { return gradleComposite; diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java index b2094deda1..0c0e7fa365 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java @@ -77,7 +77,7 @@ public void createWidgets() { } this.gradleProjectTree.setUseHashlookup(true); - + this.buttonComposite = new Composite(this, SWT.NONE); this.buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1)); GridLayoutFactory.fillDefaults().numColumns(1).applyTo(this.buttonComposite); @@ -89,6 +89,7 @@ public void createWidgets() { this.addExternalGradleProject = new Button(this.buttonComposite, SWT.PUSH); this.addExternalGradleProject.setText(WorkspaceCompositeWizardMessages.Button_Add_ExternalGradleProject); this.addExternalGradleProject.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + this.addExternalGradleProject.setEnabled(false); addListener(); } @@ -110,10 +111,12 @@ public void widgetSelected(SelectionEvent e) { } private void configureTree() { - ArrayList selection = getInitialTreeSelection(); + selectTreeElements(selection); + } - try { + private void selectTreeElements(ArrayList selection) { + try { this.gradleProjectTree.getTree().setRedraw(false); for (TreeItem item : this.gradleProjectTree.getTree().getItems()) { if (selection.contains(item.getText())) { @@ -123,8 +126,7 @@ private void configureTree() { } finally { this.gradleProjectTree.getTree().setRedraw(true); } - - } + } public boolean hasSelectedItems() { return this.gradleProjectTree.getTree().getSelectionCount() > 0; @@ -176,6 +178,14 @@ public void run() { return projectNames; } + + public void setCheckboxTreeSelection(IAdaptable[] projects) { + ArrayList compositeProjects = new ArrayList(); + for (IAdaptable project : projects) { + compositeProjects.add(((IProject) project).getName()); + } + selectTreeElements(compositeProjects); + } private void fillCheckboxTreeWithProjects() { this.gradleProjectTree.getTree().removeAll(); 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 fd1a79f1cb..643160e414 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 @@ -25,22 +25,18 @@ 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.swt.widgets.Table; 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 { private Button newButton; private Button editButton; private Button removeButton; - private Button selectAllButton; - private Button deselectAllButton; - private CheckboxTableViewer compositeSelectionListViewer; - private TableViewer viewer; + private TableViewer compositeSelectionListViewer; List composites = new ArrayList(); private ColumnLabelProvider labelProvider = new ColumnLabelProvider() { private Map icons = new Hashtable<>(); @@ -76,26 +72,9 @@ protected Control createDialogArea(Composite parent) { Composite container = createComponents(parent); addListeners(); loadCompositeNames(); - //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(contentProvider); @@ -118,9 +97,8 @@ private Object selectionChanged() { private Composite createComponents(Composite parent) { Composite container = (Composite) super.createDialogArea(parent); - container.setLayout(LayoutUtils.newGridLayout(4)); + container.setLayout(LayoutUtils.newGridLayout(3)); createCompositeCheckboxList(container); - createSideButtonContainer(container); createBottomButtonContainer(container); return container; } @@ -130,35 +108,22 @@ private void createBottomButtonContainer(Composite container) { buttonContainer.setLayout(LayoutUtils.newGridLayout(3)); 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.setText(WorkspaceCompositeWizardMessages.CompositeConfigurationDialog_New); 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.setText(WorkspaceCompositeWizardMessages.CompositeConfigurationDialog_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.setText(WorkspaceCompositeWizardMessages.CompositeConfigurationDialog_Remove); this.removeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); this.removeButton.setEnabled(false); } - private void createSideButtonContainer(Composite container) { - Composite sideButtonContainer = new Composite(container, SWT.NONE); - sideButtonContainer.setLayout(LayoutUtils.newGridLayout(1)); - sideButtonContainer.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1)); - this.selectAllButton = new Button(sideButtonContainer, SWT.PUSH); - this.selectAllButton.setText("Select All"); - this.selectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - - this.deselectAllButton = new Button(sideButtonContainer, SWT.PUSH); - this.deselectAllButton.setText("Deselect All"); - this.deselectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - } - private void createCompositeCheckboxList(Composite container) { - this.compositeSelectionListViewer = CheckboxTableViewer.newCheckList(container, SWT.BORDER | SWT.MULTI); + this.compositeSelectionListViewer = new TableViewer(new Table(container, SWT.BORDER)); GridData data = new GridData(GridData.FILL_BOTH); data.heightHint = 200; data.widthHint = 250; @@ -185,18 +150,6 @@ public void widgetSelected(SelectionEvent e) { removeWorkspaceComposite(); } }); - this.selectAllButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - selectAllWorkspaceComposites(); - } - }); - this.deselectAllButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - deselectAllWorkspaceComposites(); - } - }); } protected ISelection getSelectedComposites() { @@ -212,18 +165,8 @@ protected void removeSelectedCompositesFromList(IStructuredSelection selection) 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]); } - protected void selectAllWorkspaceComposites() { - compositeSelectionListViewer.setCheckedElements(PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets()); - } - protected abstract void createNewWorkspaceComposite(); protected abstract void editWorkspaceComposite(); protected abstract void removeWorkspaceComposite(); 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 69f03d8014..e2d3d23a63 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 @@ -4,35 +4,37 @@ import java.util.Iterator; import java.util.List; +import org.eclipse.buildship.ui.internal.preferences.GradleCreateWorkspaceCompositePreferencePage; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jdt.internal.ui.workingsets.WorkingSetModel; +import org.eclipse.jface.preference.IPreferenceNode; +import org.eclipse.jface.preference.IPreferencePage; +import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.jface.preference.PreferenceManager; +import org.eclipse.jface.preference.PreferenceNode; 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.IWorkbenchPage; import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.IWorkingSetManager; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.IWorkingSetEditWizard; +import org.eclipse.ui.dialogs.PreferencesUtil; +import org.eclipse.ui.dialogs.PropertyPage; +import org.eclipse.ui.internal.dialogs.PropertyDialog; 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 @@ -51,13 +53,8 @@ protected void createNewWorkspaceComposite() { @Override protected void editWorkspaceComposite() { 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); - } + PreferencesUtil.createPropertyDialogOn(this.getShell(), (IWorkingSet) selection.getFirstElement(), + "org.eclipse.buildship.ui.GradleCompositePage", null, null).open(); } @Override @@ -77,9 +74,6 @@ protected void okPressed() { } } addedWorkingSets.clear(); - editedWorkingSets.clear(); - //TODO (kuzniarz) Enabling/Disabling composites in the workspace - System.out.println(result); super.okPressed(); } @@ -92,8 +86,7 @@ protected void cancelPressed() { it.remove(); } } - //restore edited composites - // TODO Auto-generated method stub + removedWorkingSets.clear(); super.cancelPressed(); } diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java index a6ecbac683..4f4a1eb842 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java @@ -94,7 +94,6 @@ protected void createWidgets(Composite root) { } private void createContent(Composite root) { - // composite name container Composite workspaceCompositeNameComposite = new Composite(root, SWT.FILL); GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 5).numColumns(2).applyTo(workspaceCompositeNameComposite); diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java index 5c5de71196..159861b2cb 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java @@ -51,6 +51,10 @@ public final class WorkspaceCompositeWizardMessages extends NLS { public static String Group_Label_GradleProjects; public static String Button_New_GradleProject; public static String Button_Add_ExternalGradleProject; + + public static String CompositeConfigurationDialog_New; + public static String CompositeConfigurationDialog_Edit; + public static String CompositeConfigurationDialog_Remove; public static String Label_RootProject; public static String Button_Select_RootProject; 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 816ce8bc66..79612a5516 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 @@ -42,6 +42,10 @@ InfoMessage_NewGradleWorkspaceCompositeCompositeRootWizardPageContext=Click the Group_Label_GradleProjects=Gradle projects Button_New_GradleProject=New... Button_Add_ExternalGradleProject=Add external... + +CompositeConfigurationDialog_New=New... +CompositeConfigurationDialog_Edit=Edit... +CompositeConfigurationDialog_Remove=Remove Label_RootProject=Root project Button_Select_RootProject=Select... \ No newline at end of file From 2bf8ef0a2297da4aa822a0fb6199e33afe6f25f8 Mon Sep 17 00:00:00 2001 From: Sebastian Kuzniarz Date: Fri, 12 Apr 2019 13:18:59 +0200 Subject: [PATCH 11/15] Implemented no-op UIs for workspace-composite wizard + preferences (#867) * Implemented no-op UIs for workspace-composite wizard + preferences * Changed workspace composite wizard element name * Changed composite wizard element description * Fixed java doc and useless indent * Javadoc/author fix+ line nitpick * Remove UiBuilder * Fixed indend * Fixed javadoc and indent * Remove UiBuilder/JavaDoc fix * Fixed checkbox tree layout * Refactor HelpContextIdProvider and WizardHelper * Knitpick and format fix Signed-off-by: kuzniarz --- org.eclipse.buildship.ui/plugin.xml | 22 +++ ...eCompositeImportOptionsPreferencePage.java | 133 +++++++++++++ ...dleCompositeRootProjectPreferencePage.java | 93 +++++++++ ...radleWorkspaceCompositePreferencePage.java | 71 +++++++ .../util/widget/GradleProjectGroup.java | 87 +++++++++ .../ui/internal/util/widget/UiBuilder.java | 33 ++++ .../{project => }/HelpContextIdProvider.java | 2 +- .../wizard/{project => }/WizardHelper.java | 4 +- .../wizard/project/AbstractProjectWizard.java | 2 + .../wizard/project/AbstractWizardPage.java | 1 + .../ProjectImportWizardController.java | 1 + .../project/ProjectPreviewWizardPage.java | 1 + .../AbstractWizardPage.java | 180 ++++++++++++++++++ .../AbstractWorkspaceCompositeWizard.java | 75 ++++++++ ...dleCreateWorkspaceCompositeWizardPage.java | 71 +++++++ .../GradleImportOptionsWizardPage.java | 80 ++++++++ .../GradleRootProjectWizardPage.java | 102 ++++++++++ .../WorkspaceCompositeCreationWizard.java | 129 +++++++++++++ .../WorkspaceCompositeWizardMessages.java | 61 ++++++ ...orkspaceCompositeWizardMessages.properties | 39 ++++ 20 files changed, 1184 insertions(+), 3 deletions(-) create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeImportOptionsPreferencePage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java rename org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/{project => }/HelpContextIdProvider.java (92%) rename org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/{project => }/WizardHelper.java (89%) create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractWizardPage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/AbstractWorkspaceCompositeWizard.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleCreateWorkspaceCompositeWizardPage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleImportOptionsWizardPage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/GradleRootProjectWizardPage.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeCreationWizard.java create mode 100644 org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.java create mode 100644 org.eclipse.buildship.ui/src/main/resources/org/eclipse/buildship/ui/internal/wizard/workspacecomposite/WorkspaceCompositeWizardMessages.properties diff --git a/org.eclipse.buildship.ui/plugin.xml b/org.eclipse.buildship.ui/plugin.xml index 277c850514..4c344cf491 100644 --- a/org.eclipse.buildship.ui/plugin.xml +++ b/org.eclipse.buildship.ui/plugin.xml @@ -51,6 +51,28 @@ name="Gradle"> + + + + + + Create a new Gradle workspace composite. + + + + + + distributionValidator; + private final Validator javaHomeValidator; + private final Validator gradleUserHomeValidator; + + public GradleCompositeImportOptionsPreferencePage() { + this.gradleUserHomeValidator = Validators.optionalDirectoryValidator("Gradle user home"); + this.javaHomeValidator = Validators.optionalDirectoryValidator("Java home"); + this.distributionValidator = GradleDistributionViewModel.validator(); + } + + @Override + protected Control createContents(Composite parent) { + this.gradleProjectSettingsComposite = GradleProjectSettingsComposite.builder(parent) + .withAutoSyncCheckbox() + .withOverrideCheckbox("Override workspace settings", "Configure Workspace Settings") + .build(); + initValues(); + addListeners(); + return this.gradleProjectSettingsComposite; + } + + private void initValues() { + IProject project = getTargetProject(); + BuildConfiguration buildConfig = CorePlugin.configurationManager().loadProjectConfiguration(project).getBuildConfiguration(); + boolean overrideWorkspaceSettings = buildConfig.isOverrideWorkspaceSettings(); + this.gradleProjectSettingsComposite.getGradleDistributionGroup().setDistribution(GradleDistributionViewModel.from(buildConfig.getGradleDistribution())); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setGradleUserHome(buildConfig.getGradleUserHome()); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setJavaHome(buildConfig.getJavaHome()); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setArguments(buildConfig.getArguments()); + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().setJvmArguments(buildConfig.getJvmArguments()); + this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().setSelection(overrideWorkspaceSettings); + this.gradleProjectSettingsComposite.getBuildScansCheckbox().setSelection(buildConfig.isBuildScansEnabled()); + this.gradleProjectSettingsComposite.getOfflineModeCheckbox().setSelection(buildConfig.isOfflineMode()); + this.gradleProjectSettingsComposite.getAutoSyncCheckbox().setSelection(buildConfig.isAutoSync()); + this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().setSelection(buildConfig.isShowConsoleView()); + this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().setSelection(buildConfig.isShowExecutionsView()); + this.gradleProjectSettingsComposite.updateEnablement(); + } + + private void addListeners() { + this.gradleProjectSettingsComposite.getParentPreferenceLink().addSelectionListener(new WorkbenchPreferenceOpeningSelectionListener()); + AdvancedOptionsGroup advancedOptionsGroup = this.gradleProjectSettingsComposite.getAdvancedOptionsGroup(); + advancedOptionsGroup.getGradleUserHomeText().addModifyListener(new ValidatingListener<>(this, () -> advancedOptionsGroup.getGradleUserHome(), this.gradleUserHomeValidator)); + advancedOptionsGroup.getJavaHomeText().addModifyListener(new ValidatingListener<>(this, () -> advancedOptionsGroup.getJavaHome(), this.javaHomeValidator)); + this.gradleProjectSettingsComposite.getGradleDistributionGroup().addDistributionChangedListener(new GradleDistributionValidatingListener(this, this.distributionValidator)); + } + + @Override + public boolean performOk() { + IProject project = getTargetProject(); + ConfigurationManager manager = CorePlugin.configurationManager(); + BuildConfiguration currentConfig = manager.loadProjectConfiguration(project).getBuildConfiguration(); + BuildConfiguration updatedConfig = manager.createBuildConfiguration(currentConfig.getRootProjectDirectory(), + this.gradleProjectSettingsComposite.getOverrideBuildSettingsCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getGradleDistributionGroup().getDistribution().toGradleDistribution(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getGradleUserHome(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJavaHome(), + this.gradleProjectSettingsComposite.getBuildScansCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getOfflineModeCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getAutoSyncCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getArguments(), + this.gradleProjectSettingsComposite.getAdvancedOptionsGroup().getJvmArguments(), + this.gradleProjectSettingsComposite.getShowConsoleViewCheckbox().getSelection(), + this.gradleProjectSettingsComposite.getShowExecutionsViewCheckbox().getSelection()); + manager.saveBuildConfiguration(updatedConfig); + return true; + } + + @SuppressWarnings("cast") + private IProject getTargetProject() { + return (IProject) Platform.getAdapterManager().getAdapter(getElement(), IProject.class); + } + + /** + * Opens the workspace preferences dialog. + */ + private class WorkbenchPreferenceOpeningSelectionListener implements SelectionListener { + + @Override + public void widgetSelected(SelectionEvent e) { + openWorkspacePreferences(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + openWorkspacePreferences(); + } + + private void openWorkspacePreferences() { + PreferencesUtil.createPreferenceDialogOn(getShell(), GradleWorkbenchPreferencePage.PAGE_ID, null, null).open(); + } + } +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java new file mode 100644 index 0000000000..6570fd72b4 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleCompositeRootProjectPreferencePage.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2017 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.eclipse.buildship.ui.internal.preferences; + +import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Layout; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.PropertyPage; + +/** + * Preference page for composite root project. + * + * @author Sebastian Kuzniarz + */ + +public final class GradleCompositeRootProjectPreferencePage extends PropertyPage { + + public static final String PAGE_ID = "org.eclipse.buildship.ui.compositeRootProjectProperties"; + + private Text workspaceCompositeRootProjectLabel; + private Text overrideCheckboxLabel; + private Button overrideSettingsCheckbox; + private Button selectRootProject; + private Composite rootProjectSettingsComposite; + private Label rootProjectLabel; + + private Layout createLayout() { + GridLayout layout = LayoutUtils.newGridLayout(2); + layout.horizontalSpacing = 4; + layout.verticalSpacing = 4; + return layout; + } + + @Override + protected Control createContents(Composite parent) { + + this.rootProjectSettingsComposite = new Composite(parent, SWT.NONE); + rootProjectSettingsComposite.setLayout(createLayout()); + + this.overrideSettingsCheckbox = new Button(rootProjectSettingsComposite, SWT.CHECK); + this.overrideSettingsCheckbox.setText("Use project as composite root"); + GridDataFactory.swtDefaults().applyTo(rootProjectSettingsComposite); + + Label line = new Label(rootProjectSettingsComposite, SWT.SEPARATOR | SWT.HORIZONTAL); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).applyTo(line); + + // composite root container + Composite workspaceCompositeNameComposite = new Composite(rootProjectSettingsComposite, SWT.NONE); + GridLayoutFactory.swtDefaults().extendedMargins(0, 0, 0, 10).numColumns(3).applyTo(workspaceCompositeNameComposite); + GridDataFactory.swtDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).span(3, SWT.DEFAULT).applyTo(workspaceCompositeNameComposite); + + // root project label + this.rootProjectLabel = new Label(workspaceCompositeNameComposite, SWT.NONE); + this.rootProjectLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + this.rootProjectLabel.setText(WorkspaceCompositeWizardMessages.Label_RootProject); + + // root project text field + this.workspaceCompositeRootProjectLabel = new Text(workspaceCompositeNameComposite, SWT.BORDER); + this.workspaceCompositeRootProjectLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + // root project select button + this.selectRootProject = new Button(workspaceCompositeNameComposite, SWT.PUSH); + this.selectRootProject.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + this.selectRootProject.setText(WorkspaceCompositeWizardMessages.Button_Select_RootProject); + return rootProjectSettingsComposite; + } + + @Override + public void dispose() { + super.dispose(); + } + + @Override + public boolean performOk() { + return true; + } +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java new file mode 100644 index 0000000000..34d0b5a146 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/preferences/GradleWorkspaceCompositePreferencePage.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ + +package org.eclipse.buildship.ui.internal.preferences; + +import org.eclipse.buildship.ui.internal.util.font.FontUtils; +import org.eclipse.buildship.ui.internal.util.layout.LayoutUtils; +import org.eclipse.buildship.ui.internal.util.widget.GradleProjectGroup; +import org.eclipse.buildship.ui.internal.util.widget.UiBuilder; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.PropertyPage; + +/** + * Preference page for workspace composite configuration + * + * @author Sebastian Kuzniarz + */ +@SuppressWarnings("unused") +public final class GradleWorkspaceCompositePreferencePage extends PropertyPage { + + public static final String PAGE_ID = "org.eclipse.buildship.ui.compositeproperties"; + + private Text workspaceCompositeNameText; + private Label compositeName; + private GradleProjectGroup gradleProjectCheckboxtreeComposite; + private Composite gradleWorkspaceCompositeSettingsComposite; + + @Override + protected Control createContents(Composite parent) { + this.gradleWorkspaceCompositeSettingsComposite = new Composite(parent, SWT.FILL); + gradleWorkspaceCompositeSettingsComposite.setLayout(LayoutUtils.newGridLayout(2)); + + // composite name container + Composite workspaceCompositeNameComposite = new Composite(gradleWorkspaceCompositeSettingsComposite, SWT.FILL); + GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 5).numColumns(2).applyTo(workspaceCompositeNameComposite); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).span(3, SWT.DEFAULT).applyTo(workspaceCompositeNameComposite); + + // composite name label + this.compositeName = new Label(workspaceCompositeNameComposite, SWT.NONE); + this.compositeName.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + this.compositeName.setText(WorkspaceCompositeWizardMessages.Label_CompositeName); + + // composite name text field + this.workspaceCompositeNameText = new Text(workspaceCompositeNameComposite, SWT.BORDER); + this.workspaceCompositeNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + this.gradleProjectCheckboxtreeComposite = new GradleProjectGroup(gradleWorkspaceCompositeSettingsComposite); + GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(3, SWT.DEFAULT).applyTo(this.gradleProjectCheckboxtreeComposite); + + return gradleWorkspaceCompositeSettingsComposite; + } + + @Override + public boolean performOk() { + return true; + } +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java new file mode 100644 index 0000000000..2bd1a42502 --- /dev/null +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/GradleProjectGroup.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2015 the original author or authors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sebastian Kuzniarz (Diebold Nixdorf Inc.) - initial UI implementation + */ + +package org.eclipse.buildship.ui.internal.util.widget; + +import org.eclipse.buildship.ui.internal.util.gradle.GradleDistributionViewModel; +import org.eclipse.buildship.ui.internal.wizard.workspacecomposite.WorkspaceCompositeWizardMessages; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; + +@SuppressWarnings("unused") +public class GradleProjectGroup extends Group { + + private Font font; + private Button newGradleProject; + private Button addExternalGradleProject; + private Composite buttonComposite; + private Tree gradleProjectTree; + + public GradleProjectGroup(Composite parent) { + super(parent, SWT.NONE); + setText(WorkspaceCompositeWizardMessages.Group_Label_GradleProjects); + createWidgets(); + } + + public void createWidgets() { + setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayoutFactory.swtDefaults().numColumns(4).applyTo(this); + + this.gradleProjectTree = new Tree(this, SWT.CHECK); + this.gradleProjectTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + + this.buttonComposite = new Composite(this, SWT.NONE); + this.buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1)); + GridLayoutFactory.fillDefaults().numColumns(1).applyTo(buttonComposite); + + this.newGradleProject = new Button(buttonComposite, SWT.PUSH); + this.newGradleProject.setText(WorkspaceCompositeWizardMessages.Button_New_GradleProject); + this.newGradleProject.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + this.addExternalGradleProject = new Button(buttonComposite, SWT.PUSH); + this.addExternalGradleProject.setText(WorkspaceCompositeWizardMessages.Button_Add_ExternalGradleProject); + this.addExternalGradleProject.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + fillCheckboxTreeWithFakeData(); + } + + + private void fillCheckboxTreeWithFakeData() { + for (int i = 0; i < 4; i++) { + TreeItem iItem = new TreeItem(this.gradleProjectTree, 0); + iItem.setText("TreeItem (0) -" + i); + for (int j = 0; j < 4; j++) { + TreeItem jItem = new TreeItem(iItem, 0); + jItem.setText("TreeItem (1) -" + j); + for (int k = 0; k < 4; k++) { + TreeItem kItem = new TreeItem(jItem, 0); + kItem.setText("TreeItem (2) -" + k); + for (int l = 0; l < 4; l++) { + TreeItem lItem = new TreeItem(kItem, 0); + lItem.setText("TreeItem (3) -" + l); + } + } + } + } + } + + @Override + protected void checkSubclass() { + // Disable the check that prevents subclassing of SWT components + } +} diff --git a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/UiBuilder.java b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/UiBuilder.java index e4bc15aaa7..8960712bf5 100644 --- a/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/UiBuilder.java +++ b/org.eclipse.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/util/widget/UiBuilder.java @@ -84,6 +84,16 @@ public UiBuilder alignFillHorizontal() { this.control.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); return this; } + + /** + * Aligns the created widget to fill the cell vertically aligned at top. + * + * @return the builder + */ + public UiBuilder alignFillVerticalTop() { + this.control.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1)); + return this; + } /** * Aligns the created widget to fill both horizontal and vertical. @@ -176,6 +186,17 @@ public UiBuilder