Skip to content

Commit 735cb09

Browse files
committed
feat: display connection configuration on preferences window
1 parent c6531ef commit 735cb09

File tree

4 files changed

+228
-13
lines changed

4 files changed

+228
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.developer.nefarious.zjoule.plugin.core.preferences;
2+
3+
import org.eclipse.jface.preference.StringFieldEditor;
4+
import org.eclipse.swt.SWT;
5+
import org.eclipse.swt.layout.GridData;
6+
import org.eclipse.swt.widgets.Composite;
7+
8+
public class InputField extends StringFieldEditor {
9+
10+
private static final int WIDTH_IN_CHARS = 10;
11+
12+
private static final int HEIGTH_IN_CHARS = 2;
13+
14+
private static final int MINIMUM_WIDTH = 300;
15+
16+
private static final int MINIMUM_HEIGHT = 50;
17+
18+
public InputField(final String key, final String labelText, final Composite parent) {
19+
super(key, labelText, WIDTH_IN_CHARS, HEIGTH_IN_CHARS, VALIDATE_ON_FOCUS_LOST, parent);
20+
setFixedWidth(parent);
21+
}
22+
23+
private void setFixedWidth(final Composite parent) {
24+
if (getTextControl(parent) != null) {
25+
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
26+
gridData.widthHint = MINIMUM_WIDTH;
27+
gridData.heightHint = MINIMUM_HEIGHT;
28+
getTextControl(parent).setLayoutData(gridData);
29+
}
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.developer.nefarious.zjoule.plugin.core.preferences;
2+
3+
import org.eclipse.jface.preference.StringFieldEditor;
4+
import org.eclipse.swt.SWT;
5+
import org.eclipse.swt.layout.GridData;
6+
import org.eclipse.swt.widgets.Composite;
7+
import org.eclipse.swt.widgets.Text;
8+
9+
public class OutputField extends StringFieldEditor {
10+
11+
private String currentValue = ""; // To hold the temporary value
12+
13+
private static final int MINIMUM_WIDTH = 300;
14+
15+
public OutputField(final String labelText, final String value, final Composite parent) {
16+
super("local", labelText, parent);
17+
setStringValue(value);
18+
setFixedWidth(parent);
19+
}
20+
21+
@Override
22+
protected void doLoadDefault() {
23+
// Do nothing to prevent the value from being reset
24+
}
25+
26+
@Override
27+
protected void createControl(final Composite parent) {
28+
super.createControl(parent);
29+
30+
// Set the Text widget to read-only
31+
Text textField = getTextControl();
32+
if (textField != null) {
33+
textField.setEditable(false);
34+
}
35+
}
36+
37+
@Override
38+
protected void doStore() {
39+
// Do nothing, as we don't want to store the value
40+
}
41+
42+
@Override
43+
protected void doLoad() {
44+
// Do nothing, as we don't want to load from the preference store
45+
}
46+
47+
@Override
48+
public void setStringValue(final String value) {
49+
super.setStringValue(value);
50+
this.currentValue = value; // Keep the value locally
51+
}
52+
53+
@Override
54+
public String getStringValue() {
55+
return this.currentValue; // Return the locally stored value
56+
}
57+
58+
private void setFixedWidth(final Composite parent) {
59+
// Retrieve the text control from the StringFieldEditor
60+
if (getTextControl(parent) != null) {
61+
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
62+
gridData.widthHint = MINIMUM_WIDTH;
63+
getTextControl(parent).setLayoutData(gridData);
64+
}
65+
}
66+
67+
}

com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/core/preferences/PluginPreferencesPage.java

Lines changed: 113 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,132 @@
1010
import org.eclipse.ui.IWorkbench;
1111
import org.eclipse.ui.IWorkbenchPreferencePage;
1212

13+
import com.developer.nefarious.zjoule.plugin.auth.SessionManager;
1314
import com.developer.nefarious.zjoule.plugin.core.Activator;
15+
import com.developer.nefarious.zjoule.plugin.memory.MemoryDeployment;
16+
import com.developer.nefarious.zjoule.plugin.memory.MemoryOllamaEndpoint;
17+
import com.developer.nefarious.zjoule.plugin.memory.MemoryOllamaModel;
18+
import com.developer.nefarious.zjoule.plugin.memory.MemoryResourceGroup;
1419

1520
public class PluginPreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
1621

22+
private static final int SPACER_SIZE = 10;
23+
24+
private static final int SPACER_WIDTH = 10;
25+
26+
private static final int SPACER_HEIGHT = 10;
27+
1728
public PluginPreferencesPage() {
18-
super(GRID);
19-
setPreferenceStore(Activator.getDefault().getPreferenceStore());
20-
}
29+
super(GRID);
30+
}
2131

2232
@Override
23-
public void init(final IWorkbench workbench) { }
33+
public void init(final IWorkbench workbench) {
34+
setPreferenceStore(Activator.getDefault().getPreferenceStore());
35+
}
2436

2537
@Override
2638
protected void createFieldEditors() {
27-
28-
Group group = new Group(getFieldEditorParent(), SWT.NONE);
29-
group.setText("Chat Settings");
30-
group.setLayout(new GridLayout(1, false));
31-
group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
3239

33-
Composite groupContent = new Composite(group, SWT.NONE);
34-
groupContent.setLayout(new GridLayout(1, false));
35-
groupContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
40+
displayInstructionsInput();
41+
42+
createSpacer();
43+
44+
if (SessionManager.isSapSession()) {
45+
displaySapSettings();
46+
} else if (SessionManager.isOllamaSession()) {
47+
displayOllamaSettings();
48+
}
49+
50+
}
51+
52+
private void displayInstructionsInput() {
53+
Group group = new Group(getFieldEditorParent(), SWT.NONE);
54+
group.setText("Chat Settings");
55+
group.setLayout(new GridLayout(1, false));
56+
group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
57+
58+
Composite groupContent = new Composite(group, SWT.NONE);
59+
groupContent.setLayout(new GridLayout(1, false));
60+
groupContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
61+
62+
addField(new InputField(Instruction.KEY, "Instructions:", groupContent));
63+
}
3664

37-
addField(new StringFieldEditor(Instruction.KEY, "Instructions:", groupContent));
65+
private void createSpacer() {
66+
Composite spacer = new Composite(getFieldEditorParent(), SWT.NONE);
67+
GridData gridData = new GridData(SPACER_WIDTH,SPACER_HEIGHT);
68+
gridData.heightHint = SPACER_SIZE;
69+
spacer.setLayoutData(gridData);
70+
}
71+
72+
private Composite createContentContainer(final String title) {
73+
Group group = new Group(getFieldEditorParent(), SWT.NONE);
74+
group.setText(title);
75+
group.setLayout(new GridLayout(1, false));
76+
group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
77+
78+
Composite groupContent = new Composite(group, SWT.NONE);
79+
groupContent.setLayout(new GridLayout(1, false));
80+
groupContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
81+
return groupContent;
82+
}
83+
84+
private void displaySapSettings() {
85+
Composite contentContainer = createContentContainer("SAP AI Core Configuration Parameters");
86+
87+
class OutputFieldFactory {
88+
StringFieldEditor create(final String key, final String value) {
89+
return new OutputField(key, value, contentContainer);
90+
}
91+
}
92+
93+
OutputFieldFactory outputFieldFactory = new OutputFieldFactory();
94+
95+
String resourceGroup = MemoryResourceGroup.getInstance().load();
96+
addField(outputFieldFactory.create("Resource Group:", resourceGroup));
97+
98+
String configurationName = MemoryDeployment.getInstance().load().getConfigurationName();
99+
addField(outputFieldFactory.create("Configuration Name:", configurationName));
100+
101+
String model = MemoryDeployment.getInstance().load().getModelName();
102+
addField(outputFieldFactory.create("Model:", model));
103+
104+
String deploymentUrl = MemoryDeployment.getInstance().load().getDeploymentUrl();
105+
addField(outputFieldFactory.create("Deployment Url:", deploymentUrl));
106+
}
107+
108+
private void displayOllamaSettings() {
109+
Composite contentContainer = createContentContainer("Ollama Configuration Parameters");
110+
111+
class OutputFieldFactory {
112+
StringFieldEditor create(final String key, final String value) {
113+
return new OutputField(key, value, contentContainer);
114+
}
115+
}
116+
117+
OutputFieldFactory outputFieldFactory = new OutputFieldFactory();
118+
119+
String endpoint = MemoryOllamaEndpoint.getInstance().load();
120+
addField(outputFieldFactory.create("Endpoint:", endpoint));
121+
122+
String name = MemoryOllamaModel.getInstance().load().getName();
123+
addField(outputFieldFactory.create("Name:", name));
124+
125+
String model = MemoryOllamaModel.getInstance().load().getModel();
126+
addField(outputFieldFactory.create("Model:", model));
127+
128+
String format = MemoryOllamaModel.getInstance().load().getFormat();
129+
addField(outputFieldFactory.create("Format:", format));
130+
131+
String family = MemoryOllamaModel.getInstance().load().getFamily();
132+
addField(outputFieldFactory.create("Family:", family));
133+
134+
String parameterSize = MemoryOllamaModel.getInstance().load().getParameterSize();
135+
addField(outputFieldFactory.create("Parameter Size:", parameterSize));
38136

137+
String quantizationLevel = MemoryOllamaModel.getInstance().load().getQuantizationLevel();
138+
addField(outputFieldFactory.create("Quantization Level:", quantizationLevel));
39139
}
40140

41141
}

com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/models/OllamaModel.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ public OllamaModelDetails getDetails() {
6767
public void setDetails(final OllamaModelDetails details) {
6868
this.details = details;
6969
}
70+
71+
public String getFormat() {
72+
return details.getFormat();
73+
}
74+
75+
public String getFamily() {
76+
return details.getFamily();
77+
}
78+
79+
public String getParameterSize() {
80+
return details.getParameterSize();
81+
}
82+
83+
public String getQuantizationLevel() {
84+
return details.getQuantizationLevel();
85+
}
7086

7187
}
7288

0 commit comments

Comments
 (0)