mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Refactor study settings
This commit is contained in:
@@ -37,6 +37,9 @@
|
||||
</extensionPoint>
|
||||
<extensionPoint qualifiedName="Edu.studyPluginConfigurator" interface="com.jetbrains.edu.learning.StudyPluginConfigurator"/>
|
||||
<extensionPoint qualifiedName="Edu.studyTwitterPluginConfigurator" interface="com.jetbrains.edu.learning.StudyTwitterPluginConfigurator"/>
|
||||
<extensionPoint qualifiedName="Edu.optionsProvider" beanClass="com.jetbrains.edu.learning.settings.StudyOptionsProviderEP">>
|
||||
<with attribute="instance" implements="com.jetbrains.edu.learning.settings.StudyOptionsProvider"/>
|
||||
</extensionPoint>
|
||||
</extensionPoints>
|
||||
|
||||
<actions>
|
||||
@@ -93,4 +96,7 @@
|
||||
<renameHandler implementation="com.jetbrains.edu.learning.StudyRenameHandler"/>
|
||||
<refactoring.moveHandler implementation="com.jetbrains.edu.learning.StudyMoveDelegate" order="first"/>
|
||||
</extensions>
|
||||
<extensions defaultExtensionNs="Edu">
|
||||
<optionsProvider instance="com.jetbrains.edu.learning.stepic.StepicOptionsProvider"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
-4
@@ -5,7 +5,6 @@ import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.jetbrains.edu.learning.actions.StudyAfterCheckAction;
|
||||
import com.jetbrains.edu.learning.settings.ModifiableSettingsPanel;
|
||||
import com.jetbrains.edu.learning.ui.StudyToolWindow;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -41,9 +40,6 @@ public interface StudyPluginConfigurator {
|
||||
StudyAfterCheckAction[] getAfterCheckActions();
|
||||
|
||||
@NotNull String getLanguageScriptUrl();
|
||||
|
||||
@Nullable
|
||||
ModifiableSettingsPanel getSettingsPanel();
|
||||
|
||||
boolean accept(@NotNull final Project project);
|
||||
}
|
||||
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package com.jetbrains.edu.learning.settings;
|
||||
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public interface ModifiableSettingsPanel {
|
||||
void apply();
|
||||
|
||||
void reset();
|
||||
|
||||
void resetCredentialsModification();
|
||||
|
||||
boolean isModified();
|
||||
|
||||
@NotNull
|
||||
JComponent getPanel();
|
||||
}
|
||||
-91
@@ -1,91 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.edu.learning.settings.StudyBaseSettingsPanel">
|
||||
<grid id="27dc6" binding="myPane" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="646" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<clientProperties>
|
||||
<html.disable class="java.lang.Boolean" value="false"/>
|
||||
</clientProperties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="6ace">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="bda15" layout-manager="CardLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="e4354" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<card name="Password"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="c0234" class="com.intellij.ui.components.JBLabel">
|
||||
<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>
|
||||
<properties>
|
||||
<anchor value="e4416"/>
|
||||
<text value="Login:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e76ec" class="javax.swing.JTextField" binding="myLoginTextField">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="e4416" class="com.intellij.ui.components.JBLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Password:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9edbd" class="javax.swing.JPasswordField" binding="myPasswordField" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="6d9fb" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<card name="Token"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="811c0" class="com.intellij.ui.TitledSeparator">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Stepic"/>
|
||||
<titleFont size="14" style="1"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
+15
-67
@@ -15,36 +15,22 @@
|
||||
*/
|
||||
package com.jetbrains.edu.learning.settings;
|
||||
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.options.CompositeConfigurable;
|
||||
import com.intellij.openapi.options.ex.ConfigurableWrapper;
|
||||
import com.intellij.openapi.ui.VerticalFlowLayout;
|
||||
import com.jetbrains.edu.learning.StudyPluginConfigurator;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StudyConfigurable implements SearchableConfigurable {
|
||||
public class StudyConfigurable extends CompositeConfigurable<StudyOptionsProvider> {
|
||||
public static final String ID = "com.jetbrains.edu.learning.stepic.EduConfigurable";
|
||||
private JPanel myMainPanel;
|
||||
private ArrayList<ModifiableSettingsPanel> myPluginsSettingsPanels;
|
||||
private StudyBaseSettingsPanel mySettingsPanel;
|
||||
|
||||
public StudyConfigurable() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Runnable enableSearch(String option) {
|
||||
return null;
|
||||
myMainPanel = new JPanel(new VerticalFlowLayout());
|
||||
}
|
||||
|
||||
@Nls
|
||||
@@ -62,63 +48,25 @@ public class StudyConfigurable implements SearchableConfigurable {
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
if (myMainPanel == null) {
|
||||
myMainPanel = new JPanel(new VerticalFlowLayout());
|
||||
}
|
||||
mySettingsPanel = new StudyBaseSettingsPanel();
|
||||
myMainPanel.add(mySettingsPanel.getPanel());
|
||||
|
||||
myPluginsSettingsPanels = new ArrayList<>();
|
||||
StudyPluginConfigurator[] extensions = StudyPluginConfigurator.EP_NAME.getExtensions();
|
||||
for (StudyPluginConfigurator configurator: extensions) {
|
||||
final ModifiableSettingsPanel settingsPanel = configurator.getSettingsPanel();
|
||||
if (settingsPanel != null) {
|
||||
myPluginsSettingsPanels.add(settingsPanel);
|
||||
myMainPanel.add(settingsPanel.getPanel());
|
||||
myMainPanel.removeAll();
|
||||
for (int i = 0; i < getConfigurables().size(); i++) {
|
||||
StudyOptionsProvider provider = getConfigurables().get(i);
|
||||
JComponent component = provider.createComponent();
|
||||
if (component != null) {
|
||||
myMainPanel.add(component);
|
||||
}
|
||||
}
|
||||
return myMainPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
if (mySettingsPanel != null) {
|
||||
boolean isModified = mySettingsPanel.isModified();
|
||||
if (myPluginsSettingsPanels != null && !myPluginsSettingsPanels.isEmpty()) {
|
||||
for (ModifiableSettingsPanel settingsPanel: myPluginsSettingsPanels) {
|
||||
isModified &= settingsPanel.isModified();
|
||||
}
|
||||
}
|
||||
return isModified;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void apply() throws ConfigurationException {
|
||||
if (myMainPanel != null) {
|
||||
mySettingsPanel.apply();
|
||||
if (myPluginsSettingsPanels != null && !myPluginsSettingsPanels.isEmpty()) {
|
||||
for (ModifiableSettingsPanel settingsPanel: myPluginsSettingsPanels) {
|
||||
settingsPanel.apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
if (myMainPanel != null) {
|
||||
mySettingsPanel.apply();
|
||||
if (myPluginsSettingsPanels != null && !myPluginsSettingsPanels.isEmpty()) {
|
||||
for (ModifiableSettingsPanel settingsPanel: myPluginsSettingsPanels) {
|
||||
settingsPanel.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void disposeUIResources() {
|
||||
super.disposeUIResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
myMainPanel = null;
|
||||
protected List<StudyOptionsProvider> createConfigurables() {
|
||||
return ConfigurableWrapper.createConfigurables(StudyOptionsProviderEP.EP_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.jetbrains.edu.learning.settings;
|
||||
|
||||
import com.intellij.openapi.options.UnnamedConfigurable;
|
||||
|
||||
public interface StudyOptionsProvider extends UnnamedConfigurable {
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.jetbrains.edu.learning.settings;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.options.ConfigurableEP;
|
||||
|
||||
public class StudyOptionsProviderEP extends ConfigurableEP<StudyOptionsProvider> {
|
||||
public static final ExtensionPointName<StudyOptionsProviderEP>
|
||||
EP_NAME = ExtensionPointName.create("Edu.optionsProvider");
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.jetbrains.edu.learning.stepic;
|
||||
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.jetbrains.edu.learning.settings.StudyOptionsProvider;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class StepicOptionsProvider implements StudyOptionsProvider{
|
||||
|
||||
private StepicStudyOptions myPanel;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
myPanel = new StepicStudyOptions();
|
||||
return myPanel.getPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return myPanel.isModified();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
myPanel.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
myPanel.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.edu.learning.stepic.StepicStudyOptions">
|
||||
<grid id="27dc6" binding="myPane" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="646" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<clientProperties>
|
||||
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
|
||||
<html.disable class="java.lang.Boolean" value="false"/>
|
||||
</clientProperties>
|
||||
<border type="etched" title="Stepic">
|
||||
<font/>
|
||||
</border>
|
||||
<children>
|
||||
<vspacer id="6ace">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="e4354" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e76ec" class="javax.swing.JTextField" binding="myLoginTextField">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="e4416" class="com.intellij.ui.components.JBLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="9edbd"/>
|
||||
<text value="&Password:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9edbd" class="javax.swing.JPasswordField" binding="myPasswordField" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="c0234" class="com.intellij.ui.components.JBLabel">
|
||||
<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>
|
||||
<properties>
|
||||
<anchor value="e4416"/>
|
||||
<labelFor value="e76ec"/>
|
||||
<text value="&Login:"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
+15
-11
@@ -13,13 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.edu.learning.settings;
|
||||
package com.jetbrains.edu.learning.stepic;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.edu.learning.stepic.EduStepicConnector;
|
||||
import com.jetbrains.edu.learning.stepic.StudySettings;
|
||||
import com.jetbrains.edu.learning.settings.StudyOptionsProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -31,7 +29,7 @@ import javax.swing.text.PlainDocument;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
|
||||
public class StudyBaseSettingsPanel implements ModifiableSettingsPanel{
|
||||
public class StepicStudyOptions implements StudyOptionsProvider {
|
||||
private static final String DEFAULT_PASSWORD_TEXT = "************";
|
||||
private JTextField myLoginTextField;
|
||||
private JPasswordField myPasswordField;
|
||||
@@ -39,7 +37,7 @@ public class StudyBaseSettingsPanel implements ModifiableSettingsPanel{
|
||||
|
||||
private boolean myCredentialsModified;
|
||||
|
||||
public StudyBaseSettingsPanel() {
|
||||
public StepicStudyOptions() {
|
||||
myPasswordField.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(DocumentEvent e) {
|
||||
@@ -69,7 +67,6 @@ public class StudyBaseSettingsPanel implements ModifiableSettingsPanel{
|
||||
public void focusLost(FocusEvent e) {
|
||||
}
|
||||
});
|
||||
myPane.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, UIUtil.getBoundsColor()));
|
||||
reset();
|
||||
}
|
||||
|
||||
@@ -79,7 +76,6 @@ public class StudyBaseSettingsPanel implements ModifiableSettingsPanel{
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JComponent getPanel() {
|
||||
return myPane;
|
||||
}
|
||||
@@ -102,7 +98,7 @@ public class StudyBaseSettingsPanel implements ModifiableSettingsPanel{
|
||||
myPasswordField.setText(StringUtil.isEmpty(password) ? null : password);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void reset() {
|
||||
final StudySettings studySettings = StudySettings.getInstance();
|
||||
setLogin(studySettings.getLogin());
|
||||
@@ -112,6 +108,10 @@ public class StudyBaseSettingsPanel implements ModifiableSettingsPanel{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
if (myCredentialsModified) {
|
||||
final StudySettings studySettings = StudySettings.getInstance();
|
||||
@@ -124,12 +124,16 @@ public class StudyBaseSettingsPanel implements ModifiableSettingsPanel{
|
||||
resetCredentialsModification();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
return myPane;
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return myCredentialsModified;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void resetCredentialsModification() {
|
||||
myCredentialsModified = false;
|
||||
}
|
||||
-8
@@ -3,9 +3,7 @@ package com.jetbrains.edu.learning;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.jetbrains.edu.learning.courseFormat.Course;
|
||||
import com.jetbrains.edu.learning.settings.ModifiableSettingsPanel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PyStudyPluginConfigurator extends StudyBasePluginConfigurator {
|
||||
|
||||
@@ -38,10 +36,4 @@ public class PyStudyPluginConfigurator extends StudyBasePluginConfigurator {
|
||||
Course course = taskManager.getCourse();
|
||||
return course != null && "Python".equals(course.getLanguage()) && "PyCharm".equals(course.getCourseType());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ModifiableSettingsPanel getSettingsPanel() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user