Skip to content

Commit f8b7e88

Browse files
author
nickchecan
committed
feat: implement ollama login pages
1 parent da29299 commit f8b7e88

File tree

4 files changed

+163
-3
lines changed

4 files changed

+163
-3
lines changed

com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/LoginWizard.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ private void startSapAiCoreLogin() {
4949
}
5050

5151
private void startOllamaLogin() {
52-
// OllamaLoginWizard wizard = new OllamaLoginWizard(browser);
53-
// WizardDialog dialog = new WizardDialog(shell, wizard);
54-
// dialog.open();
52+
OllamaLoginWizard wizard = new OllamaLoginWizard(browser);
53+
WizardDialog dialog = new WizardDialog(shell, wizard);
54+
dialog.open();
5555
}
5656

5757
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.developer.nefarious.zjoule.plugin.login;
2+
3+
import org.eclipse.jface.wizard.Wizard;
4+
import org.eclipse.swt.browser.Browser;
5+
6+
import com.developer.nefarious.zjoule.plugin.login.pages.FirstOllamaLoginPage;
7+
import com.developer.nefarious.zjoule.plugin.login.pages.SecondOllamaLoginPage;
8+
9+
public class OllamaLoginWizard extends Wizard {
10+
11+
private Browser browser;
12+
13+
public OllamaLoginWizard(final Browser browser) {
14+
this.browser = browser;
15+
16+
setWindowTitle("Login to Ollama");
17+
}
18+
19+
@Override
20+
public void addPages() {
21+
addPage(new FirstOllamaLoginPage());
22+
addPage(new SecondOllamaLoginPage());
23+
}
24+
25+
@Override
26+
public boolean performFinish() {
27+
// TemporaryMemoryOllamaConfig.getInstance().persist();
28+
29+
// SessionManager.login(browser);
30+
return true;
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.developer.nefarious.zjoule.plugin.login.pages;
2+
3+
import org.eclipse.jface.wizard.IWizardPage;
4+
import org.eclipse.jface.wizard.WizardPage;
5+
import org.eclipse.swt.SWT;
6+
import org.eclipse.swt.layout.GridData;
7+
import org.eclipse.swt.layout.GridLayout;
8+
import org.eclipse.swt.widgets.Composite;
9+
import org.eclipse.swt.widgets.Label;
10+
import org.eclipse.swt.widgets.Text;
11+
12+
public class FirstOllamaLoginPage extends WizardPage {
13+
14+
public static final String PAGE_ID = "Ollama Login First Page";
15+
16+
private Text endpointText;
17+
18+
private Text errorText;
19+
20+
public FirstOllamaLoginPage() {
21+
super(PAGE_ID);
22+
23+
setTitle("Ollama Setup");
24+
setDescription("Enter the host and port for the local Ollama instance.");
25+
setPageComplete(false); // Initially set the page as incomplete
26+
}
27+
28+
@Override
29+
public void createControl(final Composite parent) {
30+
Composite container = new Composite(parent, SWT.NONE);
31+
container.setLayout(new GridLayout(2, false));
32+
33+
Label inputLabel = new Label(container, SWT.NONE);
34+
inputLabel.setText("Ollama Endpoint:");
35+
36+
endpointText = new Text(container, SWT.BORDER);
37+
endpointText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
38+
endpointText.setText("http://localhost:11434");
39+
40+
// Hidden error text widget
41+
errorText = new Text(container, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP);
42+
GridData errorTextGridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
43+
errorText.setLayoutData(errorTextGridData);
44+
errorText.setForeground(container.getDisplay().getSystemColor(SWT.COLOR_RED));
45+
errorText.setVisible(false); // Initially hidden
46+
47+
setControl(container);
48+
}
49+
50+
@Override
51+
public boolean canFlipToNextPage() {
52+
return true;
53+
}
54+
55+
@Override
56+
public IWizardPage getNextPage() {
57+
58+
String input = endpointText.getText();
59+
60+
if (input == null || input.isEmpty() || input.isBlank()) {
61+
displayErrorMessage("Please, enter a local Ollama endpoint to proceed.");
62+
return null;
63+
}
64+
65+
errorText.setVisible(false);
66+
return super.getNextPage(); // Proceed to the next page
67+
}
68+
69+
private void displayErrorMessage(final String message) {
70+
errorText.setText(message);
71+
errorText.setVisible(true);
72+
}
73+
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.developer.nefarious.zjoule.plugin.login.pages;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.eclipse.jface.wizard.WizardPage;
7+
import org.eclipse.swt.SWT;
8+
import org.eclipse.swt.layout.GridData;
9+
import org.eclipse.swt.layout.GridLayout;
10+
import org.eclipse.swt.widgets.Combo;
11+
import org.eclipse.swt.widgets.Composite;
12+
import org.eclipse.swt.widgets.Label;
13+
14+
public class SecondOllamaLoginPage extends WizardPage {
15+
16+
public static final String PAGE_ID = "Ollama Login Second Page";
17+
18+
private Combo modelDropdown;
19+
20+
private List<String> modelsForSelection = new ArrayList<>();
21+
22+
public SecondOllamaLoginPage() {
23+
super(PAGE_ID);
24+
25+
setTitle("Ollama Setup");
26+
setDescription("Select the Ollama model.");
27+
setPageComplete(false); // Initially set the page as incomplete
28+
}
29+
30+
@Override
31+
public void createControl(Composite parent) {
32+
Composite container = new Composite(parent, SWT.NONE);
33+
container.setLayout(new GridLayout(2, false));
34+
35+
Label modelLabel = new Label(container, SWT.NONE);
36+
modelLabel.setText("Select the Model:");
37+
38+
modelDropdown = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
39+
modelDropdown.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
40+
modelDropdown.addListener(SWT.Selection, event -> selectModel());
41+
42+
setControl(container);
43+
}
44+
45+
private void selectModel() {
46+
setPageComplete(true);
47+
}
48+
49+
public void setModelsForSelection(List<String> modelsForSelection) {
50+
modelDropdown.setItems(modelsForSelection.toArray(new String[0]));
51+
}
52+
53+
}

0 commit comments

Comments
 (0)