From 778157b5d39ceb66f840d9f9af7b304754ef28ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Porras=20Campo?= Date: Tue, 31 Mar 2026 12:04:16 +0200 Subject: [PATCH] feat: remove wizards for created checks --- .../check/ui/test/CheckCatalogWizardTest.java | 271 ---------- .../check/ui/test/CheckProjectWizardTest.java | 129 ----- .../ddk/check/ui/test/CheckUiTestSuite.java | 2 - .../ui/test/util/CheckWizardTestUtil.java | 191 ------- .../META-INF/MANIFEST.MF | 1 - .../tools/ddk/check/ui/CheckUiModule.java | 22 - .../check/ui/wizard/CheckCatalogCreator.java | 92 ---- .../ui/wizard/CheckCatalogGenerator.java | 79 --- .../ddk/check/ui/wizard/CheckNewProject.xtend | 50 -- .../check/ui/wizard/CheckProjectCreator.java | 120 ----- .../check/ui/wizard/CheckProjectFactory.java | 119 ----- .../ddk/check/ui/wizard/CheckProjectInfo.java | 121 ----- .../ui/wizard/CheckQuickfixProvider.xtend | 63 --- .../check/ui/wizard/ICheckCatalogCreator.java | 21 - .../tools/ddk/check/ui/wizard/Messages.java | 58 -- .../ui/wizard/NewCheckCatalogWizard.java | 91 ---- .../ui/wizard/NewCheckCatalogWizardPage.java | 496 ------------------ .../ui/wizard/NewCheckProjectWizard.java | 77 --- .../ui/wizard/NewCheckProjectWizardPage.java | 150 ------ .../ddk/check/ui/wizard/messages.properties | 20 - 20 files changed, 2173 deletions(-) delete mode 100644 com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckCatalogWizardTest.java delete mode 100644 com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckProjectWizardTest.java delete mode 100644 com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/util/CheckWizardTestUtil.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckCatalogCreator.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckCatalogGenerator.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckNewProject.xtend delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectCreator.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectFactory.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectInfo.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckQuickfixProvider.xtend delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/ICheckCatalogCreator.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/Messages.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckCatalogWizard.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckCatalogWizardPage.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckProjectWizard.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckProjectWizardPage.java delete mode 100644 com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/messages.properties diff --git a/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckCatalogWizardTest.java b/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckCatalogWizardTest.java deleted file mode 100644 index 7ddf752f33..0000000000 --- a/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckCatalogWizardTest.java +++ /dev/null @@ -1,271 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.test; - -import static com.avaloq.tools.ddk.test.ui.swtbot.util.SwtBotWizardUtil.selectProjectFolder; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertSame; - -import java.lang.reflect.InvocationTargetException; -import java.util.Collections; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.swtbot.swt.finder.waits.Conditions; -import org.eclipse.ui.actions.WorkspaceModifyOperation; -import org.eclipse.xtext.Grammar; -import org.eclipse.xtext.testing.InjectWith; -import org.eclipse.xtext.testing.extensions.InjectionExtension; -import org.eclipse.xtext.ui.util.PluginProjectFactory; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.junit.jupiter.api.TestInstance.Lifecycle; -import org.junit.jupiter.api.extension.ExtendWith; - -import com.avaloq.tools.ddk.check.ui.test.internal.CheckWizardUiTestInjectorProvider; -import com.avaloq.tools.ddk.check.ui.test.util.CheckWizardTestUtil; -import com.avaloq.tools.ddk.check.ui.util.CheckResourceUtil; -import com.avaloq.tools.ddk.check.ui.wizard.Messages; -import com.avaloq.tools.ddk.test.core.jupiter.BugTest; -import com.avaloq.tools.ddk.test.ui.swtbot.SwtWizardBot; -import com.google.inject.Inject; -import com.google.inject.Provider; - - -/** - * The CheckProjectWizardTestBackup tests the Check Project Wizard. - */ -@InjectWith(CheckWizardUiTestInjectorProvider.class) -@ExtendWith(InjectionExtension.class) -@SuppressWarnings("nls") -@TestInstance(Lifecycle.PER_CLASS) -public class CheckCatalogWizardTest { - - /** This is the name of the catalog wizard. It's the name SWTBot uses to look up the wizard. */ - private static final String CHECK_CATALOG = "Check Catalog"; - private static final String SRC_FOLDER = "src"; - - /** input strings for wizard testing. */ - private static final String VALID_PACKAGE_NAME = "p.p"; - - private static final Logger LOG = LogManager.getLogger(CheckCatalogWizardTest.class); - - private SwtWizardBot wizard; - private static IProject project; - - @Inject - private Provider projectFactoryProvider; - - /** - * Creates a project. - * - * @return a created project - */ - private IProject createProject() { - final PluginProjectFactory factory = projectFactoryProvider.get(); - factory.setProjectName("project.name"); - - factory.addFolders(Collections.singletonList(SRC_FOLDER)); - factory.addBuilderIds(JavaCore.BUILDER_ID); - factory.addProjectNatures(JavaCore.NATURE_ID); - - final IProject[] result = new IProject[1]; - WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { - - @Override - protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { - result[0] = factory.createProject(monitor, null); - IJavaProject javaProject = JavaCore.create(result[0]); - IFolder sourceFolder = result[0].getFolder(SRC_FOLDER); - IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(sourceFolder); - try { - root.createPackageFragment(VALID_PACKAGE_NAME, false, null); - } catch (JavaModelException e) { - LOG.error("create package" + e.getMessage()); - } - } - }; - try { - operation.run(new NullProgressMonitor()); - } catch (InvocationTargetException e) { - return null; - } catch (InterruptedException e) { - return null; - } - return result[0]; - } - - /** - * Start again the Check project wizard before every test. - *

- * Initializes this test class pre-loading grammar access instances, which might involve bundle activation and class loading. - *

- */ - @BeforeEach - public void setUp() { - wizard = new SwtWizardBot(); - project = createProject(); - for (Grammar g : new CheckResourceUtil().getGrammars()) { // make sure all grammars accessible for combo field. - g.getName(); - } - } - - /** - * Initializes the wizard bot for creating a new check catalog. - */ - private void initializeWizardBot() { - wizard.openNewWizard(CHECK_CATALOG); - wizard.waitUntilWizardPageAppears(CHECK_CATALOG); - } - - /** - * Test if the package field contains the selected package. - */ - @Test - public void testPackageSelected() { - selectProjectFolder(wizard, VALID_PACKAGE_NAME); - initializeWizardBot(); - // because the selected item is a package initially, this package is shown in the field. - assertEquals(VALID_PACKAGE_NAME, wizard.textWithLabel(Messages.PACKAGE_NAME_LABEL).getText(), "Initial package is entered"); - } - - /** - * Test if catalog wizard is enabled if a project folder is selected. - */ - @Test - public void testCheckCatalogWizardIsEnabled() { - selectProjectFolder(wizard, VALID_PACKAGE_NAME); - // open the check catalog wizard after having selected the project source folder. - // that way, the wizard page should be enabled. - initializeWizardBot(); - - assertEquals(Messages.CATALOG_WIZARD_WINDOW_TITLE, wizard.activeShell().getText(), "new check catalog page was loaded"); - wizard.waitUntil(Conditions.widgetIsEnabled(wizard.textWithLabel(Messages.CATALOG_FIELD_NAME_LABEL)), SwtWizardBot.SWTBOT_TIMEOUT); - wizard.waitUntil(Conditions.widgetIsEnabled(wizard.textWithLabel(Messages.PACKAGE_NAME_LABEL)), SwtWizardBot.SWTBOT_TIMEOUT); - CheckWizardTestUtil.assertButtonsEnabled(false, true, false, wizard); - } - - /** - * Test if the package field is empty, if the selected item is no package. - */ - @Test - public void testInitiallyNoPackageSelected() { - selectProjectFolder(wizard, SRC_FOLDER); - initializeWizardBot(); - - // because the selected item is not a package initially, the field has to be empty. - assertSame(wizard.textWithLabel(Messages.PACKAGE_NAME_LABEL).getText().length(), 0, "Initially, no package is selected"); - } - - /** - * Test if the next and finish button are disabled if the package name is invalid. - */ - @Test - public void testPackageNameInvalid() { - selectProjectFolder(wizard, VALID_PACKAGE_NAME); - // open the check catalog wizard after having selected the project source folder. - initializeWizardBot(); - - CheckWizardTestUtil.packageName(wizard, ".package.name", CheckWizardTestUtil.FINISH_DISABLED); - CheckWizardTestUtil.packageName(wizard, "Package.name", CheckWizardTestUtil.FINISH_DISABLED); - CheckWizardTestUtil.packageName(wizard, "packageName", CheckWizardTestUtil.FINISH_DISABLED); - CheckWizardTestUtil.packageName(wizard, "package. name", CheckWizardTestUtil.FINISH_DISABLED); - CheckWizardTestUtil.packageName(wizard, "package..name", CheckWizardTestUtil.FINISH_DISABLED); - } - - /** - * Test if the finish button is enabled if the package name is valid. - */ - @Test - public void testPackageNameValid() { - selectProjectFolder(wizard, VALID_PACKAGE_NAME); - // open the check catalog wizard after having selected the project source folder. - initializeWizardBot(); - - CheckWizardTestUtil.packageName(wizard, "mypackage", CheckWizardTestUtil.FINISH_ENABLED); - CheckWizardTestUtil.packageName(wizard, "my.package", CheckWizardTestUtil.FINISH_ENABLED); - } - - /** - * Test if the next and finish button are disabled if the catalog name is invalid. - */ - @Test - public void testCatalogNameInvalid() { - selectProjectFolder(wizard, VALID_PACKAGE_NAME); - // open the check catalog wizard after having selected the project source folder. - initializeWizardBot(); - - CheckWizardTestUtil.catalogName(wizard, "catalogname.", CheckWizardTestUtil.FINISH_DISABLED); - CheckWizardTestUtil.catalogName(wizard, "catalog*name", CheckWizardTestUtil.FINISH_DISABLED); - CheckWizardTestUtil.catalogName(wizard, ",catalogname", CheckWizardTestUtil.FINISH_DISABLED); - } - - /** - * Tests that discouraged catalog names are accepted. - */ - @Test - public void testCatalogNameDiscouraged() { - selectProjectFolder(wizard, VALID_PACKAGE_NAME); - initializeWizardBot(); - - // TODO the finish button is enabled, but also test that a warning status is shown - CheckWizardTestUtil.catalogName(wizard, "lowerCase", CheckWizardTestUtil.FINISH_ENABLED); - CheckWizardTestUtil.catalogName(wizard, "lowercase", CheckWizardTestUtil.FINISH_ENABLED); - } - - /** - * Tests valid catalog names. - */ - @Test - public void testCatalogName() { - selectProjectFolder(wizard, VALID_PACKAGE_NAME); - initializeWizardBot(); - - // TODO the finish button is enabled, but also test that NO warning status is shown - CheckWizardTestUtil.catalogName(wizard, "UpperCase", CheckWizardTestUtil.FINISH_ENABLED); - CheckWizardTestUtil.catalogName(wizard, "Uppercase", CheckWizardTestUtil.FINISH_ENABLED); - } - - /** - * Tests that initially no grammar is selected, so pressing finish is disabled if no grammar is chosen. - */ - @BugTest("AIG-708") - public void testInitiallyNoGrammarSelected() { - selectProjectFolder(wizard, VALID_PACKAGE_NAME); - initializeWizardBot(); - - CheckWizardTestUtil.grammarName(wizard, SwtWizardBot.UNDEFINED_COMBO_BOX_INDEX, CheckWizardTestUtil.FINISH_DISABLED); - } - - /** - * Close the wizard after every test. - * - * @throws CoreException - * if project doesn't exist. - */ - @AfterEach - public void tearDown() throws CoreException { - wizard.closeWizard(); - project.delete(true, new NullProgressMonitor()); - } - -} diff --git a/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckProjectWizardTest.java b/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckProjectWizardTest.java deleted file mode 100644 index 71323ec6d3..0000000000 --- a/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckProjectWizardTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNotSame; - -import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; -import org.eclipse.xtext.testing.InjectWith; -import org.eclipse.xtext.testing.extensions.InjectionExtension; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import com.avaloq.tools.ddk.check.ui.test.internal.CheckWizardUiTestInjectorProvider; -import com.avaloq.tools.ddk.check.ui.test.util.CheckWizardTestUtil; -import com.avaloq.tools.ddk.check.ui.wizard.Messages; -import com.avaloq.tools.ddk.test.core.jupiter.BugTest; -import com.avaloq.tools.ddk.test.ui.swtbot.SwtWizardBot; - - -/** - * The CheckProjectWizardTest tests the Check Project Wizard. - */ -@InjectWith(CheckWizardUiTestInjectorProvider.class) -@ExtendWith(InjectionExtension.class) -@SuppressWarnings("nls") -public class CheckProjectWizardTest { - - /** This is the name of the project wizard. It's the name SWTBot uses to look up the wizard. */ - private static final String CHECK_PROJECT_WIZARD_NAME = "Check Project"; - - /** input strings for wizard testing. */ - private static final String CORRECT_PROJECT_NAME = "p.n"; - - private SwtWizardBot wizard; - - /** - * Start again the Check project wizard before every test. - */ - @BeforeEach - public void setUp() { - wizard = new SwtWizardBot(); - wizard.openNewWizard(CHECK_PROJECT_WIZARD_NAME); - } - - /** - * Check if the project wizard is available. - */ - @Test - public void testCheckProjectWizardIsAvailable() { - assertNotNull(wizard, "the project wizard was found"); - CheckWizardTestUtil.assertButtonsEnabled(false, true, false, wizard); - } - - /** - * Test if the buttons 'next', 'back' and 'finish' are correctly enabled/disabled. - */ - @Test - public void testProjectNameInvalid() { - CheckWizardTestUtil.projectName(wizard, "", CheckWizardTestUtil.NEXT_DISABLED); - CheckWizardTestUtil.projectName(wizard, ".project.name", CheckWizardTestUtil.NEXT_DISABLED); - CheckWizardTestUtil.projectName(wizard, "Project.name", CheckWizardTestUtil.NEXT_DISABLED); - CheckWizardTestUtil.projectName(wizard, "projectName", CheckWizardTestUtil.NEXT_DISABLED); - CheckWizardTestUtil.projectName(wizard, "project. name", CheckWizardTestUtil.NEXT_DISABLED); - CheckWizardTestUtil.projectName(wizard, "project..name", CheckWizardTestUtil.NEXT_DISABLED); - } - - /** - * Tests that the 'finish' button is not enabled in the project page. - */ - @BugTest("AIG-490") - public void testFinishButtonDisabledInProjectPage() { - CheckWizardTestUtil.projectName(wizard, "valid.project.name", CheckWizardTestUtil.NEXT_ENABLED, CheckWizardTestUtil.FINISH_DISABLED); - } - - /** - * Test if the buttons 'next', 'back' and 'finish' are correctly enabled/disabled. - */ - @Test - public void testProjectNameValid() { - CheckWizardTestUtil.projectName(wizard, "project.name", CheckWizardTestUtil.NEXT_ENABLED); - CheckWizardTestUtil.projectName(wizard, "projectname", CheckWizardTestUtil.NEXT_ENABLED); - } - - /** - * Test if the buttons 'next', 'back' and 'finish' are correctly enabled/disabled. - */ - @Test - public void fieldValuesAfterPageChange() { - wizard.writeToTextField(Messages.PROJECT_NAME_LABEL, CORRECT_PROJECT_NAME); - wizard.changeToPreviousPage(); - wizard.changeToNextPage(); - assertEquals(CORRECT_PROJECT_NAME, wizard.textWithLabel(Messages.PROJECT_NAME_LABEL).getText(), "Project input stays unchanged"); - wizard.changeToNextPage(); - assertEquals(CORRECT_PROJECT_NAME, wizard.textWithLabel(Messages.PACKAGE_NAME_LABEL).getText(), "Initially, package name equals to project name"); - } - - /** - * Tests that applying the next button changes the wizard page. - */ - @BugTest("AIG-479") - public void testNextButtonChangesPage() { - wizard.writeToTextField(Messages.PROJECT_NAME_LABEL, "a.b"); - SWTBotShell projectPage = wizard.shell(Messages.PROJECT_WIZARD_WINDOW_TITLE); - wizard.changeToNextPage(); - SWTBotShell catalogPage = wizard.shell(Messages.PROJECT_WIZARD_WINDOW_TITLE); - assertNotSame(projectPage, catalogPage, "Next button changed page"); - } - - /** - * Close the wizard after every test. - */ - @AfterEach - public void tearDown() { - wizard.closeWizard(); - } - -} diff --git a/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckUiTestSuite.java b/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckUiTestSuite.java index de6a8964e6..d51dda6646 100644 --- a/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckUiTestSuite.java +++ b/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/CheckUiTestSuite.java @@ -27,8 +27,6 @@ @Suite @SelectClasses({ CheckQuickfixTest.class, - CheckProjectWizardTest.class, - CheckCatalogWizardTest.class, CheckMarkerHelpExtensionTest.class, CheckContextsExtensionTest.class, CheckTocExtensionTest.class, diff --git a/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/util/CheckWizardTestUtil.java b/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/util/CheckWizardTestUtil.java deleted file mode 100644 index e98cb010b0..0000000000 --- a/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/util/CheckWizardTestUtil.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.test.util; - -import static com.avaloq.tools.ddk.test.ui.swtbot.SwtWizardBot.BACK; -import static com.avaloq.tools.ddk.test.ui.swtbot.SwtWizardBot.FINISH; -import static com.avaloq.tools.ddk.test.ui.swtbot.SwtWizardBot.NEXT; -import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swtbot.eclipse.finder.waits.Conditions; -import org.eclipse.swtbot.swt.finder.results.BoolResult; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; - -import com.avaloq.tools.ddk.check.ui.wizard.Messages; -import com.avaloq.tools.ddk.test.ui.swtbot.SwtWizardBot; - - -/** - * Util class for the Check project and Check catalog wizard tests. - */ -@SuppressWarnings("nls") -public final class CheckWizardTestUtil { - - // Next button disabled - public static final boolean NEXT_DISABLED = false; - // Next button enabled - public static final boolean NEXT_ENABLED = true; - // Back button enabled - public static final boolean BACK_ENABLED = true; - // Finish button disabled - public static final boolean FINISH_DISABLED = false; - // Finish button enabled - public static final boolean FINISH_ENABLED = true; - - /** input strings for wizard testing. */ - private static final String VALID_CATALOG_NAME = "Cc"; - private static final String VALID_PACKAGE_NAME = "p.p"; - - private CheckWizardTestUtil() { - // Prevent class from being instantiated. - } - - /** - * Assert buttons are correctly enabled. - * - * @param nextIsEnabled - * is next button enabled - * @param backIsEnabled - * is the back button enabled - * @param finishIsEnabled - * is the finish button enabled - * @param swtWizardBot - * the wizard - */ - public static void assertButtonsEnabled(final boolean nextIsEnabled, final boolean backIsEnabled, final boolean finishIsEnabled, final SwtWizardBot swtWizardBot) { - if (nextIsEnabled) { - assertTrue(swtWizardBot.button(NEXT).isEnabled(), "Next button is enabled"); - } else { - assertFalse(swtWizardBot.button(NEXT).isEnabled(), "Next button is disabled"); - } - if (backIsEnabled) { - assertTrue(swtWizardBot.button(BACK).isEnabled(), "Back button is enabled"); - } else { - assertFalse(swtWizardBot.button(BACK).isEnabled(), "Back button is disabled"); - } - if (finishIsEnabled) { - assertTrue(swtWizardBot.button(FINISH).isEnabled(), "Finish button is enabled"); - } else { - assertFalse(swtWizardBot.button(FINISH).isEnabled(), "Finish button is disabled"); - } - } - - /** - * Test if the buttons 'next', 'back' and 'finish' are correctly enabled/disabled depending on given project name. - * - * @param wizard - * the wizard - * @param projectName - * the project name - * @param nextButtonAssertion - * assertion about the 'next' button: {@code true} if expected to be enabled, else {@code false} - */ - public static void projectName(final SwtWizardBot wizard, final String projectName, final Boolean nextButtonAssertion) { - wizard.writeToTextField(Messages.PROJECT_NAME_LABEL, projectName); - CheckWizardTestUtil.assertButtonsEnabled(nextButtonAssertion, BACK_ENABLED, FINISH_DISABLED, wizard); - } - - /** - * Test if the buttons 'next', 'back' and 'finish' are correctly enabled/disabled depending on given project name. - * - * @param wizard - * the wizard - * @param projectName - * the project name - * @param nextButtonAssertion - * assertion about the 'next' button: {@code true} if expected to be enabled, else {@code false} - * @param finishButtonAssertion - * assertion about the 'next' button: {@code true} if expected to be enabled, else {@code false} - */ - public static void projectName(final SwtWizardBot wizard, final String projectName, final Boolean nextButtonAssertion, final Boolean finishButtonAssertion) { - wizard.writeToTextField(Messages.PROJECT_NAME_LABEL, projectName); - CheckWizardTestUtil.assertButtonsEnabled(nextButtonAssertion, BACK_ENABLED, finishButtonAssertion, wizard); - } - - /** - * Test if the finish button is enabled if the package name is valid. - * - * @param wizard - * the wizard - * @param packageName - * the package name - * @param finishButtonAssertion - * boolean value indicating whether the finish button is expected to be enabled ({@code true}) or not ({@code false}) - */ - public static void packageName(final SwtWizardBot wizard, final String packageName, final Boolean finishButtonAssertion) { - waitForGrammarFieldEnabled(wizard); - wizard.selectInComboBox(Messages.GRAMMAR_FIELD_NAME_LABEL, 0); - wizard.writeToTextField(Messages.CATALOG_FIELD_NAME_LABEL, VALID_CATALOG_NAME); - wizard.writeToTextField(Messages.PACKAGE_NAME_LABEL, packageName); - - assertButtonsEnabled(NEXT_DISABLED, BACK_ENABLED, finishButtonAssertion, wizard); - } - - /** - * Test if the finish button is enabled if the catalog name is deprecated. - * - * @param wizard - * the wizard - * @param catalogName - * the catalog name - * @param finishButtonAssertion - * boolean value indicating whether the finish button is expected to be enabled ({@code true}) or not ({@code false}) - */ - public static void catalogName(final SwtWizardBot wizard, final String catalogName, final Boolean finishButtonAssertion) { - waitForGrammarFieldEnabled(wizard); - wizard.selectInComboBox(Messages.GRAMMAR_FIELD_NAME_LABEL, 0); - wizard.writeToTextField(Messages.PACKAGE_NAME_LABEL, VALID_PACKAGE_NAME); - wizard.writeToTextField(Messages.CATALOG_FIELD_NAME_LABEL, catalogName); - - assertButtonsEnabled(NEXT_DISABLED, BACK_ENABLED, finishButtonAssertion, wizard); - } - - /** - * Sets the grammar to the combo box entry at given index. Sets valid package and catalog names. - * - * @param wizard - * the wizard - * @param grammarIndex - * the grammar index - * @param finishButtonAssertion - * boolean value indicating whether the finish button is expected to be enabled ({@code true}) or not ({@code false}) - */ - public static void grammarName(final SwtWizardBot wizard, final int grammarIndex, final Boolean finishButtonAssertion) { - waitForGrammarFieldEnabled(wizard); - wizard.selectInComboBox(Messages.GRAMMAR_FIELD_NAME_LABEL, grammarIndex); - wizard.writeToTextField(Messages.PACKAGE_NAME_LABEL, VALID_PACKAGE_NAME); - wizard.writeToTextField(Messages.CATALOG_FIELD_NAME_LABEL, VALID_CATALOG_NAME); - - assertButtonsEnabled(NEXT_DISABLED, BACK_ENABLED, finishButtonAssertion, wizard); - } - - /** - * Waits until the grammar field combo box is enabled. - * - * @param wizard - * the wizard - */ - public static void waitForGrammarFieldEnabled(final SwtWizardBot wizard) { - boolean wizardIsActive = syncExec(new BoolResult() { - @Override - public Boolean run() { - SWTBotShell wizardShell = wizard.activeShell(); - return wizardShell.widget.getData() instanceof WizardDialog; - } - }); - assertTrue(wizardIsActive, "Wizard is active before waiting on grammar field"); - wizard.waitUntil(Conditions.widgetIsEnabled(wizard.comboBoxWithLabel(Messages.GRAMMAR_FIELD_NAME_LABEL)), 2 * SwtWizardBot.SWTBOT_TIMEOUT); - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF index 28587340b5..0f8287fa2f 100644 --- a/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF @@ -37,7 +37,6 @@ Export-Package: com.avaloq.tools.ddk.check.ui;x-friends:="com.avaloq.tools.ddk.c com.avaloq.tools.ddk.check.ui.contentassist, com.avaloq.tools.ddk.check.ui.internal;x-friends:="com.avaloq.tools.ddk.check.ui.test", com.avaloq.tools.ddk.check.ui.util, - com.avaloq.tools.ddk.check.ui.wizard, com.avaloq.tools.ddk.check.ui.quickfix, com.avaloq.tools.ddk.check.ui.editor Import-Package: org.apache.log4j, diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/CheckUiModule.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/CheckUiModule.java index 52070c53ed..7a02766757 100644 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/CheckUiModule.java +++ b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/CheckUiModule.java @@ -24,7 +24,6 @@ import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration; import org.eclipse.xtext.ui.editor.templates.CrossReferenceTemplateVariableResolver; import org.eclipse.xtext.ui.editor.templates.XtextTemplateContextType; -import org.eclipse.xtext.ui.wizard.IProjectCreator; import org.eclipse.xtext.xbase.compiler.GeneratorConfigProvider; import org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider; @@ -42,9 +41,6 @@ import com.avaloq.tools.ddk.check.ui.navigation.CheckHyperlinkHelper; import com.avaloq.tools.ddk.check.ui.templates.CheckTemplateContextType; import com.avaloq.tools.ddk.check.ui.templates.CheckTemplateProposalProvider; -import com.avaloq.tools.ddk.check.ui.wizard.CheckCatalogCreator; -import com.avaloq.tools.ddk.check.ui.wizard.CheckProjectCreator; -import com.avaloq.tools.ddk.check.ui.wizard.ICheckCatalogCreator; import com.avaloq.tools.ddk.xtext.common.types.ui.access.jdt.JdtFallbackTypeProviderFactory; import com.avaloq.tools.ddk.xtext.ui.editor.FixedDirtyStateEditorSupport; import com.avaloq.tools.ddk.xtext.ui.templates.KeywordAwareCrossReferenceTemplateVariableResolver; @@ -59,24 +55,6 @@ public CheckUiModule(final AbstractUIPlugin plugin) { super(plugin); } - /** - * Binds a project creator. Used for the wizards. - * - * @return project creator - */ - public Class bindIProjectCreator() { - return CheckProjectCreator.class; - } - - /** - * Bind ICheckCatalogCreator. - * - * @return CheckCatalogCreator.class which creates a new Check catalog in an existing Check plugin project - */ - public Class bindICheckCatalogCreator() { - return CheckCatalogCreator.class; - } - @Override public Class bindXtextTemplateContextType() { return CheckTemplateContextType.class; diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckCatalogCreator.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckCatalogCreator.java deleted file mode 100644 index e659b0fe22..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckCatalogCreator.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.ui.actions.WorkspaceModifyOperation; -import org.eclipse.xtext.ui.wizard.IProjectInfo; - -import com.avaloq.tools.ddk.check.CheckConstants; -import com.google.inject.Inject; - - -/** - * The Class CheckCatalogCreator creates a new Check catalog in an existing Check plugin project. - */ -@SuppressWarnings("nls") -public class CheckCatalogCreator extends WorkspaceModifyOperation implements ICheckCatalogCreator { - - /** The result. */ - private IFile result; - - /** The project info. */ - private CheckProjectInfo projectInfo; - - /** The generator util. */ - @Inject - private CheckCatalogGenerator generatorUtil; - - @Override - public IFile getResult() { - return result; - } - - /** - * Sets the result. - * - * @param result - * the new result - */ - public void setResult(final IFile result) { - this.result = result; - } - - @Override - public void setProjectInfo(final IProjectInfo projectInfo) { - this.projectInfo = (CheckProjectInfo) projectInfo; - } - - /** - * Gets the project info. - * - * @return the project info - */ - public CheckProjectInfo getProjectInfo() { - return this.projectInfo; - } - - @Override - protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { - SubMonitor subMonitor = SubMonitor.convert(monitor, "create new Catalog:" + getProjectInfo().getCatalogName(), 2); - - IFolder outputFolder = (IFolder) getProjectInfo().getPackageFragment().getResource(); - IProject project = outputFolder.getProject(); - IPath path = project.getLocation().makeAbsolute(); - try { - generatorUtil.generateCheckFile(path, getProjectInfo()); - generatorUtil.generateDefaultQuickfixProvider(path, getProjectInfo()); - project.refreshLocal(IResource.DEPTH_INFINITE, monitor); - } finally { - setResult(outputFolder.getFile(getProjectInfo().getCatalogName() + '.' + CheckConstants.FILE_EXTENSION)); - subMonitor.done(); - } - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckCatalogGenerator.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckCatalogGenerator.java deleted file mode 100644 index 3e0486f593..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckCatalogGenerator.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.xtext.generator.JavaIoFileSystemAccess; - -import com.avaloq.tools.ddk.check.generator.CheckOutputConfigurationProvider; -import com.google.inject.Inject; -import com.google.inject.Singleton; - - -/** - * The Class CheckFileGeneratorUtil. - */ -@Singleton -public class CheckCatalogGenerator { - - @Inject - private CheckQuickfixProvider quickfixProvider; - - @Inject - private CheckNewProject newProject; - - @Inject - private JavaIoFileSystemAccess fsa; - - /** - * Generates a check file. - * - * @param path - * the path used for the output file destination - * @param projectInfo - * the project info - */ - public void generateCheckFile(final IPath path, final CheckProjectInfo projectInfo) { - fsa.setOutputPath(path.toOSString()); - newProject.doGenerate(projectInfo, fsa); - } - - /** - * Generates a default quickfix provider. - * - * @param path - * the path - * @param projectInfo - * the project info - */ - public void generateDefaultQuickfixProvider(final IPath path, final CheckProjectInfo projectInfo) { - fsa.setOutputPath(path.toOSString()); - quickfixProvider.doGenerate(projectInfo, fsa); - } - - /** - * Generates the docs directory. - * - * @param path - * the path - * @param projectInfo - * the project info - */ - @SuppressWarnings({"nls", "PMD.UnusedFormalParameter"}) - public void generateDocsDirectory(final IPath path, final CheckProjectInfo projectInfo) { - fsa.setOutputPath(path.toOSString()); - // IFileSystemAccess doesn't support creating empty directories, so: - String dummyFile = CheckOutputConfigurationProvider.DOCS_PATH + "/dummy.dumb"; - fsa.generateFile(dummyFile, "delete me"); - fsa.deleteFile(dummyFile); - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckNewProject.xtend b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckNewProject.xtend deleted file mode 100644 index 4b7fa3180b..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckNewProject.xtend +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard - -import org.eclipse.xtext.generator.IFileSystemAccess - -class CheckNewProject { - - def doGenerate(CheckProjectInfo info, IFileSystemAccess fsa){ - fsa.generateFile(info.fileName, info.fileContent) - } - - def String fileName(CheckProjectInfo info){ - '''«info.path + info.catalogName + ".check"»''' - } - - def fileContent(CheckProjectInfo info){ - ''' - package «info.packageName» - - «info.fileImports» - - /** - * Check catalog for «info.grammar.name» - */ - catalog «info.catalogName» - for grammar «info.grammar.name» { - - // Add categories and checks - - } - ''' - } - - def fileImports(CheckProjectInfo info) { - // package where top-level grammar rule interfaces are defined - if(info.defaultPackageImport !== null) - '''import «info.defaultPackageImport».* ''' - else "" - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectCreator.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectCreator.java deleted file mode 100644 index a07d178b78..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectCreator.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard; - -import java.util.List; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.xtext.ui.util.ProjectFactory; -import org.eclipse.xtext.ui.wizard.AbstractPluginProjectCreator; - -import com.avaloq.tools.ddk.check.ui.internal.CheckNature; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.google.inject.Inject; -import com.google.inject.Provider; - - -/** - * The Class creates a new check plugin project. - */ -@SuppressWarnings("nls") -public class CheckProjectCreator extends AbstractPluginProjectCreator { // extends CheckProjectCreator - - protected static final String SRC_ROOT = "src"; - private static final String SRC_GEN_ROOT = "src-gen"; - private static final String XTEND_GEN = "xtend-gen"; //$NON-NLS-1$ - private static final List SRC_FOLDER_LIST = ImmutableList.of(SRC_ROOT, SRC_GEN_ROOT, XTEND_GEN); - - @Inject - private Provider projectFactoryProvider; - - @Inject - private CheckCatalogGenerator generatorUtil; - - @Override - protected CheckProjectFactory createProjectFactory() { - return projectFactoryProvider.get(); - } - - @Override - protected ProjectFactory configureProjectFactory(final ProjectFactory factory) { - ProjectFactory result = super.configureProjectFactory(factory); - result.addProjectNatures(CheckNature.CHECK_NATURE_ID); - return result; - } - - @Override - protected CheckProjectInfo getProjectInfo() { - return (CheckProjectInfo) super.getProjectInfo(); - } - - /** Default set of required bundles. */ - private final List requiredBundles = Lists.newArrayList("org.eclipse.emf.ecore", // EStructuralFeature scoping requires this - "org.eclipse.xtext", // required for code generation - "com.avaloq.tools.ddk.check.runtime.core", // Check runtime - "com.avaloq.tools.ddk.check.lib", // Check user library - "com.avaloq.tools.targetdefinition.check.core;resolution:=optional", // Check configuration preferences, TODO should only be added for ASMD - "org.eclipse.core.runtime", // - "org.eclipse.xtend.lib", // required for CheckGenerator operations, e.g. 'StringConcatenation()' - "org.eclipse.xtext.xbase.lib", // required for Xbase operations, e.g. '==' - "com.avaloq.tools.dsl.check.lib;resolution:=optional" // utility operations (ASMD specific) - ); - - /** - * Uses the generator utility to generate the initial Check model to ensure that it is generated - * the same way as using the file wizard. {@inheritDoc}
- * Furthermore, it generates a default quickfix provider and a .css stylesheet which formats the content - * of ice help for Check. - */ - @Override - protected void enhanceProject(final IProject project, final IProgressMonitor monitor) throws CoreException { - IPath projectPath = project.getLocation().makeAbsolute(); - generatorUtil.generateCheckFile(projectPath, getProjectInfo()); - generatorUtil.generateDefaultQuickfixProvider(projectPath, getProjectInfo()); - // Create the docs directory to avoid the check compiler from creating it as a source folder later. This would prevent help from accessing the files. - generatorUtil.generateDocsDirectory(projectPath, getProjectInfo()); - project.refreshLocal(IResource.DEPTH_INFINITE, monitor); - } - - @Override - protected List getAllFolders() { - return SRC_FOLDER_LIST; - } - - @Override - protected List getRequiredBundles() { - Set bundles = Sets.newLinkedHashSet(requiredBundles); - bundles.addAll(getProjectInfo().getDslDependency()); - return Lists.newArrayList(bundles); - } - - /** - * @return the names of the exported packages. May not be null - */ - @Override - protected List getExportedPackages() { - CheckProjectInfo projectInfo = getProjectInfo(); - return Lists.newArrayList(projectInfo.getPackageName()); - } - - @Override - protected String getModelFolderName() { - return SRC_ROOT; - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectFactory.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectFactory.java deleted file mode 100644 index 5325583f85..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectFactory.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard; - -import java.util.Iterator; - -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.xtext.ui.util.PluginProjectFactory; - - -/** - * A factory for creating CustomCheckProject objects. - */ -// CHECKSTYLE:OFF -@SuppressWarnings("nls") -public class CheckProjectFactory extends PluginProjectFactory { - // CHECKSTYLE:ON - - @Override - protected void enhanceProject(final IProject project, final SubMonitor subMonitor, final Shell shell) throws CoreException { - super.enhanceProject(project, subMonitor, shell); - createPluginXML(project, subMonitor.newChild(1)); - } - - /** - * Creates the initial {@code plugin.xml} file. Note that the file created is empty, actual contents - * for Catalogs are created by the builder participant. - * - * @param project - * the project - * @param monitor - * the monitor - * @throws CoreException - * the core exception - */ - @SuppressWarnings("PMD.InsufficientStringBufferDeclaration") - private void createPluginXML(final IProject project, final IProgressMonitor monitor) throws CoreException { - final StringBuilder content = new StringBuilder("\n\n"); - content.append("\n\n"); - - SubMonitor subMonitor = SubMonitor.convert(monitor, 2); - try { - createFile("plugin.xml", project, content.toString(), subMonitor.newChild(1)); - } finally { - subMonitor.done(); - } - } - - @Override - @SuppressWarnings("PMD.InsufficientStringBufferDeclaration") - protected void createBuildProperties(final IProject project, final IProgressMonitor progressMonitor) { - final StringBuilder content = new StringBuilder("source.. = "); - for (final Iterator iterator = folders.iterator(); iterator.hasNext();) { - content.append(iterator.next()).append('/'); - if (iterator.hasNext()) { - content.append(",\\\n"); - // source.. = - content.append(" "); - } - } - content.append('\n'); - content.append("bin.includes = META-INF/,\\\n"); - content.append(" .,\\\n"); - content.append(" plugin.xml,\\\n"); - content.append(" docs/"); - - createFile("build.properties", project, content.toString(), progressMonitor); - } - - /** - * Overridden in order to change BundleVendor. {@inheritDoc} - */ - @SuppressWarnings("PMD.InsufficientStringBufferDeclaration") - @Override - protected void createManifest(final IProject project, final IProgressMonitor progressMonitor) throws CoreException { - String newLine = "\n"; - final StringBuilder content = new StringBuilder("Manifest-Version: 1.0").append(newLine); - content.append("Bundle-ManifestVersion: 2").append(newLine); - content.append("Bundle-Name: ").append(projectName).append(newLine); - content.append("Bundle-Vendor: %Bundle-Vendor").append(newLine); - content.append("Bundle-Version: 1.0.0.qualifier").append(newLine); - content.append("Bundle-SymbolicName: ").append(projectName).append(";singleton:=true").append(newLine); - if (null != activatorClassName) { - content.append("Bundle-Activator: ").append(activatorClassName).append(newLine); - } - content.append("Bundle-ActivationPolicy: lazy").append(newLine); - - addToContent(content, requiredBundles, "Require-Bundle"); - addToContent(content, exportedPackages, "Export-Package"); - addToContent(content, importedPackages, "Import-Package"); - - content.append("Bundle-RequiredExecutionEnvironment: JavaSE-1.7").append(newLine); - - final IFolder metaInf = project.getFolder("META-INF"); - SubMonitor subMonitor = SubMonitor.convert(progressMonitor, 2); - try { - if (metaInf.exists()) { - metaInf.delete(false, progressMonitor); - } - metaInf.create(false, true, subMonitor.newChild(1)); - createFile("MANIFEST.MF", metaInf, content.toString(), subMonitor.newChild(1)); - } finally { - subMonitor.done(); - } - } -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectInfo.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectInfo.java deleted file mode 100644 index 953b921bc6..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckProjectInfo.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard; - -import java.util.Collection; - -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.xtext.AbstractMetamodelDeclaration; -import org.eclipse.xtext.GeneratedMetamodel; -import org.eclipse.xtext.Grammar; -import org.eclipse.xtext.ui.wizard.DefaultProjectInfo; - -import com.avaloq.tools.ddk.check.util.GrammarHelper; -import com.google.common.base.Predicates; -import com.google.common.collect.Collections2; -import com.google.common.collect.Iterables; - - -/** - * Aggregates project information collected from UI. - */ -@SuppressWarnings("nls") -public class CheckProjectInfo extends DefaultProjectInfo { - - private String catalogName; - private String path; - private String packageName; - private Grammar grammar; - private GrammarHelper grammarHelper; - private IPackageFragment packageFragment; - - public String getCatalogName() { - return catalogName; - } - - public void setCatalogName(final String catalogName) { - this.catalogName = catalogName; - } - - /** - * Sets the grammar to use for this project and creates the corresponding helper. - * - * @param projectGrammar - * the grammar to use for this project - */ - public void setGrammar(final Grammar projectGrammar) { - this.grammar = projectGrammar; - this.grammarHelper = new GrammarHelper(projectGrammar); - } - - public Grammar getGrammar() { - return grammar; - } - - public Collection getDslDependency() { - return grammarHelper.getRequiredBundleSymbolicNames(); - } - - /** - * Gets the default package import. Returns the package name of the Java package in which the interface - * of the grammar's top-level grammar rule is located. - *

- * A typical location for this would be {@code org.xtext.example.mydsl.myDsl} - *

- * - * @return the default package import or {@code null} if no default package was found - */ - public String getDefaultPackageImport() { - AbstractMetamodelDeclaration defaultDeclaration = grammar.getRules().isEmpty() ? null : grammar.getRules().get(0).getType().getMetamodel(); // NOPMD - AbstractMetamodelDeclaration declaration = Iterables.find(grammar.getMetamodelDeclarations(), Predicates.instanceOf(GeneratedMetamodel.class), defaultDeclaration); - if (declaration != null) { - return grammarHelper.getFirstInterface(declaration).getPackage().getName(); - } - return null; - } - - /** - * Gets the path to where files should be generated. If {@code path} is {@code null}, a default is calculated. - * - * @return the path - */ - public String getPath() { - if (this.path == null) { - return "src" + "/" + this.packageName.replace('.', '/') + "/"; - } - return this.path; - } - - public void setPath(final String path) { - this.path = path; - } - - public String getPackageName() { - return packageName; - } - - public void setPackageName(final String packageName) { - this.packageName = packageName; - } - - public IPackageFragment getPackageFragment() { - return packageFragment; - } - - public void setPackageFragment(final IPackageFragment packageFragment) { - this.packageFragment = packageFragment; - } - - public Collection getMetamodelImports() { - return Collections2.transform(grammarHelper.getMetamodelPackages(), importPackageName -> importPackageName + ".*"); - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckQuickfixProvider.xtend b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckQuickfixProvider.xtend deleted file mode 100644 index 665917b4a1..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/CheckQuickfixProvider.xtend +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard - -import org.eclipse.xtext.generator.IFileSystemAccess - -class CheckQuickfixProvider { - - def doGenerate(CheckProjectInfo info, IFileSystemAccess fsa){ - fsa.generateFile(info.fileName, info.fileContent) - } - - def String fileName(CheckProjectInfo info){ - '''«info.path + info.catalogName + "QuickfixProvider.java"»''' - } - - def fileContent(CheckProjectInfo info){ - ''' - package «info.packageName»; - - import com.avaloq.tools.ddk.check.runtime.quickfix.ICoreQuickfixProvider; - - /** - * Default quickfix provider for «info.catalogName». - *

- * Note that this class name must start with the catalog name and have QuickfixProvider - * as suffix. It must be located in the same Java package as the catalog file. - *

- */ - public class «info.catalogName»QuickfixProvider implements ICoreQuickfixProvider { - - // @CoreFix(value = MyIssueCodes.NAME_ENTITY_0) - // public void fixEntityNameFirstUpper(final Issue issue, - // ICoreIssueResolutionAcceptor acceptor) { - // acceptor.accept(issue, "Correct entity name", - // "Correct name by setting first letter to upper case.", - // null, new ICoreSemanticModification() { - // public void apply(EObject element, ICoreModificationContext context) { - // if (element instanceof Entity) { - // final Entity entity = (Entity) element; - // String newName = String.valueOf(entity.getName().charAt(0)).toUpperCase(); - // if (entity.getName().length() > 1) { - // newName += entity.getName().substring(1, entity.getName().length()); - // } - // entity.setName(newName); - // } - // } - // }); - // } - - } - ''' - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/ICheckCatalogCreator.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/ICheckCatalogCreator.java deleted file mode 100644 index bbd2e31a1e..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/ICheckCatalogCreator.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard; - -import org.eclipse.xtext.ui.wizard.IProjectCreator; - - -/** - * The Interface ICheckCatalogCreator. - */ -public interface ICheckCatalogCreator extends IProjectCreator { - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/Messages.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/Messages.java deleted file mode 100644 index 859abd65f7..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/Messages.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard; - -import org.eclipse.osgi.util.NLS; - - -/** - * The messages used for the wizards. - */ -// CHECKSTYLE:OFF -public final class Messages extends NLS { - - private static final String BUNDLE_NAME = "com.avaloq.tools.ddk.check.ui.wizard.messages"; //$NON-NLS-1$ - - public static String PROJECT_WIZARD_TITLE; - public static String CATALOG_WIZARD_TITLE; - public static String PROJECT_WIZARD_WINDOW_TITLE; - public static String CATALOG_WIZARD_WINDOW_TITLE; - - public static String CATALOG_WIZARD_DESCRIPTION; - public static String PROJECT_WIZARD_DESCRIPTION; - - public static String CATALOG_FIELD_NAME_LABEL; - public static String GRAMMAR_FIELD_NAME_LABEL; - public static String PROJECT_NAME_LABEL; - public static String PACKAGE_NAME_LABEL; - - public static String CHOOSE_GRAMMAR_ID; - public static String EXTENSION_MODIFICATION_READONLY; - public static String NO_CHARSET_DEFINED; - public static String NO_PROJECT_DEFINED; - - public static String PROJECT_WIZARD_COMPLETE; - public static String CATALOG_WIZARD_COMPLETE; - - static { - // Initialize the resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - /** - * Prevents instantiation. - */ - private Messages() { // NOPMD - // Do nothing. - } - -} -// CHECKSTYLE:ON diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckCatalogWizard.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckCatalogWizard.java deleted file mode 100644 index 69d91cc69e..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckCatalogWizard.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard; - -import java.lang.reflect.InvocationTargetException; - -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.graphics.Image; -import org.eclipse.xtext.ui.util.FileOpener; -import org.eclipse.xtext.ui.wizard.IProjectInfo; -import org.eclipse.xtext.ui.wizard.XtextNewProjectWizard; - -import com.avaloq.tools.ddk.check.ui.labeling.CheckImages; -import com.google.inject.Inject; - - -/** - * Wizard for creating a new Check file. - */ -public class NewCheckCatalogWizard extends XtextNewProjectWizard { - - private static final Logger LOGGER = LogManager.getLogger(NewCheckCatalogWizard.class); - - @Inject - private FileOpener fileOpener; - - /** The page. */ - private final NewCheckCatalogWizardPage catalogPage; - - /** - * Instantiates a new new check file wizard. - * - * @param images - * the shared images - * @param catalogPage - * the new catalog wizard page - * @param creator - * the check catalog creator - */ - @Inject - public NewCheckCatalogWizard(final CheckImages images, final NewCheckCatalogWizardPage catalogPage, final ICheckCatalogCreator creator) { - super(creator); - this.catalogPage = catalogPage; - Image image = images.forCheckCatalog(); - setDefaultPageImageDescriptor(ImageDescriptor.createFromImage(image)); - setWindowTitle(Messages.CATALOG_WIZARD_WINDOW_TITLE); - } - - @Override - public void addPages() { - super.addPages(); - catalogPage.init(selection); // from parent class - addPage(catalogPage); - } - - @Override - protected void doFinish(final IProjectInfo projectInfo, final IProgressMonitor monitor) { - getCreator().setProjectInfo(getProjectInfo()); - try { - getCreator().run(monitor); - fileOpener.selectAndReveal(getCreator().getResult()); - fileOpener.openFileToEdit(getShell(), getCreator().getResult()); - } catch (final InvocationTargetException e) { - LOGGER.error(e.getMessage(), e); - } catch (final InterruptedException e) { - LOGGER.error(e.getMessage(), e); - } - } - - /** - * Get the project info instance from the new file page. It contains all information except for the project name. - * - * @return the project info instance - */ - @Override - public IProjectInfo getProjectInfo() { - return catalogPage.getProjectInfo(); - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckCatalogWizardPage.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckCatalogWizardPage.java deleted file mode 100644 index 27f6fa18ee..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckCatalogWizardPage.java +++ /dev/null @@ -1,496 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard; - -import java.util.Set; - -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.internal.core.CompilationUnit; -import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; -import org.eclipse.jdt.ui.wizards.NewTypeWizardPage; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.xtext.Grammar; - -import com.avaloq.tools.ddk.check.CheckConstants; -import com.avaloq.tools.ddk.check.ui.util.CheckResourceUtil; -import com.avaloq.tools.ddk.check.ui.util.FieldInitializerUtil; -import com.avaloq.tools.ddk.check.util.GrammarHelper; -import com.avaloq.tools.ddk.check.validation.CheckJavaValidatorUtil; -import com.google.common.collect.Sets; -import com.google.inject.Inject; - - -/** - * Displays a {@link org.eclipse.jface.wizard.WizardPage page} for the {@link com.avaloq.tools.ddk.check.ui.wizard.NewCheckFileWizard - * new Check Catalog wizard}. - */ -// CHECKSTYLE:OFF (data coupling) -@SuppressWarnings({"restriction", "nls"}) -public class NewCheckCatalogWizardPage extends NewTypeWizardPage { - // CHECKSTYLE:ON - - private static final int PAGE_WIDTH_HINT = 200; - - /** The Constant DEFAULT_COLUMN_NUMBER. */ - private static final int DEFAULT_COLUMN_NUMBER = 4; - - /** Field ID of the grammar input field. */ - protected static final String GRAMMAR = "NewCheckCatalogWizardPage" + ".grammar"; // TODO NLS??? - - /** The resource. */ - private IResource resource; - - /** The field initializer utility. Sets source folder and package name as selected in the UI. */ - @Inject - private FieldInitializerUtil fieldInitializerUtil; - - /** The resource utility gets defaults for the combo fields. */ - @Inject - private CheckResourceUtil resourceUtil; - - /** The grammar status. */ - private IStatus grammarStatus; - - /** The selected element. */ - private IJavaElement element; - - private Grammar grammar; - - private final CheckProjectInfo projectInfo; - - /** Is anything selected for the file creation. */ - private final StatusInfo selectionStatus = new StatusInfo(); - - /** Validator for input validation. */ - @Inject - private CheckJavaValidatorUtil validator; - - /** - * Instantiates a new new check catalog wizard page. - */ - @Inject - public NewCheckCatalogWizardPage() { - super(NewTypeWizardPage.CLASS_TYPE, "NewCheckCatalogWizardPage"); - setTitle(Messages.CATALOG_WIZARD_TITLE); - setDescription(Messages.CATALOG_WIZARD_DESCRIPTION); - projectInfo = new CheckProjectInfo(); - grammarStatus = new StatusInfo(); - } - - @Override - protected String getTypeNameLabel() { - return Messages.CATALOG_FIELD_NAME_LABEL; - } - - /** - * Gets the catalog name. - * - * @return the catalog name - */ - public String getCatalogName() { - return getTypeName(); - } - - /** - * Gets the resource. - * - * @return the resource - */ - public IResource getResource() { - return resource; - } - - /** - * Gets the package name. - * - * @return the package name - */ - public String getPackageName() { - return getPackageText(); - } - - @Override - protected String getPackageLabel() { - return Messages.PACKAGE_NAME_LABEL; - } - - public Grammar getGrammar() { - return grammar; - } - - /** - * Validate grammar. - * - * @return the status (ERROR or OK) - */ - private IStatus validateGrammarAccess() { - StatusInfo status = new StatusInfo(); - if (getGrammar() == null || (getGrammar().getName().length() == 0)) { - status.setError(Messages.CHOOSE_GRAMMAR_ID); - } - // update Check ProjectInfo - if (status.isOK()) { - projectInfo.setGrammar(getGrammar()); - } - return status; - } - - @Override - public void createControl(final Composite parent) { - initializeDialogUnits(parent); - - final Composite composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = DEFAULT_COLUMN_NUMBER; - composite.setLayout(layout); - composite.setFont(parent.getFont()); - - // Create controls - createPackageControls(composite, DEFAULT_COLUMN_NUMBER); - createSeparator(composite, DEFAULT_COLUMN_NUMBER); - - createTypeNameControls(composite, DEFAULT_COLUMN_NUMBER); - createGrammarsControls(composite); - - // If no project was selected for file creation, disable the controls of the file wizard - // and state an Error in the header. - if (selectionStatus.matches(IStatus.ERROR)) { - Control[] children = composite.getChildren(); - for (Control child : children) { - child.setEnabled(false); - } - this.setDescription(selectionStatus.getMessage()); - // TODO set an information icon - // ImageDescriptor image = ImageDescriptor.createFromImage(IconAndMessageDialog.getInfoImage()); - // this.setImageDescriptor(image); - } - setPageComplete(false); - setControl(composite); - } - - /** - * Creates the grammars controls. - * - * @param composite - * the composite - */ - private void createGrammarsControls(final Composite composite) { - Label generatorConfigLabel = new Label(composite, SWT.NONE); - generatorConfigLabel.setText(Messages.GRAMMAR_FIELD_NAME_LABEL); - - Combo generatorConfigurationField = new Combo(composite, SWT.READ_ONLY); - GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1); - data.widthHint = PAGE_WIDTH_HINT; // prevents shrinking of combo view - generatorConfigurationField.setLayoutData(data); - generatorConfigurationField.setFont(composite.getFont()); - - ComboViewer grammars = new ComboViewer(generatorConfigurationField); - grammars.setContentProvider(new ArrayContentProvider()); - grammars.setLabelProvider(new LabelProvider() { - @Override - public String getText(final Object object) { - if (object instanceof Grammar) { - return new GrammarHelper((Grammar) object).getLabelName(); - } - return super.getText(object); - } - }); - grammars.setInput(resourceUtil.getGrammars()); - - // React to the selection of the viewer - // Note that the viewer return the real object and not just a string - // representation - grammars.addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(final SelectionChangedEvent event) { - if (event.getSelection() instanceof StructuredSelection) { - grammar = (Grammar) ((StructuredSelection) event.getSelection()).getFirstElement(); - grammarStatus = validateGrammarAccess(); - handleFieldChanged(GRAMMAR); - } - } - }); - grammars.setSelection(null); // no pre-defined grammar to be used, forces the user to make a decision about which language to target - } - - /** - * Initializes the page with selected elements. - * - * @param selection - * the selection - */ - protected void init(final IStructuredSelection selection) { - // check if anything is selected at all; note that it is currently possible to create a new - // check file even if there is no project in the workspace (it is created in the External Plug-in Libraries - // directory of the workspace root) - if (!selection.isEmpty()) { - element = fieldInitializerUtil.getSelectedResource(selection); - } else { - selectionStatus.setError(Messages.NO_PROJECT_DEFINED); - } - } - - @Override - public void setVisible(final boolean visible) { - if (visible) { - // don't initialize this page before it becomes visible because -if a project shall be created - it needs - // information from the first page for its initialization. - if (previousPageIsProjectPage()) { - setTitle(Messages.PROJECT_WIZARD_TITLE); - } else { - setTitle(Messages.CATALOG_WIZARD_TITLE); - } - initContainerPage(element); - initTypePage(element); - } - - super.setVisible(visible); - setFocus(); - } - - /** - * ensures that an entered value is still inserted in the field after a page change ("< back", "next >"). - * - * @param catalogName - * the catalog name to be set - * @param canBeModified - * if true the package fragment is - * editable; otherwise it is read-only. - */ - @Override - public void setTypeName(final String catalogName, final boolean canBeModified) { - String catalog = catalogName; - if (getCatalogName().length() != 0) { - catalog = getCatalogName(); - } - super.setTypeName(catalog, canBeModified); - } - - /** - * Sets the package fragment. Sets an initial package, if possible. - * - * @param pack - * the package fragment to be set - * @param canBeModified - * if true the package fragment is - * editable; otherwise it is read-only - */ - @Override - public void setPackageFragment(final IPackageFragment pack, final boolean canBeModified) { - super.setPackageFragment(getPackageFragment(), canBeModified); - } - - /** - * Creates a fragment with the same name as the project name. - * It is used to show an initial package name in the project wizard. - * - * @param name - * name of the initial package - * @return the initial package fragment - */ - private IPackageFragment createInitialFragment(final String name) { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(((NewCheckProjectWizardPage) getPreviousPage()).getProjectName()); - IFolder src = project.getFolder(com.avaloq.tools.ddk.check.ui.wizard.CheckProjectCreator.SRC_ROOT); - IJavaProject jProject = JavaCore.create(project); - IPackageFragmentRoot root = jProject.getPackageFragmentRoot(src); - return root.getPackageFragment(name); - } - - /** - * Checks if the previous page is the first page of the new project wizard. - * - * @return true, if the previous page is the project wizard's first page - */ - private boolean previousPageIsProjectPage() { - return getPreviousPage() instanceof NewCheckProjectWizardPage; - } - - /** - * Do status update. - */ - private void doStatusUpdate() { - IStatus[] status = new IStatus[] {fPackageStatus, fTypeNameStatus, grammarStatus}; - updateStatus(status); - } - - @Override - protected void handleFieldChanged(final String fieldName) { - super.handleFieldChanged(fieldName); - grammarStatus = validateGrammarAccess(); - doStatusUpdate(); - } - - /** - * Gets the output file name. - * - * @return the output file name - */ - public String getOutputFileName() { - return getTypeName() + '.' + CheckConstants.FILE_EXTENSION; - } - - /** - * Gets the output folder. Returns null if no package has been specified. - * - * @return the output folder or null - */ - public IFolder getOutputFolder() { - if (getPackageFragment() == null) { - return null; - } - return (IFolder) getPackageFragment().getResource(); - } - - /** - * Gets the project info. - * - * @return the project info - */ - public CheckProjectInfo getProjectInfo() { - return projectInfo; - } - - @Override - protected IStatus packageChanged() { - super.packageChanged(); // makes modifications to read-only field in parent class; required! - IStatus status = validator.checkPackageName(getPackageName()); - if (status.isOK()) { - projectInfo.setPackageName(getPackageName()); - } - return status; - } - - /** - * Ensures that the project creation is done with the current package fragment. - * Especially when the package name is changed. - * - * @return the current package fragment. - */ - @Override - public IPackageFragment getPackageFragment() { - IPackageFragment packageFragment = super.getPackageFragment(); - if (previousPageIsProjectPage()) { - - if (getPackageText() == null || getPackageText().length() == 0) { - packageFragment = createInitialFragment(((NewCheckProjectWizardPage) getPreviousPage()).getProjectName()); - } else { - packageFragment = createInitialFragment(getPackageText()); - } - } else if (this.element instanceof IPackageFragment && packageFragment.getElementName().length() == 0) { - // initially, get the selected package (if selected). - packageFragment = (IPackageFragment) this.element; - } else if (this.element instanceof CompilationUnit && packageFragment.getElementName().length() == 0) { - // This happens if a Java file is selected - if (((CompilationUnit) this.element).getParent() instanceof IPackageFragment) { // NOPMD - packageFragment = (IPackageFragment) ((CompilationUnit) this.element).getParent(); - } - } - // update projectInfo with current package fragment - projectInfo.setPackageFragment(packageFragment); - return packageFragment; - } - - @Override - public IStatus typeNameChanged() { - super.typeNameChanged(); - IStatus status = validator.checkCatalogName(getCatalogName()); - - if (!previousPageIsProjectPage()) { - - IPackageFragment packageFragment = getPackageFragment(); - - if (packageFragment != null && catalogExists(packageFragment.getResource())) { - return new Status(IStatus.ERROR, status.getPlugin(), NLS.bind(com.avaloq.tools.ddk.check.validation.Messages.CheckJavaValidator_CATALOG_NAME_STATUS, com.avaloq.tools.ddk.check.validation.Messages.CheckJavaValidator_EXISTS)); - } - } - if (!status.matches(IStatus.ERROR)) { - projectInfo.setCatalogName(getCatalogName()); - } - return status; - } - - /** - * Checks if a given catalog name already exists in the project. - * - * @param packageFragment - * the package in which the file is looked for - * @return true, if catalog exists - */ - private boolean catalogExists(final IResource packageFragment) { - final Set foundResources = Sets.newHashSet(); - final String catalogName = getCatalogName() + '.' + CheckConstants.FILE_EXTENSION; - IResourceVisitor catalogNameVisitor = new IResourceVisitor() { - @Override - public boolean visit(final IResource res) throws CoreException { - String resourceName = res.getName(); - if (catalogName.equalsIgnoreCase(resourceName)) { - foundResources.add(res); - } - return foundResources.isEmpty(); - } - }; - try { - packageFragment.accept(catalogNameVisitor); - return !foundResources.isEmpty(); - } catch (CoreException e) { - // packageFragment does not yet exist. Therefore, the catalog name is unique. - return false; - } - } - - /** - * Does not set the message to "OK" when there is no error. - *

- * Is a copy of com.avaloq.tools.ddk.check.ui.wizard.NewCheckProjectWizardPage.updateStatus(IStatus). - *

- *

- * {@inheritDoc} - */ - @Override - protected void updateStatus(final IStatus status) { - IStatus result = status; - if (status.isOK()) { - // avoid setting the message to "OK" when there is no problem - if (previousPageIsProjectPage()) { - result = new Status(status.getSeverity(), status.getPlugin(), Messages.PROJECT_WIZARD_COMPLETE); - } else { - result = new Status(status.getSeverity(), status.getPlugin(), Messages.CATALOG_WIZARD_COMPLETE); - } - } - super.updateStatus(result); - } -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckProjectWizard.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckProjectWizard.java deleted file mode 100644 index 5ab8d0ada9..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckProjectWizard.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard; - -import org.eclipse.xtext.ui.wizard.IProjectCreator; -import org.eclipse.xtext.ui.wizard.IProjectInfo; -import org.eclipse.xtext.ui.wizard.XtextNewProjectWizard; - -import com.google.inject.Inject; - - -/** - * This is a new plugin project wizard. Its role is to create a new plugin - * project including the necessary dependencies for a check project. The wizard - * creates one file with the extension "check" in the src folder - * of the new project. - */ - -public class NewCheckProjectWizard extends XtextNewProjectWizard { // extends Wizard implements INewWizard - - private final NewCheckProjectWizardPage newProjectPage; - private final NewCheckCatalogWizardPage newCatalogPage; - - /** - * Constructor for the check project wizard. The pages required by this wizard are not created by hand, but by Guice (see also plugin.xml). - * - * @param creator - * the project creator - * @param newProjectPage - * the new project wizard page - * @param newCatalogPage - * the new catalog wizard page - */ - @Inject - public NewCheckProjectWizard(final IProjectCreator creator, final NewCheckProjectWizardPage newProjectPage, final NewCheckCatalogWizardPage newCatalogPage) { - super(creator); - this.newProjectPage = newProjectPage; - this.newCatalogPage = newCatalogPage; - setNeedsProgressMonitor(true); - setWindowTitle(Messages.PROJECT_WIZARD_WINDOW_TITLE); - } - - /** - * Adding the page to the wizard. - */ - @Override - public void addPages() { - addPage(newProjectPage); - addPage(newCatalogPage); - } - - /** - * Get the project info instance from the new file page. It contains all information except for the project name. - * - * @return the project info instance - */ - @Override - protected IProjectInfo getProjectInfo() { - CheckProjectInfo projectInfo = newCatalogPage.getProjectInfo(); - projectInfo.setProjectName(newProjectPage.getProjectName()); // the project name is only required by the project creator; in case of the new file wizard, - // the project name is neither available nor needed - if (projectInfo.getPackageName().isBlank()) { - // If no package name was provided, set the project name as package name - // Should not happen as package name is mandatory - projectInfo.setPackageName(projectInfo.getProjectName()); - } - return projectInfo; - } -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckProjectWizardPage.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckProjectWizardPage.java deleted file mode 100644 index fe1bfaa929..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/NewCheckProjectWizardPage.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.check.ui.wizard; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; -import org.eclipse.jdt.ui.wizards.NewTypeWizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Text; -import org.eclipse.xtext.ui.editor.tasks.dialogfields.DialogField; -import org.eclipse.xtext.ui.editor.tasks.dialogfields.IDialogFieldListener; -import org.eclipse.xtext.ui.editor.tasks.dialogfields.StringDialogField; - -import com.avaloq.tools.ddk.check.validation.CheckJavaValidatorUtil; -import com.google.inject.Inject; - - -/** - * The CustomCheck Wizard Page allows setting the name, the dsl - * dependency, the grammarId for the new check catalog project. - * Furthermore, the page allows setting the catalog name and a - * new check file. - */ -@SuppressWarnings({"restriction", "nls"}) -public class NewCheckProjectWizardPage extends NewTypeWizardPage { - - private static final int DEFAULT_COLUMN_NUMBER = 4; - - private final StringDialogField projectName; - - private IStatus projectNameStatus; - - @Inject - private CheckJavaValidatorUtil validator; - - /** Field ID of the project input field. */ - protected static final String PROJECT = "NewCheckProjectWizardPage.project"; - - /** - * Constructor for NewCheckProjectWizardPage. - */ - @Inject - public NewCheckProjectWizardPage() { - super(NewTypeWizardPage.CLASS_TYPE, "NewCheckProjectWizardPage"); - setTitle(Messages.PROJECT_WIZARD_TITLE); - setDescription(Messages.PROJECT_WIZARD_DESCRIPTION); - projectName = new StringDialogField(); - projectNameStatus = new StatusInfo(); - } - - private IDialogFieldListener getProjectValueListener() { - return new IDialogFieldListener() { - @Override - public void dialogFieldChanged(final DialogField field) { - projectNameStatus = validator.checkProjectName(getProjectName()); - handleFieldChanged(field.toString()); - } - }; - } - - /** - * Creates the control. - * - * @param parent - * the parent - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite) - */ - @Override - public void createControl(final Composite parent) { - initializeDialogUnits(parent); - Composite composite = new Composite(parent, SWT.NONE); - composite.setFont(parent.getFont()); - GridLayout layout = new GridLayout(); - layout.numColumns = DEFAULT_COLUMN_NUMBER; - composite.setLayout(layout); - - createProjectControls(composite, DEFAULT_COLUMN_NUMBER); - - setControl(composite); - handleFieldChanged(null); - } - - /** - * Does not set the message to "OK" when there is no error. - *

- * Is a copy of com.avaloq.tools.ddk.check.ui.wizard.NewCheckCatalogWizardPage.updateStatus(IStatus). - *

- *

- * {@inheritDoc} - */ - @Override - protected void updateStatus(final IStatus status) { - IStatus result = status; - if (status.isOK()) { - // avoid setting the message to "OK" when there is no problem - result = new Status(status.getSeverity(), status.getPlugin(), ""); - } - super.updateStatus(result); - } - - /** - * Creates the grammars controls. - * - * @param composite - * the composite - * @param columns - * the columns - */ - private void createProjectControls(final Composite composite, final int columns) { - projectName.setDialogFieldListener(getProjectValueListener()); - projectName.setLabelText(Messages.PROJECT_NAME_LABEL); - projectName.doFillIntoGrid(composite, columns); - - DialogField.createEmptySpace(composite); - - Text text = projectName.getTextControl(null); - GridData gridData = new GridData(GridData.FILL_HORIZONTAL); - text.setLayoutData(gridData); - projectName.setFocus(); - } - - @Override - protected void handleFieldChanged(final String fieldName) { - super.handleFieldChanged(fieldName); - projectNameStatus = validator.checkProjectName(getProjectName()); - updateStatus(projectNameStatus); - } - - /** - * Gets the project name. - * - * @return the project name - */ - public String getProjectName() { - return projectName.getText(); - } - -} diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/messages.properties b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/messages.properties deleted file mode 100644 index 42db45f469..0000000000 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/wizard/messages.properties +++ /dev/null @@ -1,20 +0,0 @@ -PROJECT_WIZARD_WINDOW_TITLE=New Check Plug-in Project -CATALOG_WIZARD_WINDOW_TITLE=New Check Catalog -PROJECT_WIZARD_TITLE=Check Plug-in Project -CATALOG_WIZARD_TITLE=Check Catalog - -CATALOG_WIZARD_DESCRIPTION=Creates a new catalog -PROJECT_WIZARD_DESCRIPTION=Creates a new check plug-in project - -CATALOG_FIELD_NAME_LABEL=&Catalog -GRAMMAR_FIELD_NAME_LABEL=&Grammar -PROJECT_NAME_LABEL=N&ame -PACKAGE_NAME_LABEL=&Package - -PROJECT_WIZARD_COMPLETE=Create a new check plug-in project -CATALOG_WIZARD_COMPLETE=Create a new catalog in specified package location - -CHOOSE_GRAMMAR_ID=Grammar must be specified. -EXTENSION_MODIFICATION_READONLY = The operation cannot proceed because plug-in ''{0}'' has a read-only manifest file. -NO_CHARSET_DEFINED=Could not determine workspace default character set, using default. -NO_PROJECT_DEFINED=In order to create a check catalog a project needs to be created first.