From eccac6a9e260383de19d5440148ae96360807a8a Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Sun, 21 Sep 2014 19:24:48 +0400 Subject: [PATCH] m2e support https://github.com/konsoletyper/teavm/issues/5 --- .../META-INF/MANIFEST.MF | 6 +- .../eclipse/m2e/TeaVMProjectConfigurator.java | 129 +++++++++++++++++- .../teavm-eclipse-plugin/META-INF/MANIFEST.MF | 32 ++--- teavm-eclipse/teavm-eclipse-plugin/pom.xml | 2 +- .../PreferencesBasedTeaVMProjectSettings.java | 31 +++-- .../java/org/teavm/eclipse/TeaVMProfile.java | 4 + .../teavm/eclipse/TeaVMProjectBuilder.java | 5 +- .../teavm/eclipse/ui/TeaVMProfileDialog.java | 20 ++- .../eclipse/ui/TeaVMProjectPropertyPage.java | 19 +++ 9 files changed, 212 insertions(+), 36 deletions(-) diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/META-INF/MANIFEST.MF b/teavm-eclipse/teavm-eclipse-m2e-plugin/META-INF/MANIFEST.MF index 5f523a57c..21219c619 100644 --- a/teavm-eclipse/teavm-eclipse-m2e-plugin/META-INF/MANIFEST.MF +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/META-INF/MANIFEST.MF @@ -7,7 +7,9 @@ Bundle-Vendor: Alexey Andreev Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Require-Bundle: org.teavm.eclipse;bundle-version="[0.2,0.3)", org.eclipse.m2e.core;bundle-version="[1.3,2)", - org.eclipse.core.runtime;bundle-version="[3.8.0,4.0)", + org.eclipse.core.runtime;bundle-version="[3.8,4.0)", org.eclipse.m2e.maven.runtime;bundle-version="[1.3,2)", org.eclipse.core.resources;bundle-version="[3.6,4)", - org.eclipse.ui;bundle-version="[3.6,4.0)" + org.eclipse.core.variables;bundle-version="[3.2,4)", + org.eclipse.ui;bundle-version="[3.6,4.0)", + org.eclipse.jdt.core;bundle-version="[3.8,4.0.0)" diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java b/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java index e4e398aff..825f9f928 100644 --- a/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java @@ -1,14 +1,22 @@ package org.teavm.eclipse.m2e; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.*; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.variables.IStringVariableManager; +import org.eclipse.core.variables.VariablesPlugin; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.embedder.IMaven; import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; @@ -16,12 +24,14 @@ import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; import org.teavm.eclipse.TeaVMEclipsePlugin; import org.teavm.eclipse.TeaVMProfile; import org.teavm.eclipse.TeaVMProjectSettings; +import org.teavm.eclipse.TeaVMRuntimeMode; /** * * @author Alexey Andreev */ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator { + private static final String TOOL_ID = "teavm-eclipse-m2e-plugin.tool"; private static final String TEAVM_ARTIFACT_ID = "teavm-maven-plugin"; private static final String TEAVM_GROUP_ID = "org.teavm"; private static final String TEAVM_MAIN_GOAL = "build-javascript"; @@ -29,6 +39,7 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator { private Set usedExecutionIds = new HashSet<>(); private IMaven maven; private MavenProject mavenProject; + private IProject project; @Override public void configure(ProjectConfigurationRequest configurationRequest, IProgressMonitor monitor) @@ -38,7 +49,7 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator { List executions = configurationRequest.getMavenProjectFacade().getMojoExecutions( TEAVM_GROUP_ID, TEAVM_ARTIFACT_ID, monitor, TEAVM_MAIN_GOAL); TeaVMEclipsePlugin teaVMPlugin = TeaVMEclipsePlugin.getDefault(); - IProject project = configurationRequest.getProject(); + project = configurationRequest.getProject(); boolean hasNature = project.hasNature(TeaVMEclipsePlugin.NATURE_ID); int sz = executions.size(); if (!hasNature) { @@ -48,21 +59,29 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator { TeaVMProjectSettings settings = teaVMPlugin.getSettings(project); settings.load(); try { + Set coveredProfiles = new HashSet<>(); for (MojoExecution execution : executions) { if (monitor.isCanceled()) { return; } String profileId = getIdForProfile(execution); + coveredProfiles.add(profileId); TeaVMProfile profile = settings.getProfile(profileId); if (profile == null) { profile = settings.createProfile(); profile.setName(profileId); } + profile.setExternalToolId(TOOL_ID); configureProfile(execution, profile, new SubProgressMonitor(monitor, 1000)); if (monitor.isCanceled()) { return; } } + for (TeaVMProfile profile : settings.getProfiles()) { + if (!coveredProfiles.contains(profile.getName()) && profile.getExternalToolId().equals(TOOL_ID)) { + settings.deleteProfile(profile); + } + } if (!hasNature) { teaVMPlugin.addNature(new SubProgressMonitor(monitor, 1000), project); } @@ -74,19 +93,117 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator { private void configureProfile(MojoExecution execution, TeaVMProfile profile, IProgressMonitor monitor) throws CoreException { - monitor.beginTask("Configuring profile " + profile.getName(), 30); + monitor.beginTask("Configuring profile " + profile.getName(), 110); + String buildDir = getProjectBuildDirectory(); + String mainClass = maven.getMojoParameterValue(mavenProject, execution, "mainClass", String.class, new SubProgressMonitor(monitor, 10)); profile.setMainClass(mainClass); + String targetDir = maven.getMojoParameterValue(mavenProject, execution, "targetDirectory", String.class, new SubProgressMonitor(monitor, 10)); - profile.setTargetDirectory(targetDir); + profile.setTargetDirectory(targetDir != null ? absolutePathToWorkspacePath(targetDir) : + buildDir + "/javascript"); + String targetFileName = maven.getMojoParameterValue(mavenProject, execution, "targetFileName", String.class, new SubProgressMonitor(monitor, 10)); profile.setTargetFileName(targetFileName != null ? targetFileName : "classes.js"); + + Boolean minifying = maven.getMojoParameterValue(mavenProject, execution, "minifying", Boolean.class, + new SubProgressMonitor(monitor, 10)); + profile.setMinifying(minifying != null ? minifying : true); + + String runtime = maven.getMojoParameterValue(mavenProject, execution, "runtime", String.class, + new SubProgressMonitor(monitor, 10)); + profile.setRuntimeMode(runtime != null ? getRuntimeMode(runtime) : TeaVMRuntimeMode.SEPARATE); + + Properties properties = maven.getMojoParameterValue(mavenProject, execution, "properties", Properties.class, + new SubProgressMonitor(monitor, 10)); + profile.setProperties(properties != null ? properties : new Properties()); + + Boolean debug = maven.getMojoParameterValue(mavenProject, execution, "debugInformationGenerated", + Boolean.class, new SubProgressMonitor(monitor, 10)); + profile.setDebugInformationGenerated(debug != null ? debug : false); + + Boolean sourceMaps = maven.getMojoParameterValue(mavenProject, execution, "sourceMapsGenerated", + Boolean.class, new SubProgressMonitor(monitor, 10)); + profile.setSourceMapsGenerated(sourceMaps != null ? sourceMaps : false); + + Boolean incremental = maven.getMojoParameterValue(mavenProject, execution, "incremental", Boolean.class, + new SubProgressMonitor(monitor, 10)); + profile.setIncremental(incremental != null ? incremental : false); + + String cacheDir = maven.getMojoParameterValue(mavenProject, execution, "cacheDirectory", String.class, + new SubProgressMonitor(monitor, 10)); + profile.setCacheDirectory(cacheDir != null ? absolutePathToWorkspacePath(cacheDir) : + buildDir + "/teavm-cache"); + + String[] transformers = maven.getMojoParameterValue(mavenProject, execution, "transformers", String[].class, + new SubProgressMonitor(monitor, 10)); + profile.setTransformers(transformers != null ? transformers : new String[0]); + + profile.setClassAliases(readClassAliases(execution)); + monitor.done(); } + private Map readClassAliases(MojoExecution execution) { + Map aliases = new HashMap<>(); + Xpp3Dom aliasesElem = execution.getConfiguration().getChild("classAliases"); + if (aliasesElem != null) { + for (Xpp3Dom item : aliasesElem.getChildren()) { + String className = item.getChild("className").getValue(); + String alias = item.getChild("alias").getValue(); + aliases.put(className, alias); + } + } + return aliases; + } + + private String getProjectBuildDirectory() throws CoreException { + IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager(); + if (!project.hasNature(JavaCore.NATURE_ID)) { + return varManager.generateVariableExpression("workspace_loc", "/" + project.getName()); + } + IJavaProject javaProject = JavaCore.create(project); + String path = javaProject.getOutputLocation().toString(); + return varManager.generateVariableExpression("workspace_loc", path); + } + + private String absolutePathToWorkspacePath(String path) { + try { + IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager(); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IContainer[] containers = root.findContainersForLocationURI(new URI("file://" + path)); + if (containers.length == 0) { + return null; + } + IContainer container = containers[0]; + String suffix = ""; + while (!(container instanceof IProject)) { + suffix = "/" + container.getName() + suffix; + container = container.getParent(); + } + path = container.getFullPath().toString(); + return varManager.generateVariableExpression("workspace_loc", path) + suffix; + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + + private TeaVMRuntimeMode getRuntimeMode(String name) { + switch (name) { + case "SEPARATE": + return TeaVMRuntimeMode.SEPARATE; + case "MERGED": + return TeaVMRuntimeMode.MERGE; + case "NONE": + return TeaVMRuntimeMode.NONE; + default: + return TeaVMRuntimeMode.NONE; + } + } + private String getIdForProfile(MojoExecution pluginExecution) { String executionId = pluginExecution.getExecutionId(); if (executionId != null && usedExecutionIds.add(executionId)) { diff --git a/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF b/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF index 53c693e2e..a95cab80e 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF +++ b/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF @@ -6,22 +6,22 @@ Bundle-Version: 0.2.0.qualifer Bundle-Vendor: Alexey Andreev Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-Activator: org.teavm.eclipse.TeaVMEclipsePlugin -Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.8.0,4.0)", - org.eclipse.debug.core;bundle-version="[3.7.0,4.0)", - org.eclipse.debug.ui;bundle-version="[3.8.0,4.0)", - org.eclipse.swt;bundle-version="[3.8.1,4.0)", - org.eclipse.ui;bundle-version="[3.7.1,4.0)", - org.eclipse.jdt.debug;bundle-version="[3.7.101,4.0.0)", - org.eclipse.jdt.debug.ui;bundle-version="[3.6.100,4.0.0)", - org.eclipse.jdt.core;bundle-version="[3.8.3,4.0.0)", - org.eclipse.jdt.launching;bundle-version="[3.6.1,4.0.0)", - org.eclipse.ui.editors;bundle-version="[3.8.0,4.0.0)", - org.eclipse.ui.ide;bundle-version="[3.8.2,4.0.0)", - org.eclipse.jdt.ui;bundle-version="[3.8.2,4.0.0)", - org.eclipse.core.filesystem;bundle-version="[1.3.200,2)", - org.eclipse.core.variables;bundle-version="[3.2.600,4)", - org.eclipse.core.databinding.observable;bundle-version="[1.4.1,2)", - org.eclipse.jface.databinding;bundle-version="[1.6.0,2)" +Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.8,4.0)", + org.eclipse.debug.core;bundle-version="[3.7,4.0)", + org.eclipse.debug.ui;bundle-version="[3.8,4.0)", + org.eclipse.swt;bundle-version="[3.8,4.0)", + org.eclipse.ui;bundle-version="[3.7,4.0)", + org.eclipse.jdt.debug;bundle-version="[3.7,4.0.0)", + org.eclipse.jdt.debug.ui;bundle-version="[3.6,4.0.0)", + org.eclipse.jdt.core;bundle-version="[3.8,4.0.0)", + org.eclipse.jdt.launching;bundle-version="[3.6,4.0.0)", + org.eclipse.ui.editors;bundle-version="[3.8,4.0.0)", + org.eclipse.ui.ide;bundle-version="[3.8,4.0.0)", + org.eclipse.jdt.ui;bundle-version="[3.8,4.0.0)", + org.eclipse.core.filesystem;bundle-version="[1.3,2)", + org.eclipse.core.variables;bundle-version="[3.2,4)", + org.eclipse.core.databinding.observable;bundle-version="[1.4,2)", + org.eclipse.jface.databinding;bundle-version="[1.6,2)" Bundle-ClassPath: ., lib/asm-5.0.1.jar, lib/asm-commons-5.0.1.jar, diff --git a/teavm-eclipse/teavm-eclipse-plugin/pom.xml b/teavm-eclipse/teavm-eclipse-plugin/pom.xml index e2b91d95e..d85c52152 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/pom.xml +++ b/teavm-eclipse/teavm-eclipse-plugin/pom.xml @@ -1,3 +1,4 @@ + - 4.0.0 diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java index ff4644b9c..f06e005e8 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/PreferencesBasedTeaVMProjectSettings.java @@ -43,6 +43,7 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting public static final String PROPERTIES = "properties"; public static final String CLASSES = "classes"; public static final String TRANSFORMERS = "transformers"; + public static final String EXTERNAL_TOOL_ID = "externalTool"; private static final String NEW_PROFILE_NAME = "New profile"; private List profiles = new ArrayList<>(); @@ -71,7 +72,7 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting if (profileMap.get(profile.getName()) != profile) { return; } - profileMap.remove(profile); + profileMap.remove(profile.getName()); profiles.remove(profile); } @@ -109,7 +110,8 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting } for (String key : globalPreferences.childrenNames()) { if (!profileMap.containsKey(key)) { - globalPreferences.node(key).removeNode(); + Preferences node = globalPreferences.node(key); + node.removeNode(); } } globalPreferences.flush(); @@ -160,7 +162,8 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting private boolean debugInformationGenerated; private Properties properties = new Properties(); private String[] transformers = new String[0]; - private Map classeAliases = new HashMap<>(); + private Map classAliases = new HashMap<>(); + private String externalToolId = ""; @Override public String getName() { @@ -293,12 +296,12 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting @Override public Map getClassAliases() { - return new HashMap<>(classeAliases); + return new HashMap<>(classAliases); } @Override public void setClassAliases(Map classAliases) { - this.classeAliases = new HashMap<>(classAliases); + this.classAliases = new HashMap<>(classAliases); } @Override @@ -311,6 +314,16 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting this.transformers = transformers.clone(); } + @Override + public String getExternalToolId() { + return externalToolId; + } + + @Override + public void setExternalToolId(String toolId) { + this.externalToolId = toolId; + } + public void load() throws BackingStoreException { preferences.sync(); enabled = preferences.getBoolean(ENABLED, true); @@ -335,8 +348,9 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting Preferences classesPrefs = preferences.node(CLASSES); classesPrefs.sync(); for (String key : classesPrefs.keys()) { - classeAliases.put(key, classesPrefs.get(key, "_")); + classAliases.put(key, classesPrefs.get(key, "_")); } + externalToolId = preferences.get(EXTERNAL_TOOL_ID, ""); } public void save() throws BackingStoreException { @@ -365,10 +379,11 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting transformersPrefs.flush(); Preferences classesPrefs = preferences.node(CLASSES); classesPrefs.clear(); - for (String key : classeAliases.keySet()) { - classesPrefs.put(key, classeAliases.get(key)); + for (String key : classAliases.keySet()) { + classesPrefs.put(key, classAliases.get(key)); } classesPrefs.flush(); + preferences.put(EXTERNAL_TOOL_ID, externalToolId); preferences.flush(); } } diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMProfile.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMProfile.java index bf6b633f6..532238cee 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMProfile.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMProfile.java @@ -78,4 +78,8 @@ public interface TeaVMProfile { Map getClassAliases(); void setClassAliases(Map classAliases); + + String getExternalToolId(); + + void setExternalToolId(String toolId); } diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMProjectBuilder.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMProjectBuilder.java index 4ceec891b..7d7922a60 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMProjectBuilder.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/TeaVMProjectBuilder.java @@ -99,7 +99,7 @@ public class TeaVMProjectBuilder extends IncrementalProjectBuilder { tool.setDebugInformationGenerated(profile.isDebugInformationGenerated()); tool.setSourceMapsFileGenerated(profile.isSourceMapsGenerated()); String targetDir = profile.getTargetDirectory(); - tool.setTargetDirectory(new File(varManager.performStringSubstitution(targetDir))); + tool.setTargetDirectory(new File(varManager.performStringSubstitution(targetDir, false))); tool.setTargetFileName(profile.getTargetFileName()); tool.setMinifying(profile.isMinifying()); tool.setRuntime(mapRuntime(profile.getRuntimeMode())); @@ -107,7 +107,8 @@ public class TeaVMProjectBuilder extends IncrementalProjectBuilder { tool.getProperties().putAll(profile.getProperties()); tool.setIncremental(profile.isIncremental()); String cacheDir = profile.getCacheDirectory(); - tool.setCacheDirectory(!cacheDir.isEmpty() ? new File(varManager.performStringSubstitution(cacheDir)) : null); + tool.setCacheDirectory(!cacheDir.isEmpty() ? + new File(varManager.performStringSubstitution(cacheDir, false)) : null); for (ClassHolderTransformer transformer : instantiateTransformers(profile, classLoader)) { tool.getTransformers().add(transformer); } diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProfileDialog.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProfileDialog.java index c0d29f835..dedd6dbba 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProfileDialog.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProfileDialog.java @@ -53,6 +53,7 @@ import org.teavm.eclipse.TeaVMRuntimeMode; public class TeaVMProfileDialog extends Dialog { private static List runtimeModes = Arrays.asList(TeaVMRuntimeMode.SEPARATE, TeaVMRuntimeMode.MERGE, TeaVMRuntimeMode.NONE); + private TabFolder tabFolder; private Text nameField; private Text mainClassField; private Button mainClassChooseButton; @@ -107,7 +108,7 @@ public class TeaVMProfileDialog extends Dialog { area.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); ScrolledComposite scrollContainer = new ScrolledComposite(area, SWT.V_SCROLL | SWT.H_SCROLL); scrollContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - TabFolder tabFolder = new TabFolder(scrollContainer, SWT.TOP); + tabFolder = new TabFolder(scrollContainer, SWT.TOP); scrollContainer.setContent(tabFolder); scrollContainer.setExpandHorizontal(true); scrollContainer.setExpandVertical(true); @@ -644,6 +645,18 @@ public class TeaVMProfileDialog extends Dialog { cacheDirectoryWorkspaceButton.setEnabled(incrementalButton.getSelection()); } + private static void setEnabledRecursive(Composite composite, boolean enabled) { + Control[] children = composite.getChildren(); + for (int i = 0; i < children.length; i++) { + if (children[i] instanceof Composite) { + setEnabledRecursive((Composite) children[i], enabled); + } else { + children[i].setEnabled(enabled); + } + } + composite.setEnabled(enabled); + } + private void load() { nameField.setText(profile.getName()); mainClassField.setText(profile.getMainClass() != null ? profile.getMainClass() : ""); @@ -671,6 +684,11 @@ public class TeaVMProfileDialog extends Dialog { row.alias = entry.getValue(); classAliases.add(row); } + for (Control control : tabFolder.getTabList()) { + if (control instanceof Composite) { + setEnabledRecursive((Composite)control, profile.getExternalToolId().isEmpty()); + } + } } private boolean save() { diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProjectPropertyPage.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProjectPropertyPage.java index 962ac08fe..170a494cc 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProjectPropertyPage.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/ui/TeaVMProjectPropertyPage.java @@ -99,6 +99,11 @@ public class TeaVMProjectPropertyPage extends PropertyPage implements IWorkbench TableColumn fileColumn = new TableColumn(profilesTable, SWT.LEFT); fileColumn.setText("Target file"); fileColumn.setWidth(150); + profilesTable.addSelectionListener(new SelectionAdapter() { + @Override public void widgetSelected(SelectionEvent e) { + updateTableSelection(); + } + }); addProfileButton = new Button(container, SWT.PUSH); addProfileButton.setText("Add..."); @@ -130,6 +135,16 @@ public class TeaVMProjectPropertyPage extends PropertyPage implements IWorkbench return container; } + private void updateTableSelection() { + if (profilesTable.getSelectionCount() != 1) { + removeProfileButton.setEnabled(false); + return; + } + TableItem item = profilesTable.getSelection()[0]; + TeaVMProfile profile = (TeaVMProfile)item.getData(); + removeProfileButton.setEnabled(profile.getExternalToolId().isEmpty()); + } + private void loadProfiles() { try { settings.load(); @@ -197,6 +212,10 @@ public class TeaVMProjectPropertyPage extends PropertyPage implements IWorkbench return; } TableItem item = profilesTable.getSelection()[0]; + TeaVMProfile profile = (TeaVMProfile)item.getData(); + if (!profile.getExternalToolId().isEmpty()) { + return; + } boolean confirmed = MessageDialog.openConfirm(getShell(), "Deletion confirmation", "Are you sure to delete profile " + item.getText(0) + "?"); if (!confirmed) {