From 49a864846b05423a0244eb68b0f11125a215ecac Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 1 Mar 2013 14:13:52 +0400 Subject: [PATCH] GUI for copy ecma 3 file --- .../framework/JSLibraryDescription.java | 40 ++--- .../JavaRuntimeLibraryDescription.java | 6 +- .../ui/ChooseCompilerSourcePanel.form | 48 ++++++ ...og.java => ChooseCompilerSourcePanel.java} | 148 ++++++++---------- .../plugin/framework/ui/CopyIntoPanel.form | 32 ++++ .../plugin/framework/ui/CopyIntoPanel.java | 95 +++++++++++ .../framework/ui/CreateJavaLibraryDialog.form | 58 +++++++ .../framework/ui/CreateJavaLibraryDialog.java | 101 ++++++++++++ ...orm => CreateJavaScriptLibraryDialog.form} | 67 ++++---- .../ui/CreateJavaScriptLibraryDialog.java | 99 ++++++++++++ .../jet/plugin/framework/ui/FileUIUtils.java | 95 ++++++++--- .../plugin/framework/ui/ValidityListener.java | 23 +++ 12 files changed, 639 insertions(+), 173 deletions(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.form rename idea/src/org/jetbrains/jet/plugin/framework/ui/{CreateLibrarySourceDialog.java => ChooseCompilerSourcePanel.java} (69%) create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.form create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.java create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java rename idea/src/org/jetbrains/jet/plugin/framework/ui/{CreateLibrarySourceDialog.form => CreateJavaScriptLibraryDialog.form} (55%) create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/ui/ValidityListener.java diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java index ef9f428cd55..373a17dd804 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java @@ -24,21 +24,20 @@ import com.intellij.openapi.roots.libraries.NewLibraryConfiguration; import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.LocalFileSystem; 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.CreateLibrarySourceDialog; +import org.jetbrains.jet.plugin.framework.ui.CreateJavaScriptLibraryDialog; import org.jetbrains.jet.plugin.framework.ui.FileUIUtils; import org.jetbrains.jet.utils.KotlinPaths; import org.jetbrains.jet.utils.PathUtil; import javax.swing.*; import java.io.File; -import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import java.util.Set; public class JSLibraryDescription extends CustomLibraryDescription { @@ -56,7 +55,7 @@ public class JSLibraryDescription extends CustomLibraryDescription { @Nullable @Override public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) { - CreateLibrarySourceDialog dialog = new CreateLibrarySourceDialog(null, "Create Kotlin JavaScript Library", contextDirectory); + CreateJavaScriptLibraryDialog dialog = new CreateJavaScriptLibraryDialog(null, "Create Kotlin JavaScript Library", contextDirectory); dialog.show(); if (dialog.isOK()) { @@ -74,12 +73,20 @@ public class JSLibraryDescription extends CustomLibraryDescription { String copyIntoPath = dialog.getCopyIntoPath(); if (copyIntoPath != null) { - libraryFile = FileUIUtils.copyWithOverwriteDialog(parentComponent, copyIntoPath, libraryFile, JAVA_SCRIPT_LIBRARY_CREATION); - if (libraryFile == null) { + List copyFiles = new ArrayList(); + + if (dialog.isCopyLibraryFiles()) copyFiles.add(libraryFile); + if (dialog.isCopyECMA3()) copyFiles.add(paths.getJsLibJsPath()); + + Map copiedFiles = + FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyIntoPath, copyFiles); + if (copiedFiles == null) { return null; } - copyJsRuntimeFile(copyIntoPath); + if (dialog.isCopyLibraryFiles()) { + libraryFile = copiedFiles.get(libraryFile); + } } final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile); @@ -93,19 +100,4 @@ public class JSLibraryDescription extends CustomLibraryDescription { return null; } - - private static void copyJsRuntimeFile(@NotNull String directoryPath) { - File file = PathUtil.getKotlinPathsForIdeaPlugin().getJsLibJsPath(); - - File folder = new File(directoryPath); - File targetFile = new File(folder, file.getName()); - - try { - FileUtil.copy(file, targetFile); - LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetFile); - } - catch (IOException e) { - // Do nothing. This is a very temp code and should be removed. - } - } } diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java index d13e9a1313c..7fca101ea8e 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java @@ -28,7 +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.framework.ui.CreateLibrarySourceDialog; +import org.jetbrains.jet.plugin.framework.ui.CreateJavaLibraryDialog; import org.jetbrains.jet.plugin.framework.ui.FileUIUtils; import org.jetbrains.jet.utils.KotlinPaths; import org.jetbrains.jet.utils.PathUtil; @@ -52,7 +52,7 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription { @Nullable @Override public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) { - CreateLibrarySourceDialog dialog = new CreateLibrarySourceDialog(null, "Create Kotlin Java Runtime Library", contextDirectory); + CreateJavaLibraryDialog dialog = new CreateJavaLibraryDialog(null, "Create Kotlin Java Runtime Library", contextDirectory); dialog.show(); if (dialog.isOK()) { @@ -72,7 +72,7 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription { String copyIntoPath = dialog.getCopyIntoPath(); if (copyIntoPath != null) { - libraryFile = FileUIUtils.copyWithOverwriteDialog(parentComponent, copyIntoPath, libraryFile, JAVA_RUNTIME_LIBRARY_CREATION); + libraryFile = FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_RUNTIME_LIBRARY_CREATION, copyIntoPath, libraryFile); if (libraryFile == null) { return null; } diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.form b/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.form new file mode 100644 index 00000000000..f544431b398 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.form @@ -0,0 +1,48 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibrarySourceDialog.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.java similarity index 69% rename from idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibrarySourceDialog.java rename to idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.java index f6dce7ce1f8..369871c4864 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibrarySourceDialog.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/ChooseCompilerSourcePanel.java @@ -1,13 +1,28 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * 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.jetbrains.jet.plugin.framework.ui; import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; 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; @@ -21,27 +36,19 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; -public class CreateLibrarySourceDialog extends DialogWrapper { - private JPanel contentPane; - private JRadioButton useStandaloneKotlinRadioButton; +public class ChooseCompilerSourcePanel { private JRadioButton useBundledKotlinRadioButton; - private JCheckBox copyLibraryCheckbox; - private TextFieldWithBrowseButton copyIntoDirectoryField; + private JRadioButton useStandaloneKotlinRadioButton; private TextFieldWithBrowseButton kotlinStandalonePathField; + private JPanel contentPane; + private final EventDispatcher validityDispatcher = EventDispatcher.create(ValidityListener.class); + + private boolean hasErrorsState = false; private String version = null; - private final String initialStandaloneLabelText; - public CreateLibrarySourceDialog(@Nullable Project project, @NotNull String title, VirtualFile contextDirectory) { - super(project); - - setTitle(title); - - init(); - - contentPane.setMinimumSize(new Dimension(380, 180)); - + public ChooseCompilerSourcePanel(@Nullable Project project) { useBundledKotlinRadioButton.setText(useBundledKotlinRadioButton.getText() + " - " + JetPluginUtil.getPluginVersion()); initialStandaloneLabelText = useStandaloneKotlinRadioButton.getText(); @@ -64,30 +71,10 @@ public class CreateLibrarySourceDialog extends DialogWrapper { @Override protected void textChanged(final DocumentEvent e) { updateStandaloneVersion(); - updateComponentVersion(); - } - }); - - updateStandaloneVersion(); - - copyIntoDirectoryField.addBrowseFolderListener( - "Copy Into...", "Choose folder where files will be copied", project, - FileChooserDescriptorFactory.createSingleFolderDescriptor()); - copyIntoDirectoryField.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { - @Override - protected void textChanged(final DocumentEvent e) { - updateComponentVersion(); - } - }); - - copyIntoDirectoryField.getTextField().setText(FileUIUtils.getDefaultLibraryFolder(project, contextDirectory)); - - copyLibraryCheckbox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(@NotNull ActionEvent e) { updateComponents(); } }); + useStandaloneKotlinRadioButton.addActionListener(new ActionListener() { @Override public void actionPerformed(@NotNull ActionEvent e) { @@ -101,9 +88,18 @@ public class CreateLibrarySourceDialog extends DialogWrapper { } }); + updateStandaloneVersion(); updateComponents(); } + public void addValidityListener(ValidityListener listener) { + validityDispatcher.addListener(listener); + } + + public boolean hasErrors() { + return hasErrorsState; + } + @Nullable public String getStandaloneCompilerPath() { if (useStandaloneKotlinRadioButton.isSelected()) { @@ -113,15 +109,6 @@ public class CreateLibrarySourceDialog extends DialogWrapper { return null; } - @Nullable - public String getCopyIntoPath() { - if (copyLibraryCheckbox.isSelected()) { - return copyIntoDirectoryField.getText().trim(); - } - - return null; - } - @NotNull public String getVersion() { if (useBundledKotlinRadioButton.isSelected()) { @@ -133,6 +120,34 @@ public class CreateLibrarySourceDialog extends DialogWrapper { } } + 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()); @@ -147,43 +162,4 @@ public class CreateLibrarySourceDialog extends DialogWrapper { version = null; } - - private void updateComponentVersion() { - boolean isError = false; - - 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; - } - } - - copyLibraryCheckbox.setForeground(Color.BLACK); - if (copyLibraryCheckbox.isSelected()) { - if (copyIntoDirectoryField.getText().trim().isEmpty()) { - copyLibraryCheckbox.setForeground(Color.RED); - isError = true; - } - } - - setOKActionEnabled(!isError); - } - - private void updateComponents() { - kotlinStandalonePathField.setEnabled(useStandaloneKotlinRadioButton.isSelected()); - copyIntoDirectoryField.setEnabled(copyLibraryCheckbox.isSelected()); - updateComponentVersion(); - } - - @Nullable - @Override - protected JComponent createCenterPanel() { - return contentPane; - } } diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.form b/idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.form new file mode 100644 index 00000000000..1c663110868 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.form @@ -0,0 +1,32 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.java new file mode 100644 index 00000000000..30ba39c551c --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CopyIntoPanel.java @@ -0,0 +1,95 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * 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.jetbrains.jet.plugin.framework.ui; + +import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.TextFieldWithBrowseButton; +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 javax.swing.*; +import javax.swing.event.DocumentEvent; +import java.awt.*; + +public class CopyIntoPanel { + private JPanel contentPane; + private TextFieldWithBrowseButton copyIntoField; + private JLabel copyIntoLabel; + + private final EventDispatcher validityDispatcher = EventDispatcher.create(ValidityListener.class); + + private boolean hasErrorsState; + + public CopyIntoPanel(@Nullable Project project, @NotNull VirtualFile contextDirectory) { + copyIntoField.addBrowseFolderListener( + "Copy Into...", "Choose folder where files will be copied", project, + FileChooserDescriptorFactory.createSingleFolderDescriptor()); + copyIntoField.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { + @Override + protected void textChanged(final DocumentEvent e) { + updateComponents(); + } + }); + + copyIntoLabel.setLabelFor(copyIntoField.getTextField()); + copyIntoField.getTextField().setText(FileUIUtils.getDefaultLibraryFolder(project, contextDirectory)); + + updateComponents(); + } + + public JComponent getContentPane() { + return contentPane; + } + + public void addValidityListener(ValidityListener listener) { + validityDispatcher.addListener(listener); + } + + @Nullable + public String getPath() { + return copyIntoField.isEnabled() ? copyIntoField.getText().trim() : null; + } + + private void updateComponents() { + boolean isError = false; + + copyIntoLabel.setForeground(Color.BLACK); + if (copyIntoField.isEnabled()) { + if (copyIntoField.getText().trim().isEmpty()) { + copyIntoLabel.setForeground(Color.RED); + isError = true; + } + } + + if (isError != hasErrorsState) { + hasErrorsState = isError; + validityDispatcher.getMulticaster().validityChanged(isError); + } + } + + public void setEnabled(boolean enabled) { + copyIntoField.setEnabled(enabled); + } + + public boolean hasErrors() { + return hasErrorsState; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form new file mode 100644 index 00000000000..10a20eda205 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.form @@ -0,0 +1,58 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java new file mode 100644 index 00000000000..b0463143cdc --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaLibraryDialog.java @@ -0,0 +1,101 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * 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.jetbrains.jet.plugin.framework.ui; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; +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; + private JCheckBox copyLibraryCheckbox; + private JPanel copyIntoPanelPlace; + private JPanel compilerSourcePanelPlace; + + public CreateJavaLibraryDialog(@Nullable Project project, @NotNull String title, VirtualFile contextDirectory) { + super(project); + + setTitle(title); + + init(); + + compilerSourcePanel = new ChooseCompilerSourcePanel(project); + compilerSourcePanel.addValidityListener(new ValidityListener() { + @Override + public void validityChanged(boolean isValid) { + updateComponents(); + } + }); + compilerSourcePanelPlace.add(compilerSourcePanel.getContentPane(), BorderLayout.CENTER, 0); + + copyIntoPanel = new CopyIntoPanel(project, contextDirectory); + copyIntoPanel.addValidityListener(new ValidityListener() { + @Override + public void validityChanged(boolean isValid) { + updateComponents(); + } + }); + copyIntoPanelPlace.add(copyIntoPanel.getContentPane(), BorderLayout.CENTER); + + contentPane.setMinimumSize(new Dimension(380, 180)); + + copyLibraryCheckbox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(@NotNull ActionEvent e) { + updateComponents(); + } + }); + + 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())); + } + + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibrarySourceDialog.form b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.form similarity index 55% rename from idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibrarySourceDialog.form rename to idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.form index cf4e02f34ed..110391d2add 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibrarySourceDialog.form +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.form @@ -1,6 +1,6 @@ -
- + + @@ -8,67 +8,62 @@ - - - - - - - - - - + - - + + - + - - - - - - - + - + - + - + - + + + + + + + + + + - + - - - - - - - + - - + + + + + + + + + diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java new file mode 100644 index 00000000000..d3b1f4c513b --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java @@ -0,0 +1,99 @@ +package org.jetbrains.jet.plugin.framework.ui; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; +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; + private JCheckBox copyLibraryCheckbox; + private JCheckBox ECMAScript3JavaScriptRuntimeCheckBox; + private JPanel compilerSourcePanelPlace; + private JPanel copyIntoPanelPlace; + + public CreateJavaScriptLibraryDialog(@Nullable Project project, @NotNull String title, VirtualFile contextDirectory) { + super(project); + + setTitle(title); + + init(); + + compilerSourcePanel = new ChooseCompilerSourcePanel(project); + compilerSourcePanel.addValidityListener(new ValidityListener() { + @Override + public void validityChanged(boolean isValid) { + updateComponents(); + } + }); + compilerSourcePanelPlace.add(compilerSourcePanel.getContentPane(), BorderLayout.CENTER); + + copyIntoPanel = new CopyIntoPanel(project, contextDirectory); + copyIntoPanel.addValidityListener(new ValidityListener() { + @Override + public void validityChanged(boolean isValid) { + updateComponents(); + } + }); + copyIntoPanelPlace.add(copyIntoPanel.getContentPane(), BorderLayout.CENTER); + + contentPane.setMinimumSize(new Dimension(380, 180)); + + ActionListener updateComponentsListener = new ActionListener() { + @Override + public void actionPerformed(@NotNull ActionEvent e) { + updateComponents(); + } + }; + + copyLibraryCheckbox.addActionListener(updateComponentsListener); + ECMAScript3JavaScriptRuntimeCheckBox.addActionListener(updateComponentsListener); + + updateComponents(); + } + + @Nullable + public String getStandaloneCompilerPath() { + return compilerSourcePanel.getStandaloneCompilerPath(); + } + + @Nullable + public String getCopyIntoPath() { + return copyIntoPanel.getPath(); + } + + public boolean isCopyLibraryFiles() { + return copyLibraryCheckbox.isSelected(); + } + + public boolean isCopyECMA3() { + return ECMAScript3JavaScriptRuntimeCheckBox.isSelected(); + } + + @NotNull + public String getVersion() { + return compilerSourcePanel.getVersion(); + } + + private void updateComponents() { + copyIntoPanel.setEnabled(copyLibraryCheckbox.isSelected() || + ECMAScript3JavaScriptRuntimeCheckBox.isSelected()); + + setOKActionEnabled(!(compilerSourcePanel.hasErrors() || copyIntoPanel.hasErrors())); + } + + @Nullable + @Override + protected JComponent createCenterPanel() { + return contentPane; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/FileUIUtils.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/FileUIUtils.java index 065e3267b78..3105059e3f8 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/FileUIUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/FileUIUtils.java @@ -16,10 +16,14 @@ package org.jetbrains.jet.plugin.framework.ui; +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; +import com.google.common.collect.ImmutableList; import com.intellij.ide.util.projectWizard.ProjectWizardUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.PathUtil; @@ -30,6 +34,8 @@ import javax.swing.*; import java.awt.*; import java.io.File; import java.io.IOException; +import java.util.*; +import java.util.List; public class FileUIUtils { private FileUIUtils() { @@ -38,43 +44,84 @@ public class FileUIUtils { @Nullable public static File copyWithOverwriteDialog( @NotNull Component parent, + @NotNull String messagesTitle, @NotNull String destinationFolder, - @NotNull File file, - @NotNull String messagesTitle) { + @NotNull File file) { + Map copiedFiles = copyWithOverwriteDialog(parent, messagesTitle, destinationFolder, ImmutableList.of(file)); + if (copiedFiles == null) { + return null; + } + + File copy = copiedFiles.get(file); + assert copy != null; + + return copy; + } + + @Nullable + public static Map copyWithOverwriteDialog( + @NotNull Component parent, + @NotNull String messagesTitle, + @NotNull String destinationFolder, + @NotNull List files + ) { if (!ProjectWizardUtil.createDirectoryIfNotExists("Destination folder", destinationFolder, false)) { Messages.showErrorDialog(String.format("Error during folder creating '%s'", destinationFolder), messagesTitle + ". Error"); return null; } - + File folder = new File(destinationFolder); - File targetFile = new File(folder, file.getName()); - assert folder.exists(); + Set fileNames = new HashSet(); + Map targetFiles = new LinkedHashMap(files.size()); + for (File file : files) { + String fileName = file.getName(); - try { - if (!targetFile.exists()) { - FileUtil.copy(file, targetFile); - } - else { - int replaceIfExist = Messages.showYesNoDialog( - parent, - String.format("File \"%s\" is already exist in %s.\nDo you want to rewrite it?", targetFile.getName(), folder.getAbsolutePath()), - messagesTitle + ". Replace File", - Messages.getWarningIcon()); - - if (replaceIfExist == JOptionPane.YES_OPTION) { - FileUtil.copy(file, targetFile); - } + if (!fileNames.add(fileName)) { + throw new IllegalArgumentException("There are several files with the same name: " + fileName); } - LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetFile); + targetFiles.put(file, new File(folder, fileName)); + } - return targetFile; + Collection existentFiles = Collections2.filter(targetFiles.values(), new Predicate() { + @Override + public boolean apply(@Nullable File file) { + assert file != null; + return file.exists(); + } + }); + + if (!existentFiles.isEmpty()) { + String message = existentFiles.size() == 1 ? + String.format("File \"%s\" is already exist in %s.\nDo you want to overwrite it?", existentFiles.iterator().next().getName(), folder.getAbsolutePath()) : + String.format("Several files are already exist in %s:\n%s\nDo you want to overwrite them?", folder.getAbsolutePath(), StringUtil.join(existentFiles, "\n")); + + int replaceIfExist = Messages.showYesNoDialog( + null, + message, + messagesTitle + ". Replace File", + "Overwrite", + "Cancel", + Messages.getWarningIcon()); + + if (replaceIfExist != JOptionPane.YES_OPTION) { + return null; + } } - catch (IOException e) { - Messages.showErrorDialog("Error during file copy", messagesTitle + ". Error"); - return null; + + for (Map.Entry sourceToTarget : targetFiles.entrySet()) { + try { + FileUtil.copy(sourceToTarget.getKey(), sourceToTarget.getValue()); + LocalFileSystem.getInstance().refreshAndFindFileByIoFile(sourceToTarget.getValue()); + } + catch (IOException e) { + Messages.showErrorDialog(parent, "Error with copy file " + sourceToTarget.getKey().getName(), messagesTitle + ". Error"); + return null; + } } + + return targetFiles; } @NotNull diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/ValidityListener.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/ValidityListener.java new file mode 100644 index 00000000000..0e47d200f99 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/ValidityListener.java @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * 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.jetbrains.jet.plugin.framework.ui; + +import java.util.EventListener; + +public interface ValidityListener extends EventListener { + void validityChanged(boolean isValid); +} \ No newline at end of file