Skip to content

Commit 2a3734e

Browse files
committed
Add Server Panel and refactored code #152
1 parent 3d520a1 commit 2a3734e

File tree

8 files changed

+88
-23
lines changed

8 files changed

+88
-23
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.mercedesbenz.sechub.plugin.idea.window;
2+
3+
import javax.swing.*;
4+
5+
public interface SecHubPanel {
6+
JPanel getContent();
7+
}

src/main/java-intellij/com/mercedesbenz/sechub/plugin/idea/window/SecHubReportPanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import java.awt.event.MouseEvent;
3737
import java.util.UUID;
3838

39-
public class SecHubReportPanel {
39+
public class SecHubReportPanel implements SecHubPanel {
4040
private static final Logger LOG = Logger.getInstance(SecHubReportPanel.class);
4141
private static final int SECHUB_REPORT_DEFAULT_GAP = 5;
4242
private static SecHubReportPanel INSTANCE;
@@ -398,7 +398,7 @@ private void showInEditor(FindingNode callStep) {
398398
showInEditorSupport.showInEditor(toolWindow, callStep);
399399
}
400400

401-
401+
@Override
402402
public JPanel getContent() {
403403
return contentPanel;
404404
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.mercedesbenz.sechub.plugin.idea.window;
2+
3+
import com.intellij.openapi.diagnostic.Logger;
4+
import com.intellij.ui.components.JBPanel;
5+
import com.intellij.ui.components.JBTextField;
6+
import com.mercedesbenz.sechub.sdk.settings.AppSettings;
7+
8+
import javax.swing.*;
9+
import java.awt.*;
10+
import java.util.Objects;
11+
12+
public class SecHubServerPanel implements SecHubPanel{
13+
14+
private static final Logger LOG = Logger.getInstance(SecHubServerPanel.class);
15+
private static SecHubServerPanel INSTANCE;
16+
private JPanel contentPanel;
17+
private final JBTextField serverUrlText = new JBTextField();
18+
19+
public SecHubServerPanel() {
20+
createComponents();
21+
}
22+
23+
public static void registerInstance(SecHubServerPanel secHubToolWindow) {
24+
LOG.info("register tool windows instance:" + secHubToolWindow);
25+
INSTANCE = secHubToolWindow;
26+
}
27+
28+
public static SecHubServerPanel getInstance() {
29+
return INSTANCE;
30+
}
31+
32+
@Override
33+
public JPanel getContent() {
34+
return contentPanel;
35+
}
36+
37+
public void update(String serverURL) {
38+
serverUrlText.setText(serverURL);
39+
}
40+
41+
private void createComponents() {
42+
contentPanel = new JBPanel<>();
43+
contentPanel.setLayout(new BorderLayout());
44+
45+
JPanel top = new JPanel(new BorderLayout());
46+
String serverURL = Objects.requireNonNull(AppSettings.getInstance().getState()).serverURL;
47+
serverUrlText.setText(serverURL);
48+
serverUrlText.setEditable(false);
49+
50+
top.add(new JLabel("Server URL: "), BorderLayout.WEST);
51+
top.add(serverUrlText);
52+
contentPanel.add(top, BorderLayout.NORTH);
53+
}
54+
}

src/main/java-intellij/com/mercedesbenz/sechub/plugin/idea/window/SecHubToolWindowFactory.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class SecHubToolWindowFactory implements ToolWindowFactory, DumbAware {
2323
@Override
2424
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
2525

26+
SecHubServerPanel serverPanel = new SecHubServerPanel();
27+
SecHubServerPanel.registerInstance(serverPanel);
28+
2629
SecHubReportPanel reportPanel = new SecHubReportPanel(toolWindow);
2730
SecHubReportPanel.registerInstance(reportPanel);
2831

@@ -35,23 +38,24 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
3538
// toolbarActions.add(importAction);
3639
// toolbarActions.add(resetReportData);
3740

38-
addToolWindowTab(toolWindow, reportPanel, toolbar);
41+
addToolWindowTab(toolWindow, reportPanel, toolbar, "Report");
42+
addToolWindowTab(toolWindow, serverPanel, toolbar, "Server");
3943

4044
List<AnAction> titleActions = new ArrayList<>();
4145
titleActions.add(importAction);
4246
titleActions.add(resetReportData);
4347
toolWindow.setTitleActions(titleActions);
4448
}
4549

46-
private static void addToolWindowTab(@NotNull ToolWindow toolWindow, SecHubReportPanel reportPanel, ActionToolbar toolbar) {
50+
private static void addToolWindowTab(@NotNull ToolWindow toolWindow, SecHubPanel panel, ActionToolbar toolbar, String name) {
4751
ContentFactory contentFactory = ContentFactory.getInstance();
4852
SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(false,false);
49-
toolWindowPanel.add(reportPanel.getContent());
53+
toolWindowPanel.add(panel.getContent());
5054

5155
toolbar.setTargetComponent(toolWindowPanel);
5256
toolWindowPanel.setToolbar(toolbar.getComponent());
5357

54-
Content content = contentFactory.createContent(toolWindowPanel, "Report", false);
58+
Content content = contentFactory.createContent(toolWindowPanel, name, false);
5559
toolWindow.getContentManager().addContent(content);
5660
}
5761
}

src/main/java/org/intellij/sdk/settings/AppSettings.java renamed to src/main/java/com/mercedesbenz/sechub/sdk/settings/AppSettings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.intellij.sdk.settings;
1+
package com.mercedesbenz.sechub.sdk.settings;
22

33
import com.intellij.openapi.application.ApplicationManager;
44
import com.intellij.openapi.components.PersistentStateComponent;
@@ -8,7 +8,7 @@
88
import org.jetbrains.annotations.NotNull;
99

1010
@State(
11-
name = "org.intellij.sdk.settings.AppSettings",
11+
name = "com.mercedesbenz.sechub.sdk.settings.AppSettings",
1212
storages = @Storage("SdkSettingsPlugin.xml")
1313
)
1414
public final class AppSettings

src/main/java/org/intellij/sdk/settings/AppSettingsComponent.java renamed to src/main/java/com/mercedesbenz/sechub/sdk/settings/AppSettingsComponent.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.intellij.sdk.settings;
1+
package com.mercedesbenz.sechub.sdk.settings;
22

33
import com.intellij.ui.components.JBLabel;
44
import com.intellij.ui.components.JBPasswordField;
@@ -7,11 +7,7 @@
77
import org.jetbrains.annotations.NotNull;
88

99
import javax.swing.*;
10-
import java.util.Arrays;
1110

12-
/**
13-
* Supports creating and managing a {@link JPanel} for the Settings Dialog.
14-
*/
1511
public class AppSettingsComponent {
1612

1713
private final JPanel mainPanel;

src/main/java/org/intellij/sdk/settings/AppSettingsConfigurable.java renamed to src/main/java/com/mercedesbenz/sechub/sdk/settings/AppSettingsConfigurable.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
package org.intellij.sdk.settings;
1+
package com.mercedesbenz.sechub.sdk.settings;
22

33
import com.intellij.credentialStore.CredentialAttributes;
44
import com.intellij.credentialStore.CredentialAttributesKt;
55
import com.intellij.credentialStore.Credentials;
66
import com.intellij.ide.passwordSafe.PasswordSafe;
77
import com.intellij.openapi.options.Configurable;
8+
import com.mercedesbenz.sechub.plugin.idea.window.SecHubServerPanel;
89
import org.jetbrains.annotations.Nls;
910
import org.jetbrains.annotations.Nullable;
1011

1112
import javax.swing.*;
1213
import java.util.Objects;
1314

14-
/**
15+
/*
1516
* Provides controller functionality for application settings.
1617
*/
1718
final class AppSettingsConfigurable implements Configurable {
@@ -20,7 +21,6 @@ final class AppSettingsConfigurable implements Configurable {
2021

2122
private final String sechubCredentialsKey = "SECHUB_CREDENTIALS";
2223

23-
2424
// A default constructor with no arguments is required because
2525
// this implementation is registered as an applicationConfigurable
2626

@@ -65,8 +65,11 @@ public void apply() {
6565
AppSettings.State state =
6666
Objects.requireNonNull(AppSettings.getInstance().getState());
6767
state.serverURL = appSettingsComponent.getServerUrlText();
68+
// Updating the server URL in the SecHubServerPanel
69+
SecHubServerPanel secHubServerPanel = SecHubServerPanel.getInstance();
70+
secHubServerPanel.update(state.serverURL);
6871

69-
CredentialAttributes attributes = createCredentialAttributes(sechubCredentialsKey);
72+
CredentialAttributes attributes = createCredentialAttributes();
7073
Credentials credentials = new Credentials(appSettingsComponent.getUserNameText(), appSettingsComponent.getApiTokenPassword());
7174

7275
PasswordSafe.getInstance().set(attributes, credentials);
@@ -97,14 +100,14 @@ public void disposeUIResources() {
97100
}
98101

99102
private Credentials retrieveCredentials() {
100-
CredentialAttributes attributes = createCredentialAttributes(sechubCredentialsKey);
103+
CredentialAttributes attributes = createCredentialAttributes();
101104
PasswordSafe passwordSafe = PasswordSafe.getInstance();
102105
return passwordSafe.get(attributes);
103106
}
104107

105-
private CredentialAttributes createCredentialAttributes(String key) {
108+
private CredentialAttributes createCredentialAttributes() {
106109
return new CredentialAttributes(
107-
CredentialAttributesKt.generateServiceName("SecHub", key)
110+
CredentialAttributesKt.generateServiceName("SecHub", sechubCredentialsKey)
108111
);
109112
}
110113
}

src/main/resources/META-INF/plugin.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
<!-- Add your extensions here -->
1919
<toolWindow id="SecHub" icon="/icons/toolWindowSecHub.svg" factoryClass="com.mercedesbenz.sechub.plugin.idea.window.SecHubToolWindowFactory" anchor="left"/>
2020

21-
<applicationService serviceImplementation="org.intellij.sdk.settings.AppSettings"/>
21+
<!-- Extension for storing server credentials (package need to be in main/java) -->
22+
<applicationService serviceImplementation="com.mercedesbenz.sechub.sdk.settings.AppSettings"/>
2223

23-
<applicationConfigurable parentId="tools" instance="org.intellij.sdk.settings.AppSettingsConfigurable"
24-
id="org.intellij.sdk.settings.AppSettingsConfigurable"
24+
<applicationConfigurable parentId="tools" instance="com.mercedesbenz.sechub.sdk.settings.AppSettingsConfigurable"
25+
id="com.mercedesbenz.sechub.sdk.settings.AppSettingsConfigurable"
2526
displayName="SecHub"/>
2627
</extensions>
2728

0 commit comments

Comments
 (0)