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 36da6eef8..f05b3b6d4 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 57372c91c..ec8b3227a 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 f0331fe73..beb840934 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 9657c360c..7ffa55368 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 6ea0fcf74..cee6afe40 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 6d81e4007..70495b84a 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 21447250c..4a5e61131 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 fc3358614..b2094deda 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 2af0ec4a9..0baf57654 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 f5bde8ac4..f5cf0082d 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 bef3613ae..1335f8614 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 3484cf8a1..3c3e5bc3b 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 e93266e2b..9bf52530f 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 9170ad33c..816cb2e00 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 9aa68aa56..bfba41f60 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 6aeea4a2a..b30f30205 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 f1579c397..e635e97dd 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 e29a9f0f2..05aeb109c 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 e211834e9..8b779da96 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 f84eacc49..33cc8b229 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 6e4445ed8..54cdc0e37 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 57acd1933..768f584c8 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 f76a7216d..fa12eb509 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 c77b957e5..fcf15f45e 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 1ed990e27..ea76c4d5b 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 7fe9e2bba..5f1f0fc90 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 35c69a406..f63432dd2 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()); + } }