From dcef7fc9965e5c37526fc84d72c777f82e8c3dfe Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 27 Oct 2016 19:46:49 +0300 Subject: [PATCH 1/2] IDEA: creating facet --- .../main/java/org/teavm/idea/TeaVMFacet.java | 31 ++++++++++ .../teavm/idea/TeaVMFacetConfiguration.java | 60 +++++++++++++++++++ .../java/org/teavm/idea/TeaVMFacetType.java | 58 ++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 tools/idea/src/main/java/org/teavm/idea/TeaVMFacet.java create mode 100644 tools/idea/src/main/java/org/teavm/idea/TeaVMFacetConfiguration.java create mode 100644 tools/idea/src/main/java/org/teavm/idea/TeaVMFacetType.java diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMFacet.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacet.java new file mode 100644 index 000000000..0a0c5a1e5 --- /dev/null +++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacet.java @@ -0,0 +1,31 @@ +/* + * Copyright 2016 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.idea; + +import com.intellij.facet.Facet; +import com.intellij.facet.FacetConfiguration; +import com.intellij.facet.FacetType; +import com.intellij.openapi.module.Module; +import org.jetbrains.annotations.NotNull; + +public class TeaVMFacet extends Facet { + public TeaVMFacet(@NotNull FacetType facetType, + @NotNull Module module, + @NotNull String name, + @NotNull FacetConfiguration configuration, Facet underlyingFacet) { + super(facetType, module, name, configuration, underlyingFacet); + } +} diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetConfiguration.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetConfiguration.java new file mode 100644 index 000000000..277db7b76 --- /dev/null +++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetConfiguration.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.idea; + +import com.intellij.facet.FacetConfiguration; +import com.intellij.facet.ui.FacetEditorContext; +import com.intellij.facet.ui.FacetEditorTab; +import com.intellij.facet.ui.FacetValidatorsManager; +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.components.State; +import com.intellij.openapi.components.Storage; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.WriteExternalException; +import org.jdom.Element; +import org.jetbrains.annotations.Nullable; +import org.teavm.idea.jps.model.TeaVMJpsConfiguration; + +@State(name = "teavm", storages = @Storage(id = "other", file = "$MODULE_FILE$")) +public class TeaVMFacetConfiguration implements FacetConfiguration, PersistentStateComponent { + private TeaVMJpsConfiguration state = new TeaVMJpsConfiguration(); + + @Override + public FacetEditorTab[] createEditorTabs(FacetEditorContext editorContext, + FacetValidatorsManager validatorsManager) { + return new FacetEditorTab[0]; + } + + @Override + public void readExternal(Element element) throws InvalidDataException { + } + + @Override + public void writeExternal(Element element) throws WriteExternalException { + } + + + @Nullable + @Override + public TeaVMJpsConfiguration getState() { + return state.createCopy(); + } + + @Override + public void loadState(TeaVMJpsConfiguration state) { + this.state.applyChanges(state); + } +} diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetType.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetType.java new file mode 100644 index 000000000..7c1729039 --- /dev/null +++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetType.java @@ -0,0 +1,58 @@ +/* + * Copyright 2016 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.idea; + +import com.intellij.facet.Facet; +import com.intellij.facet.FacetType; +import com.intellij.facet.FacetTypeId; +import com.intellij.openapi.module.JavaModuleType; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; +import com.intellij.openapi.util.IconLoader; +import javax.swing.Icon; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class TeaVMFacetType extends FacetType { + public static final FacetTypeId TYPE_ID = new FacetTypeId<>("teavm-js"); + private static final Icon icon = IconLoader.getIcon("/teavm-16.png"); + + public TeaVMFacetType() { + super(TYPE_ID, "teavm-js", "TeaVM (JS)"); + } + + @Override + public TeaVMFacetConfiguration createDefaultConfiguration() { + return null; + } + + @Override + public TeaVMFacet createFacet(@NotNull Module module, String name, @NotNull TeaVMFacetConfiguration configuration, + @Nullable Facet underlyingFacet) { + return null; + } + + @Override + public boolean isSuitableModuleType(ModuleType moduleType) { + return moduleType instanceof JavaModuleType; + } + + @Nullable + @Override + public Icon getIcon() { + return icon; + } +} From eaf28d737e7a1a1bf11dc9d9d7a7dd2a4fc96c82 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 4 Nov 2016 23:41:54 +0300 Subject: [PATCH 2/2] IDEA: replace module configuration with TeaVM facet --- .../idea/jps/model/TeaVMJpsConfiguration.java | 12 +--- .../model/TeaVMModelSerializerService.java | 30 ++++++--- .../java/org/teavm/idea/jps/TeaVMBuild.java | 2 +- .../teavm/idea/TeaVMConfigurationStorage.java | 2 +- .../main/java/org/teavm/idea/TeaVMFacet.java | 11 +--- .../teavm/idea/TeaVMFacetConfiguration.java | 11 ++-- .../java/org/teavm/idea/TeaVMFacetType.java | 10 ++- .../teavm/idea/maven/TeaVMMavenImporter.java | 42 ++++++------ .../org/teavm/idea/ui/TeaVMConfigurable.java | 21 ++---- .../idea/ui/TeaVMConfigurationPanel.java | 43 +++---------- .../teavm/idea/ui/TeaVMFacetEditorTab.java | 64 +++++++++++++++++++ .../src/main/resources/META-INF/plugin.xml | 5 +- 12 files changed, 139 insertions(+), 114 deletions(-) create mode 100644 tools/idea/src/main/java/org/teavm/idea/ui/TeaVMFacetEditorTab.java diff --git a/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMJpsConfiguration.java b/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMJpsConfiguration.java index 394450e58..dd0a845c8 100644 --- a/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMJpsConfiguration.java +++ b/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMJpsConfiguration.java @@ -22,23 +22,14 @@ import org.jetbrains.jps.model.ex.JpsElementChildRoleBase; import org.jetbrains.jps.model.module.JpsModule; public class TeaVMJpsConfiguration extends JpsElementBase { - private static final JpsElementChildRole ROLE = JpsElementChildRoleBase.create( + static final JpsElementChildRole ROLE = JpsElementChildRoleBase.create( "TeaVM configuration"); - private boolean enabled; private String mainClass; private String targetDirectory; private boolean minifying; private boolean sourceMapsFileGenerated = true; private boolean sourceFilesCopied = true; - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - public String getMainClass() { return mainClass; } @@ -97,7 +88,6 @@ public class TeaVMJpsConfiguration extends JpsElementBase @Override public void applyChanges(@NotNull TeaVMJpsConfiguration modified) { - enabled = modified.enabled; mainClass = modified.mainClass; targetDirectory = modified.targetDirectory; minifying = modified.minifying; diff --git a/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMModelSerializerService.java b/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMModelSerializerService.java index 2e870db97..5bc061e3d 100644 --- a/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMModelSerializerService.java +++ b/tools/idea/jps-common/src/main/java/org/teavm/idea/jps/model/TeaVMModelSerializerService.java @@ -16,23 +16,33 @@ package org.teavm.idea.jps.model; import com.intellij.util.xmlb.XmlSerializer; -import java.util.Objects; +import java.util.Arrays; +import java.util.List; import org.jdom.Element; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.JpsElement; import org.jetbrains.jps.model.module.JpsModule; import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension; +import org.jetbrains.jps.model.serialization.facet.JpsFacetConfigurationSerializer; public class TeaVMModelSerializerService extends JpsModelSerializerExtension { + @NotNull @Override - public void loadModuleOptions(@NotNull JpsModule module, @NotNull Element rootElement) { - rootElement.getChildren("component").stream() - .filter(child -> Objects.equals(child.getAttributeValue("name"), "teavm")) - .forEach(child -> readConfig(module, child)); + public List> getFacetConfigurationSerializers() { + return Arrays.asList(serializer); } - private void readConfig(@NotNull JpsModule module, @NotNull Element element) { - TeaVMJpsConfiguration config = XmlSerializer.deserialize(element, TeaVMJpsConfiguration.class); - assert config != null; - config.setTo(module); - } + JpsFacetConfigurationSerializer serializer = + new JpsFacetConfigurationSerializer(TeaVMJpsConfiguration.ROLE, + "teavm-js", "TeaVM (JS)") { + @Override + protected TeaVMJpsConfiguration loadExtension(@NotNull Element element, String s, JpsElement jpsElement, + JpsModule jpsModule) { + return XmlSerializer.deserialize(element, TeaVMJpsConfiguration.class); + } + + @Override + protected void saveExtension(TeaVMJpsConfiguration configuration, Element element, JpsModule jpsModule) { + } + }; } diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java index a702a0f9e..194385adf 100644 --- a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java +++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java @@ -97,7 +97,7 @@ class TeaVMBuild { storage = context.getProjectDescriptor().dataManager.getStorage(target, storageProvider); TeaVMJpsConfiguration config = TeaVMJpsConfiguration.get(module); - if (config == null || !config.isEnabled()) { + if (config == null) { return false; } diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMConfigurationStorage.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMConfigurationStorage.java index 773ee37c8..25afe8ecd 100644 --- a/tools/idea/src/main/java/org/teavm/idea/TeaVMConfigurationStorage.java +++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMConfigurationStorage.java @@ -21,7 +21,7 @@ import com.intellij.openapi.components.Storage; import org.jetbrains.annotations.Nullable; import org.teavm.idea.jps.model.TeaVMJpsConfiguration; -@State(name = "teavm", storages = @Storage(id = "other", file = "$MODULE_FILE$")) +@State(name = "teavm", storages = @Storage(value = "$MODULE_FILE$")) public class TeaVMConfigurationStorage implements PersistentStateComponent { private TeaVMJpsConfiguration state = new TeaVMJpsConfiguration(); diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMFacet.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacet.java index 0a0c5a1e5..d399ef883 100644 --- a/tools/idea/src/main/java/org/teavm/idea/TeaVMFacet.java +++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacet.java @@ -16,16 +16,11 @@ package org.teavm.idea; import com.intellij.facet.Facet; -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; import com.intellij.openapi.module.Module; import org.jetbrains.annotations.NotNull; -public class TeaVMFacet extends Facet { - public TeaVMFacet(@NotNull FacetType facetType, - @NotNull Module module, - @NotNull String name, - @NotNull FacetConfiguration configuration, Facet underlyingFacet) { - super(facetType, module, name, configuration, underlyingFacet); +public class TeaVMFacet extends Facet { + public TeaVMFacet(@NotNull Module module, @NotNull String name, @NotNull TeaVMFacetConfiguration configuration) { + super(TeaVMFacetType.getInstance(), module, name, configuration, null); } } diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetConfiguration.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetConfiguration.java index 277db7b76..d90bd94a3 100644 --- a/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetConfiguration.java +++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetConfiguration.java @@ -20,22 +20,20 @@ import com.intellij.facet.ui.FacetEditorContext; import com.intellij.facet.ui.FacetEditorTab; import com.intellij.facet.ui.FacetValidatorsManager; import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.components.State; -import com.intellij.openapi.components.Storage; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.WriteExternalException; import org.jdom.Element; import org.jetbrains.annotations.Nullable; import org.teavm.idea.jps.model.TeaVMJpsConfiguration; +import org.teavm.idea.ui.TeaVMFacetEditorTab; -@State(name = "teavm", storages = @Storage(id = "other", file = "$MODULE_FILE$")) public class TeaVMFacetConfiguration implements FacetConfiguration, PersistentStateComponent { private TeaVMJpsConfiguration state = new TeaVMJpsConfiguration(); @Override public FacetEditorTab[] createEditorTabs(FacetEditorContext editorContext, FacetValidatorsManager validatorsManager) { - return new FacetEditorTab[0]; + return new FacetEditorTab[] { new TeaVMFacetEditorTab(editorContext.getModule(), state) }; } @Override @@ -46,15 +44,14 @@ public class TeaVMFacetConfiguration implements FacetConfiguration, PersistentSt public void writeExternal(Element element) throws WriteExternalException { } - @Nullable @Override public TeaVMJpsConfiguration getState() { - return state.createCopy(); + return state; } @Override public void loadState(TeaVMJpsConfiguration state) { - this.state.applyChanges(state); + this.state = state; } } diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetType.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetType.java index 7c1729039..12e80540f 100644 --- a/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetType.java +++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMFacetType.java @@ -18,6 +18,7 @@ package org.teavm.idea; import com.intellij.facet.Facet; import com.intellij.facet.FacetType; import com.intellij.facet.FacetTypeId; +import com.intellij.facet.FacetTypeRegistry; import com.intellij.openapi.module.JavaModuleType; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleType; @@ -36,13 +37,13 @@ public class TeaVMFacetType extends FacetType mavenProjectToModuleName, List postTasks) { - TeaVMConfigurationStorage configurationStorage = ModuleServiceManager.getService(module, - TeaVMConfigurationStorage.class); - if (configurationStorage == null) { - logger.warn("Could not load component to retrieve TeaVM build configuration"); - return; - } - - TeaVMJpsConfiguration configuration = configurationStorage.getState(); + FacetManager facetManager = FacetManager.getInstance(module); for (MavenPlugin mavenPlugin : mavenProject.getPlugins()) { if (mavenPlugin.getGroupId().equals(myPluginGroupID) && mavenPlugin.getArtifactId().equals(myPluginArtifactID)) { - updateConfiguration(mavenPlugin, configuration); + updateConfiguration(mavenPlugin, facetManager, module); } } - - configurationStorage.loadState(configuration); } - private void updateConfiguration(MavenPlugin plugin, TeaVMJpsConfiguration configuration) { + private void updateConfiguration(MavenPlugin plugin, FacetManager facetManager, Module module) { if (plugin.getConfigurationElement() != null) { - updateConfiguration(plugin.getConfigurationElement(), configuration); + updateConfiguration(plugin.getConfigurationElement(), facetManager, module); } + for (MavenPlugin.Execution execution : plugin.getExecutions()) { if (execution.getGoals().contains("compile")) { if (execution.getConfigurationElement() != null) { - updateConfiguration(execution.getConfigurationElement(), configuration); + updateConfiguration(execution.getConfigurationElement(), facetManager, module); } break; } } } - private void updateConfiguration(Element source, TeaVMJpsConfiguration configuration) { - configuration.setEnabled(true); + private void updateConfiguration(Element source, FacetManager facetManager, Module module) { + TeaVMFacet facet = facetManager.getFacetByType(TeaVMFacetType.TYPE_ID); + if (facet == null) { + TeaVMFacetType type = TeaVMFacetType.getInstance(); + facet = new TeaVMFacet(module, "TeaVM (JS)", type.createDefaultConfiguration()); + facetManager.addFacet(type, facet.getName(), facet); + } + + TeaVMJpsConfiguration configuration = facet.getConfiguration().getState(); + for (Element child : source.getChildren()) { switch (child.getName()) { case "sourceFilesCopied": @@ -103,5 +101,7 @@ public class TeaVMMavenImporter extends MavenImporter { break; } } + + facet.getConfiguration().loadState(configuration); } } diff --git a/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMConfigurable.java b/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMConfigurable.java index faa51b690..d9b78e9d7 100644 --- a/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMConfigurable.java +++ b/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMConfigurable.java @@ -16,21 +16,21 @@ package org.teavm.idea.ui; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleServiceManager; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; import javax.swing.JComponent; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.Nullable; -import org.teavm.idea.TeaVMConfigurationStorage; import org.teavm.idea.jps.model.TeaVMJpsConfiguration; public class TeaVMConfigurable implements Configurable { private final Module module; private TeaVMConfigurationPanel panel; + private TeaVMJpsConfiguration configuration; - public TeaVMConfigurable(Module module) { + public TeaVMConfigurable(Module module, TeaVMJpsConfiguration configuration) { this.module = module; + this.configuration = configuration; } @Nls @@ -61,23 +61,12 @@ public class TeaVMConfigurable implements Configurable { @Override public void apply() throws ConfigurationException { - TeaVMJpsConfiguration config = new TeaVMJpsConfiguration(); - panel.save(config); - TeaVMConfigurationStorage configStorage = ModuleServiceManager.getService(module, - TeaVMConfigurationStorage.class); - assert configStorage != null; - configStorage.loadState(config); + panel.save(configuration); } @Override public void reset() { - if (panel == null) { - return; - } - TeaVMConfigurationStorage configStorage = ModuleServiceManager.getService(module, - TeaVMConfigurationStorage.class); - assert configStorage != null; - panel.load(configStorage.getState()); + panel.load(configuration); } @Override diff --git a/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMConfigurationPanel.java b/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMConfigurationPanel.java index 669976357..6a7d86821 100644 --- a/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMConfigurationPanel.java +++ b/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMConfigurationPanel.java @@ -38,25 +38,19 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import javax.swing.DefaultComboBoxModel; -import javax.swing.JCheckBox; import javax.swing.JComboBox; -import javax.swing.JComponent; import javax.swing.JPanel; import org.teavm.idea.jps.model.TeaVMJpsConfiguration; class TeaVMConfigurationPanel extends JPanel { - private final JCheckBox enabledCheckBox = new JCheckBox("TeaVM enabled for this module"); private final TextFieldWithBrowseButton mainClassField = new TextFieldWithBrowseButton(event -> chooseMainClass()); private final TextFieldWithBrowseButton targetDirectoryField = new TextFieldWithBrowseButton(); private final JComboBox> minifyingField = new JComboBox<>(new DefaultComboBoxModel<>()); - private final JComboBox> sourceMapsField = new JComboBox<>(new DefaultComboBoxModel<>());; + private final JComboBox> sourceMapsField = new JComboBox<>(new DefaultComboBoxModel<>()); private final JComboBox> copySourcesField = new JComboBox<>(new DefaultComboBoxModel<>()); private final TeaVMJpsConfiguration initialConfiguration = new TeaVMJpsConfiguration(); private final Project project; - private final List editComponents = Arrays.asList(mainClassField, targetDirectoryField, - minifyingField, sourceMapsField, copySourcesField); - private final List> minifiedOptions = Arrays.asList(new ComboBoxItem<>(false, "Readable"), new ComboBoxItem<>(true, "Minified (obfuscated)")); @@ -67,8 +61,6 @@ class TeaVMConfigurationPanel extends JPanel { new ComboBoxItem<>(false, "Skip")); private final List> fields = Arrays.asList( - new Field<>(TeaVMJpsConfiguration::setEnabled, TeaVMJpsConfiguration::isEnabled, - enabledCheckBox::setSelected, enabledCheckBox::isSelected), new Field<>(TeaVMJpsConfiguration::setMainClass, TeaVMJpsConfiguration::getMainClass, mainClassField::setText, mainClassField::getText), new Field<>(TeaVMJpsConfiguration::setTargetDirectory, TeaVMJpsConfiguration::getTargetDirectory, @@ -88,7 +80,6 @@ class TeaVMConfigurationPanel extends JPanel { TeaVMConfigurationPanel(Project project) { this.project = project; - enabledCheckBox.addActionListener(event -> updateEnabledState()); setupLayout(); FileChooserDescriptor targetDirectoryChooserDescriptor = FileChooserDescriptorFactory @@ -96,24 +87,14 @@ class TeaVMConfigurationPanel extends JPanel { targetDirectoryField.addBrowseFolderListener("Target Directory", "Please, select folder where TeaVM should" + "write generated JS files", project, targetDirectoryChooserDescriptor); - minifiedOptions.stream().forEach(minifyingField::addItem); - sourceMapsOptions.stream().forEach(sourceMapsField::addItem); - copySourcesOptions.stream().forEach(copySourcesField::addItem); + minifiedOptions.forEach(minifyingField::addItem); + sourceMapsOptions.forEach(sourceMapsField::addItem); + copySourcesOptions.forEach(copySourcesField::addItem); } private void setupLayout() { setLayout(new GridBagLayout()); - GridBagConstraints constraints = new GridBagConstraints(); - constraints.gridwidth = GridBagConstraints.REMAINDER; - constraints.anchor = GridBagConstraints.BASELINE_LEADING; - constraints.insets.left = 5; - constraints.insets.right = 5; - constraints.insets.bottom = 25; - constraints.insets.top = 10; - constraints.weighty = 1; - add(enabledCheckBox, constraints); - GridBagConstraints labelConstraints = new GridBagConstraints(); labelConstraints.gridwidth = GridBagConstraints.REMAINDER; labelConstraints.anchor = GridBagConstraints.BASELINE_LEADING; @@ -153,16 +134,17 @@ class TeaVMConfigurationPanel extends JPanel { add(minifyingField, fieldConstraints); add(bold(new JBLabel("Source maps")), labelConstraints); - add(new JBLabel("Indicates whether TeaVM should generate source maps. With source maps " - + "you can debug code in the browser's devtools."), descriptionConstraints); + add(new JBLabel("Indicates whether TeaVM should generate source maps."), descriptionConstraints); + add(new JBLabel("With source maps you can debug code in the browser's devtools."), descriptionConstraints); add(sourceMapsField, fieldConstraints); add(bold(new JBLabel("Copy source code")), labelConstraints); add(new JBLabel("Source maps require your server to provide source code."), descriptionConstraints); - add(new JBLabel("TeaVM can copy source code to the corresponding location, which is very convenient if " - + "you are going to debug in the browser."), descriptionConstraints); + add(new JBLabel("TeaVM can copy source code to the corresponding location,"), descriptionConstraints); + add(new JBLabel("which is very convenient if you are going to debug in the browser."), descriptionConstraints); add(copySourcesField, fieldConstraints); + GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; constraints.weighty = 100; constraints.weightx = 1; @@ -182,7 +164,6 @@ class TeaVMConfigurationPanel extends JPanel { for (Field field : fields) { loadField(field, config); } - updateEnabledState(); } void save(TeaVMJpsConfiguration config) { @@ -206,12 +187,6 @@ class TeaVMConfigurationPanel extends JPanel { } } - private void updateEnabledState() { - for (JComponent component : editComponents) { - component.setEnabled(enabledCheckBox.isSelected()); - } - } - private void copyField(Field field, TeaVMJpsConfiguration config) { field.dataConsumer.accept(initialConfiguration, field.dataSupplier.apply(config)); } diff --git a/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMFacetEditorTab.java b/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMFacetEditorTab.java new file mode 100644 index 000000000..3a8a76b6f --- /dev/null +++ b/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMFacetEditorTab.java @@ -0,0 +1,64 @@ +/* + * Copyright 2016 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.idea.ui; + +import com.intellij.facet.ui.FacetEditorTab; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.options.ConfigurationException; +import javax.swing.JComponent; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.teavm.idea.jps.model.TeaVMJpsConfiguration; + +public class TeaVMFacetEditorTab extends FacetEditorTab { + private TeaVMConfigurable configurable; + + public TeaVMFacetEditorTab(Module module, TeaVMJpsConfiguration configuration) { + configurable = new TeaVMConfigurable(module, configuration); + } + + @NotNull + @Override + public JComponent createComponent() { + return configurable.createComponent(); + } + + @Nls + @Override + public String getDisplayName() { + return "General settings"; + } + + @Override + public boolean isModified() { + return configurable.isModified(); + } + + @Override + public void apply() throws ConfigurationException { + configurable.apply(); + } + + @Override + public void disposeUIResources() { + configurable.disposeUIResources(); + } + + @Override + public void reset() { + configurable.reset(); + } +} diff --git a/tools/idea/src/main/resources/META-INF/plugin.xml b/tools/idea/src/main/resources/META-INF/plugin.xml index 81579c5a2..7c107432e 100644 --- a/tools/idea/src/main/resources/META-INF/plugin.xml +++ b/tools/idea/src/main/resources/META-INF/plugin.xml @@ -26,13 +26,12 @@ - - + +