From 8f0fd533ba0f2f38ee4a5de7019e47f5c4e2ae60 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Mon, 27 May 2013 17:48:28 +0400 Subject: [PATCH] IDEA-104500 Gradle: Allow to reuse common logic for other external systems 1. Fold external project path to the project name on external system run configuration dialog opening; 2. Correct external system run configuration settings deserialization; --- .../ExternalSystemTaskExecutionSettings.java | 3 +- .../ExternalSystemTaskSettingsControl.java | 47 ++---------- .../service/ui/ExternalProjectPathField.java | 72 +++++++++++++++++-- .../util/TextFieldCompletionProvider.java | 20 ++++++ 4 files changed, 92 insertions(+), 50 deletions(-) diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java index 66b3ef91ffac..dfc54db28ff6 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java @@ -71,8 +71,7 @@ public class ExternalSystemTaskExecutionSettings implements Cloneable { } public void setTaskNames(List taskNames) { - myTaskNames.clear(); - myTaskNames.addAll(taskNames); + myTaskNames = taskNames; } @Override diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskSettingsControl.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskSettingsControl.java index c36d1a623711..6f6902654429 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskSettingsControl.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskSettingsControl.java @@ -15,7 +15,6 @@ */ package com.intellij.openapi.externalSystem.service.execution; -import com.intellij.openapi.editor.Editor; import com.intellij.openapi.externalSystem.ExternalSystemManager; import com.intellij.openapi.externalSystem.ExternalSystemUiAware; import com.intellij.openapi.externalSystem.model.ProjectSystemId; @@ -30,11 +29,10 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.RawCommandLineEditor; import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBTextField; -import com.intellij.util.Consumer; +import com.intellij.util.ui.GridBag; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.*; import java.awt.*; import static com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.normalizePath; @@ -94,52 +92,15 @@ public class ExternalSystemTaskSettingsControl implements ExternalSystemSettings myTasksLabel = new JBLabel(ExternalSystemBundle.message("run.configuration.settings.label.tasks")); myTasksTextField = new JBTextField(ExternalSystemConstants.TEXT_FIELD_WIDTH_IN_COLUMNS); canvas.add(myTasksLabel, ExternalSystemUiUtil.getLabelConstraints(0)); - canvas.add(myTasksTextField, ExternalSystemUiUtil.getFillLineConstraints(0)); + GridBag c = ExternalSystemUiUtil.getFillLineConstraints(0); + c.insets.right = myProjectPathField.getButton().getPreferredSize().width + 8 /* street magic, sorry */; + canvas.add(myTasksTextField, c); myVmOptionsLabel = new JBLabel(ExternalSystemBundle.message("run.configuration.settings.label.vmoptions")); myVmOptionsEditor = new RawCommandLineEditor(); myVmOptionsEditor.setDialogCaption(ExternalSystemBundle.message("run.configuration.settings.caption.vmoptions")); canvas.add(myVmOptionsLabel, ExternalSystemUiUtil.getLabelConstraints(0)); canvas.add(myVmOptionsEditor, ExternalSystemUiUtil.getFillLineConstraints(0)); - - canvas.setPaintCallback(new Consumer() { - - @Nullable private Dimension myDimension; - @Nullable private Dimension myBounds; - private boolean myBorderReset; - - @Override - public void consume(Graphics graphics) { - if (!myBorderReset) { - Editor editor = myProjectPathField.getChildComponent().getEditor(); - if (editor != null) { - myBorderReset = true; - editor.setBorder(null); - } - } - Dimension size = myVmOptionsEditor.getTextField().getPreferredSize(); - Rectangle bounds = myVmOptionsEditor.getTextField().getBounds(); - if (!size.equals(myDimension)) { - myDimension = size; - } - if (myBounds == null || myBounds.width != bounds.width || myBounds.height == bounds.height) { - myBounds = bounds.getSize(); - } - - applyDimension(myProjectPathField.getChildComponent(), false); - applyDimension(myTasksTextField, true); - } - - private void applyDimension(@NotNull JComponent component, boolean processBounds) { - Rectangle bounds = component.getBounds(); - if (bounds != null && myBounds != null && (bounds.width != myBounds.width || bounds.height != myBounds.height)) { - component.setPreferredSize(myDimension); - if (processBounds) { - component.setBounds(bounds.x, bounds.y, myBounds.width, myBounds.height); - } - } - } - }); } @Override diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ui/ExternalProjectPathField.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ui/ExternalProjectPathField.java index fa36d88c3f86..b95ef91720a2 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ui/ExternalProjectPathField.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ui/ExternalProjectPathField.java @@ -16,6 +16,9 @@ package com.intellij.openapi.externalSystem.service.ui; import com.intellij.codeInsight.completion.CompletionResultSet; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.FoldRegion; +import com.intellij.openapi.editor.FoldingModel; import com.intellij.openapi.externalSystem.ExternalSystemManager; import com.intellij.openapi.externalSystem.ExternalSystemUiAware; import com.intellij.openapi.externalSystem.model.ProjectSystemId; @@ -27,6 +30,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComponentWithBrowseButton; import com.intellij.ui.EditorTextField; import com.intellij.ui.TextAccessor; +import com.intellij.util.Consumer; import com.intellij.util.TextFieldCompletionProvider; import com.intellij.util.TextFieldCompletionProviderDumbAware; import com.intellij.util.ui.UIUtil; @@ -43,17 +47,22 @@ import java.util.Map; */ public class ExternalProjectPathField extends ComponentWithBrowseButton implements TextAccessor { + @NotNull private final Project myProject; + @NotNull private final ProjectSystemId myExternalSystemId; + public ExternalProjectPathField(@NotNull Project project, @NotNull ProjectSystemId externalSystemId, @NotNull FileChooserDescriptor descriptor, @NotNull String fileChooserTitle) { super(createTextField(project, externalSystemId), createBrowseListener(descriptor, fileChooserTitle)); + myProject = project; + myExternalSystemId = externalSystemId; } @NotNull - private static EditorTextField createTextField(@NotNull Project project, @NotNull ProjectSystemId externalSystemId) { - ExternalSystemManager manager = ExternalSystemApiUtil.getManager(externalSystemId); + private static EditorTextField createTextField(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId) { + ExternalSystemManager manager = ExternalSystemApiUtil.getManager(externalSystemId); assert manager != null; final AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project); final ExternalSystemUiAware uiAware; @@ -84,14 +93,19 @@ public class ExternalProjectPathField extends ComponentWithBrowseButton() { + @Override + public void consume(Editor editor) { + collapseIfPossible(editor, externalSystemId, project); + } + }); result.setBorder(UIUtil.getTextFieldBorder()); result.setOneLineMode(true); result.setOpaque(true); result.setBackground(UIUtil.getTextFieldBackground()); return result; } - + @NotNull private static ActionListener createBrowseListener(@NotNull final FileChooserDescriptor descriptor, final @NotNull String fileChooserTitle) @@ -110,8 +124,56 @@ public class ExternalProjectPathField extends ComponentWithBrowseButton manager = ExternalSystemApiUtil.getManager(externalSystemId); + assert manager != null; + final AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project); + final ExternalSystemUiAware uiAware; + if (manager instanceof ExternalSystemUiAware) { + uiAware = (ExternalSystemUiAware)manager; + } + else { + uiAware = DefaultExternalSystemUiAware.INSTANCE; + } + + String rawText = editor.getDocument().getText(); + for (Map.Entry> entry : settings.getAvailableProjects().entrySet()) { + if (entry.getKey().getPath().equals(rawText)) { + collapse(editor, uiAware.getProjectRepresentationName(entry.getKey().getPath(), null)); + return; + } + for (ExternalProjectPojo pojo : entry.getValue()) { + if (pojo.getPath().equals(rawText)) { + collapse(editor, uiAware.getProjectRepresentationName(pojo.getPath(), entry.getKey().getPath())); + return; + } + } + } + } + + private static void collapse(@NotNull final Editor editor, @NotNull final String placeholder) { + final FoldingModel foldingModel = editor.getFoldingModel(); + foldingModel.runBatchFoldingOperation(new Runnable() { + @Override + public void run() { + FoldRegion region = foldingModel.addFoldRegion(0, editor.getDocument().getTextLength(), placeholder); + if (region != null) { + region.setExpanded(false); + } + } + }); } @Override diff --git a/platform/lang-impl/src/com/intellij/util/TextFieldCompletionProvider.java b/platform/lang-impl/src/com/intellij/util/TextFieldCompletionProvider.java index 5b50c48bb6ed..09c1a7e83e06 100644 --- a/platform/lang-impl/src/com/intellij/util/TextFieldCompletionProvider.java +++ b/platform/lang-impl/src/com/intellij/util/TextFieldCompletionProvider.java @@ -13,6 +13,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; import com.intellij.ui.EditorTextField; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author sergey.evdokimov @@ -68,11 +69,21 @@ public abstract class TextFieldCompletionProvider { protected abstract void addCompletionVariants(@NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result); + @NotNull public EditorTextField createEditor(Project project) { return createEditor(project, true); } + @NotNull public EditorTextField createEditor(Project project, final boolean shouldHaveBorder) { + return createEditor(project, shouldHaveBorder, null); + } + + @NotNull + public EditorTextField createEditor(Project project, + final boolean shouldHaveBorder, + @Nullable final Consumer editorConstructionCallback) + { return new EditorTextField(createDocument(project, ""), project, PlainTextLanguage.INSTANCE.getAssociatedFileType()) { @Override protected boolean shouldHaveBorder() { @@ -88,6 +99,15 @@ public abstract class TextFieldCompletionProvider { editor.setBorder(null); } } + + @Override + protected EditorEx createEditor() { + EditorEx result = super.createEditor(); + if (editorConstructionCallback != null) { + editorConstructionCallback.consume(result); + } + return result; + } }; } }