diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java index 373a17dd804..2b792f2bd76 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java @@ -28,6 +28,7 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.plugin.JetPluginUtil; import org.jetbrains.jet.plugin.framework.ui.CreateJavaScriptLibraryDialog; import org.jetbrains.jet.plugin.framework.ui.FileUIUtils; import org.jetbrains.jet.utils.KotlinPaths; @@ -59,10 +60,7 @@ public class JSLibraryDescription extends CustomLibraryDescription { dialog.show(); if (dialog.isOK()) { - String standaloneCompilerPath = dialog.getStandaloneCompilerPath(); - KotlinPaths paths = standaloneCompilerPath == null ? - PathUtil.getKotlinPathsForIdeaPlugin() : - PathUtil.getKotlinStandaloneCompilerPaths(standaloneCompilerPath); + KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin(); File libraryFile = paths.getJsLibJarPath(); if (!libraryFile.exists()) { @@ -71,6 +69,8 @@ public class JSLibraryDescription extends CustomLibraryDescription { return null; } + String libraryName = LIBRARY_NAME; + String copyIntoPath = dialog.getCopyIntoPath(); if (copyIntoPath != null) { List copyFiles = new ArrayList(); @@ -86,11 +86,12 @@ public class JSLibraryDescription extends CustomLibraryDescription { if (dialog.isCopyLibraryFiles()) { libraryFile = copiedFiles.get(libraryFile); + libraryName = LIBRARY_NAME + "-" + JetPluginUtil.getPluginVersion(); } } final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile); - return new NewLibraryConfiguration(LIBRARY_NAME + "-" + dialog.getVersion(), getDownloadableLibraryType(), new LibraryVersionProperties()) { + return new NewLibraryConfiguration(libraryName, getDownloadableLibraryType(), new LibraryVersionProperties()) { @Override public void addRoots(@NotNull LibraryEditor editor) { editor.addRoot(libraryFileUrl, OrderRootType.SOURCES); diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java index 7fca101ea8e..961baf0753f 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java @@ -28,6 +28,7 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.plugin.JetPluginUtil; import org.jetbrains.jet.plugin.framework.ui.CreateJavaLibraryDialog; import org.jetbrains.jet.plugin.framework.ui.FileUIUtils; import org.jetbrains.jet.utils.KotlinPaths; @@ -56,10 +57,7 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription { dialog.show(); if (dialog.isOK()) { - String standaloneCompilerPath = dialog.getStandaloneCompilerPath(); - KotlinPaths paths = standaloneCompilerPath == null ? - PathUtil.getKotlinPathsForIdeaPlugin() : - PathUtil.getKotlinStandaloneCompilerPaths(standaloneCompilerPath); + KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin(); File libraryFile = paths.getRuntimePath(); if (!libraryFile.exists()) { @@ -70,16 +68,20 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription { return null; } + String libraryName = LIBRARY_NAME; + String copyIntoPath = dialog.getCopyIntoPath(); if (copyIntoPath != null) { libraryFile = FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_RUNTIME_LIBRARY_CREATION, copyIntoPath, libraryFile); if (libraryFile == null) { return null; } + + libraryName = LIBRARY_NAME + "-" + JetPluginUtil.getPluginVersion(); } final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile); - return new NewLibraryConfiguration(LIBRARY_NAME + "-" + dialog.getVersion(), getDownloadableLibraryType(), new LibraryVersionProperties()) { + return new NewLibraryConfiguration(libraryName, getDownloadableLibraryType(), new LibraryVersionProperties()) { @Override public void addRoots(@NotNull LibraryEditor editor) { editor.addRoot(libraryFileUrl, OrderRootType.CLASSES); diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.form b/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.form index f544431b398..5afdfab82c4 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.form +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.form @@ -1,6 +1,6 @@
- + @@ -8,33 +8,17 @@ - - - - - - - - - - + - + - - - - - - - + - - + diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.java index 8e59672d086..f00710f2ad5 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.java @@ -16,150 +16,19 @@ package org.jetbrains.jet.plugin.framework.ui; -import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.TextFieldWithBrowseButton; -import com.intellij.openapi.util.io.FileUtilRt; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.DocumentAdapter; -import com.intellij.util.EventDispatcher; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.plugin.JetPluginUtil; -import org.jetbrains.jet.utils.KotlinPaths; -import org.jetbrains.jet.utils.PathUtil; import javax.swing.*; -import javax.swing.event.DocumentEvent; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; public class ChooseCompilerSourcePanel { - private JRadioButton useBundledKotlinRadioButton; - private JRadioButton useStandaloneKotlinRadioButton; - private TextFieldWithBrowseButton kotlinStandalonePathField; private JPanel contentPane; + private JLabel bundledPluginVersion; - private final EventDispatcher validityDispatcher = EventDispatcher.create(ValidityListener.class); - - private boolean hasErrorsState = false; - private String version = null; - private final String initialStandaloneLabelText; - - public ChooseCompilerSourcePanel(@Nullable Project project) { - useBundledKotlinRadioButton.setText(useBundledKotlinRadioButton.getText() + " - " + JetPluginUtil.getPluginVersion()); - - initialStandaloneLabelText = useStandaloneKotlinRadioButton.getText(); - - kotlinStandalonePathField.setEditable(false); - kotlinStandalonePathField.addBrowseFolderListener( - "Kotlin Compiler", "Choose folder with Kotlin compiler installation", project, - new FileChooserDescriptor(false, true, false, false, false, false) { - @Override - public boolean isFileSelectable(VirtualFile file) { - if (!super.isFileSelectable(file)) { - return false; - } - - return PathUtil.KOTLIN_HOME_DIRECTORY_FINDER.fun(com.intellij.util.PathUtil.getLocalPath(file)) != null; - } - }); - - kotlinStandalonePathField.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { - @Override - protected void textChanged(final DocumentEvent e) { - updateStandaloneVersion(); - updateComponents(); - } - }); - - useStandaloneKotlinRadioButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(@NotNull ActionEvent e) { - updateComponents(); - } - }); - useBundledKotlinRadioButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(@NotNull ActionEvent e) { - updateComponents(); - } - }); - - updateStandaloneVersion(); - updateComponents(); - } - - public void addValidityListener(ValidityListener listener) { - validityDispatcher.addListener(listener); - } - - public boolean hasErrors() { - return hasErrorsState; - } - - @Nullable - public String getStandaloneCompilerPath() { - if (useStandaloneKotlinRadioButton.isSelected()) { - return kotlinStandalonePathField.getText().trim(); - } - - return null; - } - - @NotNull - public String getVersion() { - if (useBundledKotlinRadioButton.isSelected()) { - return JetPluginUtil.getPluginVersion(); - } - else { - assert version != null: "It shouldn't be possible to finish dialog with invalid version"; - return version; - } + public ChooseCompilerSourcePanel() { + bundledPluginVersion.setText(bundledPluginVersion.getText() + " - " + JetPluginUtil.getPluginVersion()); } public JPanel getContentPane() { return contentPane; } - - private void updateComponents() { - boolean isError = false; - - kotlinStandalonePathField.setEnabled(useStandaloneKotlinRadioButton.isSelected()); - - useStandaloneKotlinRadioButton.setForeground(Color.BLACK); - useStandaloneKotlinRadioButton.setText(initialStandaloneLabelText); - if (useStandaloneKotlinRadioButton.isSelected()) { - if (version != null) { - useStandaloneKotlinRadioButton.setText(initialStandaloneLabelText + " - " + version); - } - else { - useStandaloneKotlinRadioButton.setForeground(Color.RED); - useStandaloneKotlinRadioButton.setText(initialStandaloneLabelText + " - " + "Invalid Version"); - isError = true; - } - } - - if (hasErrorsState != isError) { - hasErrorsState = isError; - validityDispatcher.getMulticaster().validityChanged(isError); - } - } - - private void updateStandaloneVersion() { - if (useStandaloneKotlinRadioButton.isSelected()) { - KotlinPaths paths = PathUtil.getKotlinStandaloneCompilerPaths(kotlinStandalonePathField.getTextField().getText().trim()); - try { - version = FileUtilRt.loadFile(paths.getBuildVersionFile()); - return; - } - catch (IOException e) { - // Do nothing. Version will be set to null. - } - } - - version = null; - } } diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form index 10a20eda205..38dde0bf676 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form @@ -26,7 +26,7 @@ - + diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java index b0463143cdc..316420d37e0 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java @@ -28,7 +28,6 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class CreateJavaLibraryDialog extends DialogWrapper { - private final ChooseCompilerSourcePanel compilerSourcePanel; private final CopyIntoPanel copyIntoPanel; private JPanel contentPane; @@ -43,13 +42,7 @@ public class CreateJavaLibraryDialog extends DialogWrapper { init(); - compilerSourcePanel = new ChooseCompilerSourcePanel(project); - compilerSourcePanel.addValidityListener(new ValidityListener() { - @Override - public void validityChanged(boolean isValid) { - updateComponents(); - } - }); + ChooseCompilerSourcePanel compilerSourcePanel = new ChooseCompilerSourcePanel(); compilerSourcePanelPlace.add(compilerSourcePanel.getContentPane(), BorderLayout.CENTER, 0); copyIntoPanel = new CopyIntoPanel(project, contextDirectory); @@ -61,8 +54,6 @@ public class CreateJavaLibraryDialog extends DialogWrapper { }); copyIntoPanelPlace.add(copyIntoPanel.getContentPane(), BorderLayout.CENTER); - contentPane.setMinimumSize(new Dimension(380, 180)); - copyLibraryCheckbox.addActionListener(new ActionListener() { @Override public void actionPerformed(@NotNull ActionEvent e) { @@ -73,24 +64,14 @@ public class CreateJavaLibraryDialog extends DialogWrapper { updateComponents(); } - @Nullable - public String getStandaloneCompilerPath() { - return compilerSourcePanel.getStandaloneCompilerPath(); - } - @Nullable public String getCopyIntoPath() { return copyIntoPanel.getPath(); } - @NotNull - public String getVersion() { - return compilerSourcePanel.getVersion(); - } - private void updateComponents() { copyIntoPanel.setEnabled(copyLibraryCheckbox.isSelected()); - setOKActionEnabled(!(compilerSourcePanel.hasErrors() || copyIntoPanel.hasErrors())); + setOKActionEnabled(!copyIntoPanel.hasErrors()); } @Nullable diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java index d3b1f4c513b..e5c9d93a200 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java @@ -12,7 +12,6 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class CreateJavaScriptLibraryDialog extends DialogWrapper { - private final ChooseCompilerSourcePanel compilerSourcePanel; private final CopyIntoPanel copyIntoPanel; private JPanel contentPane; @@ -28,13 +27,7 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper { init(); - compilerSourcePanel = new ChooseCompilerSourcePanel(project); - compilerSourcePanel.addValidityListener(new ValidityListener() { - @Override - public void validityChanged(boolean isValid) { - updateComponents(); - } - }); + ChooseCompilerSourcePanel compilerSourcePanel = new ChooseCompilerSourcePanel(); compilerSourcePanelPlace.add(compilerSourcePanel.getContentPane(), BorderLayout.CENTER); copyIntoPanel = new CopyIntoPanel(project, contextDirectory); @@ -46,8 +39,6 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper { }); copyIntoPanelPlace.add(copyIntoPanel.getContentPane(), BorderLayout.CENTER); - contentPane.setMinimumSize(new Dimension(380, 180)); - ActionListener updateComponentsListener = new ActionListener() { @Override public void actionPerformed(@NotNull ActionEvent e) { @@ -61,11 +52,6 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper { updateComponents(); } - @Nullable - public String getStandaloneCompilerPath() { - return compilerSourcePanel.getStandaloneCompilerPath(); - } - @Nullable public String getCopyIntoPath() { return copyIntoPanel.getPath(); @@ -79,16 +65,11 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper { return ECMAScript3JavaScriptRuntimeCheckBox.isSelected(); } - @NotNull - public String getVersion() { - return compilerSourcePanel.getVersion(); - } - private void updateComponents() { copyIntoPanel.setEnabled(copyLibraryCheckbox.isSelected() || ECMAScript3JavaScriptRuntimeCheckBox.isSelected()); - setOKActionEnabled(!(compilerSourcePanel.hasErrors() || copyIntoPanel.hasErrors())); + setOKActionEnabled(!copyIntoPanel.hasErrors()); } @Nullable