diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml
index 149b8453c..f065a51e0 100644
--- a/.idea/codeStyleSettings.xml
+++ b/.idea/codeStyleSettings.xml
@@ -5,17 +5,21 @@
+
+
+
+
@@ -264,6 +268,13 @@
+
+
+
+
+
+
+
diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMBuilderService.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMBuilderService.java
index d4e2f6e13..40b0f98f6 100644
--- a/tools/idea/src/main/java/org/teavm/idea/TeaVMBuilderService.java
+++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMBuilderService.java
@@ -22,9 +22,12 @@ import org.jetbrains.jps.builders.BuildTargetType;
import org.jetbrains.jps.incremental.BuilderCategory;
import org.jetbrains.jps.incremental.BuilderService;
import org.jetbrains.jps.incremental.ModuleLevelBuilder;
-import org.jetbrains.jps.incremental.TargetBuilder;
public class TeaVMBuilderService extends BuilderService {
+ TeaVMBuilderService() {
+ System.out.println("Hello");
+ }
+
@NotNull
@Override
public List extends BuildTargetType>> getTargetTypes() {
diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMConfiguration.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMConfiguration.java
new file mode 100644
index 000000000..e1e29720c
--- /dev/null
+++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMConfiguration.java
@@ -0,0 +1,46 @@
+/*
+ * 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
new file mode 100644
index 000000000..922ae7745
--- /dev/null
+++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMConfigurationStorage.java
@@ -0,0 +1,65 @@
+/*
+ * 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.openapi.components.PersistentStateComponent;
+import com.intellij.openapi.components.State;
+import com.intellij.openapi.components.Storage;
+import com.intellij.openapi.module.ModuleComponent;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+@State(name = "teavm", storages = @Storage(id = "other", file = "$MODULE_FILE$"))
+public class TeaVMConfigurationStorage implements PersistentStateComponent, ModuleComponent {
+ private TeaVMConfiguration state;
+
+ @Nullable
+ @Override
+ public TeaVMConfiguration getState() {
+ return state;
+ }
+
+ @Override
+ public void loadState(TeaVMConfiguration state) {
+ this.state = state;
+ }
+
+ @Override
+ public void projectOpened() {
+ }
+
+ @Override
+ public void projectClosed() {
+ }
+
+ @Override
+ public void moduleAdded() {
+ }
+
+ @Override
+ public void initComponent() {
+ }
+
+ @Override
+ public void disposeComponent() {
+ }
+
+ @NotNull
+ @Override
+ public String getComponentName() {
+ return "TeaVM 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
new file mode 100644
index 000000000..96966576b
--- /dev/null
+++ b/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMConfigurable.java
@@ -0,0 +1,87 @@
+/*
+ * 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.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.TeaVMConfiguration;
+import org.teavm.idea.TeaVMConfigurationStorage;
+
+public class TeaVMConfigurable implements Configurable {
+ private final Module module;
+ private TeaVMConfigurationPanel panel;
+
+ public TeaVMConfigurable(Module module) {
+ this.module = module;
+ }
+
+ @Nls
+ @Override
+ public String getDisplayName() {
+ return "TeaVM";
+ }
+
+ @Nullable
+ @Override
+ public String getHelpTopic() {
+ return null;
+ }
+
+ @Nullable
+ @Override
+ public JComponent createComponent() {
+ if (panel == null) {
+ panel = new TeaVMConfigurationPanel();
+ }
+ return panel;
+ }
+
+ @Override
+ public boolean isModified() {
+ return panel != null && panel.isModified();
+ }
+
+ @Override
+ public void apply() throws ConfigurationException {
+ TeaVMConfiguration config = new TeaVMConfiguration();
+ panel.save(config);
+ TeaVMConfigurationStorage configStorage = ModuleServiceManager.getService(module,
+ TeaVMConfigurationStorage.class);
+ assert configStorage != null;
+ configStorage.loadState(config);
+ }
+
+ @Override
+ public void reset() {
+ if (panel == null) {
+ return;
+ }
+ TeaVMConfigurationStorage configStorage = ModuleServiceManager.getService(module,
+ TeaVMConfigurationStorage.class);
+ assert configStorage != null;
+ panel.load(configStorage.getState());
+ }
+
+ @Override
+ public void disposeUIResources() {
+ this.panel = null;
+ }
+}
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
new file mode 100644
index 000000000..096677dba
--- /dev/null
+++ b/tools/idea/src/main/java/org/teavm/idea/ui/TeaVMConfigurationPanel.java
@@ -0,0 +1,132 @@
+/*
+ * 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 java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import org.teavm.idea.TeaVMConfiguration;
+
+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 List editComponents = Arrays.asList(mainClassField, targetDirectoryField);
+ private final List> fields = Arrays.asList(
+ new Field<>(TeaVMConfiguration::setEnabled, TeaVMConfiguration::isEnabled,
+ enabledCheckBox::setSelected, enabledCheckBox::isSelected),
+ new Field<>(TeaVMConfiguration::setMainClass, TeaVMConfiguration::getMainClass,
+ mainClassField::setText, mainClassField::getText),
+ new Field<>(TeaVMConfiguration::setTargetDirectory, TeaVMConfiguration::getTargetDirectory,
+ targetDirectoryField::setText, targetDirectoryField::getText)
+ );
+
+ TeaVMConfigurationPanel() {
+ enabledCheckBox.addActionListener(event -> updateEnabledState());
+ setupLayout();
+ }
+
+ private void setupLayout() {
+ setLayout(new GridBagLayout());
+
+ GridBagConstraints constraints = new GridBagConstraints();
+ constraints.gridwidth = GridBagConstraints.REMAINDER;
+ add(enabledCheckBox, constraints);
+
+ constraints.gridwidth = GridBagConstraints.RELATIVE;
+ add(new JLabel("Main class:"), constraints);
+ constraints.gridwidth = GridBagConstraints.REMAINDER;
+ add(mainClassField, constraints);
+
+ constraints.gridwidth = GridBagConstraints.RELATIVE;
+ add(new JLabel("Target directory:"), constraints);
+ constraints.gridwidth = GridBagConstraints.REMAINDER;
+ add(targetDirectoryField, constraints);
+ }
+
+ public void load(TeaVMConfiguration config) {
+ if (config == null) {
+ config = new TeaVMConfiguration();
+ }
+ updateInitialConfiguration(config);
+ for (Field> field : fields) {
+ loadField(field, config);
+ }
+ updateEnabledState();
+ }
+
+ public void save(TeaVMConfiguration config) {
+ for (Field> field : fields) {
+ saveField(field, config);
+ }
+ updateInitialConfiguration(config);
+ }
+
+ private void loadField(Field field, TeaVMConfiguration config) {
+ field.editConsumer.accept(field.dataSupplier.apply(config));
+ }
+
+ private void saveField(Field field, TeaVMConfiguration config) {
+ field.dataConsumer.accept(config, field.editSupplier.get());
+ }
+
+ private void updateEnabledState() {
+ for (JComponent component : editComponents) {
+ component.setEnabled(enabledCheckBox.isSelected());
+ }
+ }
+
+ public boolean isModified() {
+ return fields.stream().anyMatch(this::isFieldModified);
+ }
+
+ private boolean isFieldModified(Field field) {
+ return !Objects.equals(field.dataSupplier.apply(initialConfiguration), field.editSupplier.get());
+ }
+
+ private void updateInitialConfiguration(TeaVMConfiguration config) {
+ initialConfiguration.setEnabled(config.isEnabled());
+ initialConfiguration.setMainClass(config.getMainClass());
+ initialConfiguration.setTargetDirectory(config.getTargetDirectory());
+ }
+
+ static class Field {
+ final BiConsumer dataConsumer;
+ final Function dataSupplier;
+ final Consumer editConsumer;
+ final Supplier editSupplier;
+
+ public Field(BiConsumer dataConsumer, Function dataSupplier,
+ Consumer editConsumer, Supplier editSupplier) {
+ this.dataConsumer = dataConsumer;
+ this.dataSupplier = dataSupplier;
+ this.editConsumer = editConsumer;
+ this.editSupplier = editSupplier;
+ }
+ }
+}
diff --git a/tools/idea/src/main/resources/META-INF/plugin.xml b/tools/idea/src/main/resources/META-INF/plugin.xml
index 68ae2627b..82d6ef691 100644
--- a/tools/idea/src/main/resources/META-INF/plugin.xml
+++ b/tools/idea/src/main/resources/META-INF/plugin.xml
@@ -15,21 +15,20 @@
]]>
-
-
-
-
-
+
+
-
+
+
+ org.teavm.idea.TeaVMConfigurationStorage
+
+
\ No newline at end of file