IDEA-133305 (support in UI and settings component)

This commit is contained in:
Roman Shevchenko
2014-12-04 13:19:16 +01:00
parent 6972f82e0e
commit 179037a52f
4 changed files with 71 additions and 47 deletions
@@ -53,6 +53,7 @@ public class UpdateSettings implements PersistentStateComponent<Element>, UserUp
public long LAST_TIME_CHECKED = 0;
public String LAST_BUILD_CHECKED = "";
public String UPDATE_CHANNEL_TYPE = ChannelStatus.RELEASE_CODE;
public boolean SECURE_CONNECTION = false;
public static UpdateSettings getInstance() {
return ServiceManager.getService(UpdateSettings.class);
@@ -128,7 +129,7 @@ public class UpdateSettings implements PersistentStateComponent<Element>, UserUp
public List<String> getPluginHosts() {
List<String> hosts = new ArrayList<String>(myPluginHosts);
final String pluginHosts = System.getProperty("idea.plugin.hosts");
String pluginHosts = System.getProperty("idea.plugin.hosts");
if (pluginHosts != null) {
ContainerUtil.addAll(hosts, pluginHosts.split(";"));
}
@@ -141,7 +142,6 @@ public class UpdateSettings implements PersistentStateComponent<Element>, UserUp
public void saveLastCheckedInfo() {
LAST_TIME_CHECKED = System.currentTimeMillis();
ApplicationInfo appInfo = ApplicationInfo.getInstance();
LAST_BUILD_CHECKED = appInfo.getBuild().asString();
LAST_BUILD_CHECKED = ApplicationInfo.getInstance().getBuild().asString();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* 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.
@@ -41,28 +41,45 @@ public class UpdateSettingsConfigurable extends BaseConfigurable implements Sear
private UpdatesSettingsPanel myUpdatesSettingsPanel;
private boolean myCheckNowEnabled = true;
public JComponent createComponent() {
myUpdatesSettingsPanel = new UpdatesSettingsPanel();
return myUpdatesSettingsPanel.myPanel;
}
public String getDisplayName() {
return IdeBundle.message("updates.settings.title");
}
public String getHelpTopic() {
return "preferences.updates";
}
public void setCheckNowEnabled(boolean enabled) {
myCheckNowEnabled = enabled;
}
@Override
public JComponent createComponent() {
myUpdatesSettingsPanel = new UpdatesSettingsPanel();
myUpdatesSettingsPanel.myCheckNow.setEnabled(myCheckNowEnabled);
return myUpdatesSettingsPanel.myPanel;
}
@Override
public String getDisplayName() {
return IdeBundle.message("updates.settings.title");
}
@NotNull
@Override
public String getHelpTopic() {
return "preferences.updates";
}
@NotNull
public String getId() {
return getHelpTopic();
}
@Nullable
@Override
public Runnable enableSearch(String option) {
return null;
}
@Override
public void apply() throws ConfigurationException {
UpdateSettings settings = UpdateSettings.getInstance();
boolean wasEnabled = settings.CHECK_NEEDED;
settings.CHECK_NEEDED = myUpdatesSettingsPanel.myCbCheckForUpdates.isSelected();
settings.CHECK_NEEDED = myUpdatesSettingsPanel.myCheckForUpdates.isSelected();
if (wasEnabled != settings.CHECK_NEEDED) {
UpdateCheckerComponent checker = ApplicationManager.getApplication().getComponent(UpdateCheckerComponent.class);
if (checker != null) {
@@ -76,35 +93,42 @@ public class UpdateSettingsConfigurable extends BaseConfigurable implements Sear
}
settings.UPDATE_CHANNEL_TYPE = myUpdatesSettingsPanel.getSelectedChannelType().getCode();
settings.SECURE_CONNECTION = myUpdatesSettingsPanel.myUseSecureConnection.isSelected();
}
@Override
public void reset() {
UpdateSettings settings = UpdateSettings.getInstance();
myUpdatesSettingsPanel.myCbCheckForUpdates.setSelected(settings.CHECK_NEEDED);
myUpdatesSettingsPanel.myCheckForUpdates.setSelected(settings.CHECK_NEEDED);
myUpdatesSettingsPanel.myUseSecureConnection.setSelected(settings.SECURE_CONNECTION);
myUpdatesSettingsPanel.updateLastCheckedLabel();
myUpdatesSettingsPanel.setSelectedChannelType(ChannelStatus.fromCode(settings.UPDATE_CHANNEL_TYPE));
}
@Override
public boolean isModified() {
if (myUpdatesSettingsPanel == null) return false;
UpdateSettings settings = UpdateSettings.getInstance();
if (settings.CHECK_NEEDED != myUpdatesSettingsPanel.myCbCheckForUpdates.isSelected()) return true;
final JComboBox channelsBox = myUpdatesSettingsPanel.myUpdateChannelsBox;
return (channelsBox.getSelectedItem() != null && !channelsBox.getSelectedItem().equals(ChannelStatus.fromCode(settings.UPDATE_CHANNEL_TYPE)));
if (settings.CHECK_NEEDED != myUpdatesSettingsPanel.myCheckForUpdates.isSelected()) return true;
if (settings.SECURE_CONNECTION != myUpdatesSettingsPanel.myUseSecureConnection.isSelected()) return true;
Object channel = myUpdatesSettingsPanel.myUpdateChannels.getSelectedItem();
return channel != null && !channel.equals(ChannelStatus.fromCode(settings.UPDATE_CHANNEL_TYPE));
}
@Override
public void disposeUIResources() {
myUpdatesSettingsPanel = null;
}
private class UpdatesSettingsPanel {
private static class UpdatesSettingsPanel {
private JPanel myPanel;
private JButton myBtnCheckNow;
private JCheckBox myCbCheckForUpdates;
private JButton myCheckNow;
private JCheckBox myCheckForUpdates;
private JLabel myBuildNumber;
private JLabel myVersionNumber;
private JLabel myLastCheckedDate;
private JComboBox myUpdateChannelsBox;
private JComboBox myUpdateChannels;
private JCheckBox myUseSecureConnection;
public UpdatesSettingsPanel() {
final ApplicationInfo appInfo = ApplicationInfo.getInstance();
@@ -122,22 +146,23 @@ public class UpdateSettingsConfigurable extends BaseConfigurable implements Sear
myVersionNumber.setText(appInfo.getVersionName() + " " + versionNumber);
myBuildNumber.setText(appInfo.getBuild().asString());
myBtnCheckNow.addActionListener(new ActionListener() {
myCheckNow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myBtnCheckNow));
Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myCheckNow));
UpdateSettings settings = new UpdateSettings();
settings.loadState(UpdateSettings.getInstance().getState());
settings.UPDATE_CHANNEL_TYPE = getSelectedChannelType().getCode();
settings.SECURE_CONNECTION = myUseSecureConnection.isSelected();
UpdateChecker.updateAndShowResult(project, true, settings); //todo load configured hosts on the fly
updateLastCheckedLabel();
}
});
myBtnCheckNow.setEnabled(myCheckNowEnabled);
LabelTextReplacingUtil.replaceText(myPanel);
final UpdateSettings settings = UpdateSettings.getInstance();
myUpdateChannelsBox.setModel(new CollectionComboBoxModel(ChannelStatus.all(), ChannelStatus.fromCode(settings.UPDATE_CHANNEL_TYPE)));
UpdateSettings settings = UpdateSettings.getInstance();
//noinspection unchecked
myUpdateChannels.setModel(new CollectionComboBoxModel(ChannelStatus.all(), ChannelStatus.fromCode(settings.UPDATE_CHANNEL_TYPE)));
}
private void updateLastCheckedLabel() {
@@ -146,21 +171,11 @@ public class UpdateSettingsConfigurable extends BaseConfigurable implements Sear
}
public ChannelStatus getSelectedChannelType() {
return (ChannelStatus) myUpdateChannelsBox.getSelectedItem();
return (ChannelStatus) myUpdateChannels.getSelectedItem();
}
public void setSelectedChannelType(ChannelStatus channelType) {
myUpdateChannelsBox.setSelectedItem(channelType != null ? channelType : ChannelStatus.RELEASE);
myUpdateChannels.setSelectedItem(channelType != null ? channelType : ChannelStatus.RELEASE);
}
}
@NotNull
public String getId() {
return getHelpTopic();
}
@Nullable
public Runnable enableSearch(String option) {
return null;
}
}
@@ -8,7 +8,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="e409a" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e409a" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="0" bottom="20" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="2" indent="0" use-parent-layout="false"/>
@@ -16,7 +16,7 @@
<properties/>
<border type="none"/>
<children>
<component id="1aa0e" class="javax.swing.JCheckBox" binding="myCbCheckForUpdates">
<component id="1aa0e" class="javax.swing.JCheckBox" binding="myCheckForUpdates">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
@@ -25,7 +25,7 @@
<text resource-bundle="messages/IdeBundle" key="updates.settings.checkbox"/>
</properties>
</component>
<component id="cc207" class="javax.swing.JButton" binding="myBtnCheckNow">
<component id="cc207" class="javax.swing.JButton" binding="myCheckNow">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
@@ -33,12 +33,20 @@
<text resource-bundle="messages/IdeBundle" key="updates.settings.check.now.button"/>
</properties>
</component>
<component id="8eae8" class="javax.swing.JComboBox" binding="myUpdateChannelsBox">
<component id="8eae8" class="javax.swing.JComboBox" binding="myUpdateChannels">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="fc5f1" class="javax.swing.JCheckBox" binding="myUseSecureConnection">
<constraints>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/IdeBundle" key="updates.settings.secure"/>
</properties>
</component>
</children>
</grid>
<component id="36fbb" class="javax.swing.JLabel">
@@ -923,6 +923,7 @@ updates.settings.title=Updates
updates.last.check.never=Never
updates.settings.check.now.button=&Check Now
updates.settings.checkbox=Automatically check updates for
updates.settings.secure=Use secure connection
updates.settings.build.number=Build number:
updates.settings.current.version=Current version:
updates.settings.last.check=Last checked: