diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMConfiguration.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMConfiguration.java deleted file mode 100644 index e1e29720c..000000000 --- a/tools/idea/src/main/java/org/teavm/idea/TeaVMConfiguration.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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; - -public class TeaVMConfiguration { - private boolean enabled; - private String mainClass; - private String targetDirectory; - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public String getMainClass() { - return mainClass; - } - - public void setMainClass(String mainClass) { - this.mainClass = mainClass; - } - - public String getTargetDirectory() { - return targetDirectory; - } - - public void setTargetDirectory(String targetDirectory) { - this.targetDirectory = targetDirectory; - } -} 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 922ae7745..69631e937 100644 --- a/tools/idea/src/main/java/org/teavm/idea/TeaVMConfigurationStorage.java +++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMConfigurationStorage.java @@ -21,20 +21,21 @@ import com.intellij.openapi.components.Storage; import com.intellij.openapi.module.ModuleComponent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.teavm.idea.jps.model.TeaVMJpsConfiguration; @State(name = "teavm", storages = @Storage(id = "other", file = "$MODULE_FILE$")) -public class TeaVMConfigurationStorage implements PersistentStateComponent, ModuleComponent { - private TeaVMConfiguration state; +public class TeaVMConfigurationStorage implements PersistentStateComponent, ModuleComponent { + private TeaVMJpsConfiguration state = new TeaVMJpsConfiguration(); @Nullable @Override - public TeaVMConfiguration getState() { - return state; + public TeaVMJpsConfiguration getState() { + return state.createCopy(); } @Override - public void loadState(TeaVMConfiguration state) { - this.state = state; + public void loadState(TeaVMJpsConfiguration state) { + this.state.applyChanges(state); } @Override 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 96966576b..fe71011a6 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 @@ -22,8 +22,8 @@ import com.intellij.openapi.options.ConfigurationException; import javax.swing.JComponent; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.Nullable; -import org.teavm.idea.TeaVMConfiguration; import org.teavm.idea.TeaVMConfigurationStorage; +import org.teavm.idea.jps.model.TeaVMJpsConfiguration; public class TeaVMConfigurable implements Configurable { private final Module module; @@ -61,7 +61,7 @@ public class TeaVMConfigurable implements Configurable { @Override public void apply() throws ConfigurationException { - TeaVMConfiguration config = new TeaVMConfiguration(); + TeaVMJpsConfiguration config = new TeaVMJpsConfiguration(); panel.save(config); TeaVMConfigurationStorage configStorage = ModuleServiceManager.getService(module, TeaVMConfigurationStorage.class); 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 a4f9b6f5a..3570197ea 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 @@ -29,20 +29,20 @@ import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import org.teavm.idea.TeaVMConfiguration; +import org.teavm.idea.jps.model.TeaVMJpsConfiguration; class TeaVMConfigurationPanel extends JPanel { private final JCheckBox enabledCheckBox = new JCheckBox("TeaVM enabled for this module"); private final JTextField mainClassField = new JTextField(); private final JTextField targetDirectoryField = new JTextField(); - private final TeaVMConfiguration initialConfiguration = new TeaVMConfiguration(); + private final TeaVMJpsConfiguration initialConfiguration = new TeaVMJpsConfiguration(); private final List editComponents = Arrays.asList(mainClassField, targetDirectoryField); private final List> fields = Arrays.asList( - new Field<>(TeaVMConfiguration::setEnabled, TeaVMConfiguration::isEnabled, + new Field<>(TeaVMJpsConfiguration::setEnabled, TeaVMJpsConfiguration::isEnabled, enabledCheckBox::setSelected, enabledCheckBox::isSelected), - new Field<>(TeaVMConfiguration::setMainClass, TeaVMConfiguration::getMainClass, + new Field<>(TeaVMJpsConfiguration::setMainClass, TeaVMJpsConfiguration::getMainClass, mainClassField::setText, mainClassField::getText), - new Field<>(TeaVMConfiguration::setTargetDirectory, TeaVMConfiguration::getTargetDirectory, + new Field<>(TeaVMJpsConfiguration::setTargetDirectory, TeaVMJpsConfiguration::getTargetDirectory, targetDirectoryField::setText, targetDirectoryField::getText) ); @@ -75,9 +75,9 @@ class TeaVMConfigurationPanel extends JPanel { add(targetDirectoryField, fieldConstrains); } - public void load(TeaVMConfiguration config) { + public void load(TeaVMJpsConfiguration config) { if (config == null) { - config = new TeaVMConfiguration(); + config = new TeaVMJpsConfiguration(); } updateInitialConfiguration(config); for (Field field : fields) { @@ -86,18 +86,18 @@ class TeaVMConfigurationPanel extends JPanel { updateEnabledState(); } - public void save(TeaVMConfiguration config) { + public void save(TeaVMJpsConfiguration config) { for (Field field : fields) { saveField(field, config); } updateInitialConfiguration(config); } - private void loadField(Field field, TeaVMConfiguration config) { + private void loadField(Field field, TeaVMJpsConfiguration config) { field.editConsumer.accept(field.dataSupplier.apply(config)); } - private void saveField(Field field, TeaVMConfiguration config) { + private void saveField(Field field, TeaVMJpsConfiguration config) { field.dataConsumer.accept(config, field.editSupplier.get()); } @@ -115,19 +115,19 @@ class TeaVMConfigurationPanel extends JPanel { return !Objects.equals(field.dataSupplier.apply(initialConfiguration), field.editSupplier.get()); } - private void updateInitialConfiguration(TeaVMConfiguration config) { + private void updateInitialConfiguration(TeaVMJpsConfiguration config) { initialConfiguration.setEnabled(config.isEnabled()); initialConfiguration.setMainClass(config.getMainClass()); initialConfiguration.setTargetDirectory(config.getTargetDirectory()); } static class Field { - final BiConsumer dataConsumer; - final Function dataSupplier; + final BiConsumer dataConsumer; + final Function dataSupplier; final Consumer editConsumer; final Supplier editSupplier; - public Field(BiConsumer dataConsumer, Function dataSupplier, + public Field(BiConsumer dataConsumer, Function dataSupplier, Consumer editConsumer, Supplier editSupplier) { this.dataConsumer = dataConsumer; this.dataSupplier = dataSupplier;