diff --git a/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubProjectGeneratorPeer.java b/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubProjectGeneratorPeer.java index dadf2c89137a..6dc85cfdf288 100644 --- a/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubProjectGeneratorPeer.java +++ b/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubProjectGeneratorPeer.java @@ -26,6 +26,7 @@ import com.intellij.ui.ListCellRendererWrapper; import com.intellij.util.ObjectUtils; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.ReloadableComboBoxPanel; +import com.intellij.util.ui.ReloadablePanel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -116,7 +117,7 @@ public class GithubProjectGeneratorPeer implements WebProjectGenerator.Generator private final GithubTagListProvider myTagListProvider; private JComponent myComponent; private JPanel myVersionPanel; - private ReloadableComboBoxPanel myReloadableComboBoxPanel; + private ReloadablePanel myReloadableComboBoxPanel; public GithubProjectGeneratorPeer(@NotNull AbstractGithubTagDownloadedProjectGenerator generator) { String ghUserName = generator.getGithubUserName(); diff --git a/platform/platform-impl/src/com/intellij/util/ui/ReloadableComboBoxPanel.form b/platform/platform-impl/src/com/intellij/util/ui/ReloadableComboBoxPanel.form index 3f7b56801418..6fb541a0a883 100644 --- a/platform/platform-impl/src/com/intellij/util/ui/ReloadableComboBoxPanel.form +++ b/platform/platform-impl/src/com/intellij/util/ui/ReloadableComboBoxPanel.form @@ -21,7 +21,7 @@ - + diff --git a/platform/platform-impl/src/com/intellij/util/ui/ReloadableComboBoxPanel.java b/platform/platform-impl/src/com/intellij/util/ui/ReloadableComboBoxPanel.java index fb6849aa1396..22adf2886018 100644 --- a/platform/platform-impl/src/com/intellij/util/ui/ReloadableComboBoxPanel.java +++ b/platform/platform-impl/src/com/intellij/util/ui/ReloadableComboBoxPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -15,176 +15,34 @@ */ package com.intellij.util.ui; -import com.intellij.icons.AllIcons; -import com.intellij.openapi.actionSystem.ActionToolbar; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.impl.ActionButton; import com.intellij.openapi.ui.ComboBox; -import com.intellij.ui.JBColor; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.awt.*; -import java.util.Set; -public abstract class ReloadableComboBoxPanel { - public interface DataProvider { - - /** - * returns init cached values - */ - @Nullable - Set getCachedValues(); - - /** - * After getting values method must call #onUpdateValues or #onValuesUpdateError - */ - void updateValuesAsynchronously(); - } - - private static final String CONTROL_PLACE = "UI.Configuration.Component.Reload.Panel"; - - private final AsyncProcessIcon myLoadingVersionIcon = new AsyncProcessIcon("Getting possible values"); - - private final JLabel myErrorMessage = new JLabel(); - @Nullable - private volatile DataProvider myDataProvider; - @Nullable - private volatile UpdateStatus myUpdateStatus; +public abstract class ReloadableComboBoxPanel extends ReloadablePanel { protected JComboBox myComboBox; - - protected JPanel myActionPanel; - protected JPanel myMainPanel; - public ReloadableComboBoxPanel() { - myErrorMessage.setForeground(JBColor.RED); - fillActionPanel(); - } - - public final void setDataProvider(@NotNull DataProvider dataProvider) { - myDataProvider = dataProvider; - - Set cachedValues = dataProvider.getCachedValues(); - if (cachedValues != null) { - onUpdateValues(cachedValues); - } - } - - protected abstract void doUpdateValues(@NotNull Set values); + private JPanel myActionPanel; + private JPanel myMainPanel; @SuppressWarnings("unchecked") public T getSelectedValue() { return (T)myComboBox.getSelectedItem(); } - @NotNull - public final JLabel getErrorComponent() { - return myErrorMessage; - } - - public final boolean isBackgroundJobRunning() { - return myUpdateStatus == UpdateStatus.UPDATING; - } - - public final void onUpdateValues(@NotNull Set values) { - changeUpdateStatus(UpdateStatus.IDLE); - doUpdateValues(values); - } - - public final void reloadValuesInBackground() { - if (myUpdateStatus == UpdateStatus.UPDATING) return; - changeUpdateStatus(UpdateStatus.UPDATING); - myErrorMessage.setText(null); - DataProvider provider = myDataProvider; - assert provider != null; - provider.updateValuesAsynchronously(); - } - - private void changeUpdateStatus(@NotNull UpdateStatus status) { - CardLayout cardLayout = (CardLayout)myActionPanel.getLayout(); - cardLayout.show(myActionPanel, status.name()); - if (status == UpdateStatus.UPDATING) { - myLoadingVersionIcon.resume(); - } - else { - myLoadingVersionIcon.suspend(); - } - myUpdateStatus = status; - } - - private void fillActionPanel() { - myActionPanel.add(createReloadButtonPanel(), UpdateStatus.IDLE.name()); - myActionPanel.add(createReloadInProgressPanel(), UpdateStatus.UPDATING.name()); - changeUpdateStatus(UpdateStatus.IDLE); - } - - public final void onValuesUpdateError(@NotNull final String errorMessage) { - UIUtil.invokeLaterIfNeeded(new Runnable() { - @Override - public void run() { - if (getSelectedValue() == null) { - myErrorMessage.setText(errorMessage); - } - changeUpdateStatus(UpdateStatus.IDLE); - } - }); - } - - - @NotNull - private JPanel createReloadButtonPanel() { - ReloadAction reloadAction = new ReloadAction(); - ActionButton reloadButton = new ActionButton( - reloadAction, - reloadAction.getTemplatePresentation().clone(), - CONTROL_PLACE, - ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE - ); - JPanel panel = new JPanel(new BorderLayout(0, 0)); - panel.add(reloadButton, BorderLayout.WEST); - return panel; - } - - @NotNull - public final JPanel getMainPanel() { - return myMainPanel; - } - - @NotNull - private JPanel createReloadInProgressPanel() { - JPanel panel = new JPanel(); - panel.add(myLoadingVersionIcon); - return panel; - } - - private final class ReloadAction extends AnAction { - - private ReloadAction() { - super("Reload list", null, AllIcons.Actions.Refresh); - } - - @Override - public void actionPerformed(AnActionEvent e) { - reloadValuesInBackground(); - } - - @Override - public void update(AnActionEvent e) { - e.getPresentation().setEnabled(true); - } - } - - private enum UpdateStatus { - UPDATING, IDLE - } - @NotNull protected JComboBox createValuesComboBox() { return new ComboBox(); } + @NotNull + @Override + public JPanel getMainPanel() { + return myMainPanel; + } + private void createUIComponents() { myComboBox = createValuesComboBox(); + myActionPanel = getActionPanel(); } } diff --git a/platform/platform-impl/src/com/intellij/util/ui/ReloadableListPanel.form b/platform/platform-impl/src/com/intellij/util/ui/ReloadableListPanel.form new file mode 100644 index 000000000000..af6515c230b3 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/util/ui/ReloadableListPanel.form @@ -0,0 +1,53 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/platform/platform-impl/src/com/intellij/util/ui/ReloadableListPanel.java b/platform/platform-impl/src/com/intellij/util/ui/ReloadableListPanel.java new file mode 100644 index 000000000000..85f830fbb10f --- /dev/null +++ b/platform/platform-impl/src/com/intellij/util/ui/ReloadableListPanel.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2016 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 com.intellij.util.ui; + +import com.intellij.ui.components.JBList; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +public abstract class ReloadableListPanel extends ReloadablePanel { + protected JList myList; + private JPanel myMainPanel; + private JPanel myActionPanel; + + @SuppressWarnings("unchecked") + public T getSelectedValue() { + return (T)myList.getSelectedValue(); + } + + protected void createList() { + myList = new JBList(); + } + + @NotNull + @Override + public JPanel getMainPanel() { + return myMainPanel; + } + + private void createUIComponents() { + myActionPanel = getActionPanel(); + createList(); + } +} diff --git a/platform/platform-impl/src/com/intellij/util/ui/ReloadablePanel.java b/platform/platform-impl/src/com/intellij/util/ui/ReloadablePanel.java new file mode 100644 index 000000000000..0b8341555126 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/util/ui/ReloadablePanel.java @@ -0,0 +1,184 @@ +/* + * Copyright 2000-2014 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 com.intellij.util.ui; + +import com.intellij.icons.AllIcons; +import com.intellij.openapi.actionSystem.ActionToolbar; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.impl.ActionButton; +import com.intellij.ui.JBColor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; +import java.util.Set; + +public abstract class ReloadablePanel { + public interface DataProvider { + + /** + * returns init cached values + */ + @Nullable + Set getCachedValues(); + + /** + * After getting values method must call #onUpdateValues or #onValuesUpdateError + */ + void updateValuesAsynchronously(); + } + + private static final String CONTROL_PLACE = "UI.Configuration.Component.Reload.Panel"; + + private final AsyncProcessIcon myLoadingVersionIcon = new AsyncProcessIcon("Getting possible values"); + + private final JLabel myErrorMessage = new JLabel(); + @Nullable + private volatile DataProvider myDataProvider; + @Nullable + private volatile UpdateStatus myUpdateStatus; + + protected JPanel myActionPanel; + public ReloadablePanel() { + myErrorMessage.setForeground(JBColor.RED); + + createActionPanel(); + fillActionPanel(); + } + + private void createActionPanel() { + myActionPanel = new JPanel(new CardLayout()); + } + + public final void setDataProvider(@NotNull DataProvider dataProvider) { + myDataProvider = dataProvider; + + Set cachedValues = dataProvider.getCachedValues(); + if (cachedValues != null) { + onUpdateValues(cachedValues); + } + } + + protected abstract void doUpdateValues(@NotNull Set values); + + public abstract T getSelectedValue(); + + @NotNull + public final JLabel getErrorComponent() { + return myErrorMessage; + } + + public final boolean isBackgroundJobRunning() { + return myUpdateStatus == UpdateStatus.UPDATING; + } + + public final void onUpdateValues(@NotNull Set values) { + changeUpdateStatus(UpdateStatus.IDLE); + doUpdateValues(values); + } + + public final void reloadValuesInBackground() { + if (myUpdateStatus == UpdateStatus.UPDATING) return; + changeUpdateStatus(UpdateStatus.UPDATING); + myErrorMessage.setText(null); + DataProvider provider = myDataProvider; + assert provider != null; + provider.updateValuesAsynchronously(); + } + + private void changeUpdateStatus(@NotNull UpdateStatus status) { + CardLayout cardLayout = (CardLayout)myActionPanel.getLayout(); + cardLayout.show(myActionPanel, status.name()); + if (status == UpdateStatus.UPDATING) { + myLoadingVersionIcon.resume(); + } + else { + myLoadingVersionIcon.suspend(); + } + myUpdateStatus = status; + } + + protected void fillActionPanel() { + myActionPanel.add(createReloadButtonPanel(), UpdateStatus.IDLE.name()); + myActionPanel.add(createReloadInProgressPanel(), UpdateStatus.UPDATING.name()); + changeUpdateStatus(UpdateStatus.IDLE); + } + + public final void onValuesUpdateError(@NotNull final String errorMessage) { + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + if (getSelectedValue() == null) { + myErrorMessage.setText(errorMessage); + } + changeUpdateStatus(UpdateStatus.IDLE); + } + }); + } + + + @NotNull + private JPanel createReloadButtonPanel() { + ReloadAction reloadAction = new ReloadAction(); + ActionButton reloadButton = new ActionButton( + reloadAction, + reloadAction.getTemplatePresentation().clone(), + CONTROL_PLACE, + ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE + ); + JPanel panel = new JPanel(new BorderLayout(0, 0)); + panel.add(reloadButton, BorderLayout.WEST); + return panel; + } + + @NotNull + public abstract JPanel getMainPanel(); + + @NotNull + JPanel getActionPanel(){ + return myActionPanel; + } + + @NotNull + private JPanel createReloadInProgressPanel() { + JPanel panel = new JPanel(); + panel.add(myLoadingVersionIcon); + return panel; + } + + private final class ReloadAction extends AnAction { + + private ReloadAction() { + super("Reload list", null, AllIcons.Actions.Refresh); + } + + @Override + public void actionPerformed(AnActionEvent e) { + reloadValuesInBackground(); + } + + @Override + public void update(AnActionEvent e) { + e.getPresentation().setEnabled(true); + } + } + + private enum UpdateStatus { + UPDATING, IDLE + } +}