From f8b7e88ba0da26b11dfa8d7c1218affb86ab284a Mon Sep 17 00:00:00 2001 From: nickchecan Date: Wed, 15 Jan 2025 20:54:24 -0600 Subject: [PATCH] feat: implement ollama login pages --- .../zjoule/plugin/login/LoginWizard.java | 6 +- .../plugin/login/OllamaLoginWizard.java | 33 +++++++++ .../login/pages/FirstOllamaLoginPage.java | 74 +++++++++++++++++++ .../login/pages/SecondOllamaLoginPage.java | 53 +++++++++++++ 4 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/OllamaLoginWizard.java create mode 100644 com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/FirstOllamaLoginPage.java create mode 100644 com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/SecondOllamaLoginPage.java diff --git a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/LoginWizard.java b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/LoginWizard.java index 8e5fd72..a05e6d6 100644 --- a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/LoginWizard.java +++ b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/LoginWizard.java @@ -49,9 +49,9 @@ private void startSapAiCoreLogin() { } private void startOllamaLogin() { -// OllamaLoginWizard wizard = new OllamaLoginWizard(browser); -// WizardDialog dialog = new WizardDialog(shell, wizard); -// dialog.open(); + OllamaLoginWizard wizard = new OllamaLoginWizard(browser); + WizardDialog dialog = new WizardDialog(shell, wizard); + dialog.open(); } } diff --git a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/OllamaLoginWizard.java b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/OllamaLoginWizard.java new file mode 100644 index 0000000..da5156b --- /dev/null +++ b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/OllamaLoginWizard.java @@ -0,0 +1,33 @@ +package com.developer.nefarious.zjoule.plugin.login; + +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.swt.browser.Browser; + +import com.developer.nefarious.zjoule.plugin.login.pages.FirstOllamaLoginPage; +import com.developer.nefarious.zjoule.plugin.login.pages.SecondOllamaLoginPage; + +public class OllamaLoginWizard extends Wizard { + + private Browser browser; + + public OllamaLoginWizard(final Browser browser) { + this.browser = browser; + + setWindowTitle("Login to Ollama"); + } + + @Override + public void addPages() { + addPage(new FirstOllamaLoginPage()); + addPage(new SecondOllamaLoginPage()); + } + + @Override + public boolean performFinish() { +// TemporaryMemoryOllamaConfig.getInstance().persist(); + +// SessionManager.login(browser); + return true; + } + +} diff --git a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/FirstOllamaLoginPage.java b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/FirstOllamaLoginPage.java new file mode 100644 index 0000000..1488435 --- /dev/null +++ b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/FirstOllamaLoginPage.java @@ -0,0 +1,74 @@ +package com.developer.nefarious.zjoule.plugin.login.pages; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +public class FirstOllamaLoginPage extends WizardPage { + + public static final String PAGE_ID = "Ollama Login First Page"; + + private Text endpointText; + + private Text errorText; + + public FirstOllamaLoginPage() { + super(PAGE_ID); + + setTitle("Ollama Setup"); + setDescription("Enter the host and port for the local Ollama instance."); + setPageComplete(false); // Initially set the page as incomplete + } + + @Override + public void createControl(final Composite parent) { + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(new GridLayout(2, false)); + + Label inputLabel = new Label(container, SWT.NONE); + inputLabel.setText("Ollama Endpoint:"); + + endpointText = new Text(container, SWT.BORDER); + endpointText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + endpointText.setText("http://localhost:11434"); + + // Hidden error text widget + errorText = new Text(container, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP); + GridData errorTextGridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1); + errorText.setLayoutData(errorTextGridData); + errorText.setForeground(container.getDisplay().getSystemColor(SWT.COLOR_RED)); + errorText.setVisible(false); // Initially hidden + + setControl(container); + } + + @Override + public boolean canFlipToNextPage() { + return true; + } + + @Override + public IWizardPage getNextPage() { + + String input = endpointText.getText(); + + if (input == null || input.isEmpty() || input.isBlank()) { + displayErrorMessage("Please, enter a local Ollama endpoint to proceed."); + return null; + } + + errorText.setVisible(false); + return super.getNextPage(); // Proceed to the next page + } + + private void displayErrorMessage(final String message) { + errorText.setText(message); + errorText.setVisible(true); + } + +} diff --git a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/SecondOllamaLoginPage.java b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/SecondOllamaLoginPage.java new file mode 100644 index 0000000..566a3dd --- /dev/null +++ b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/SecondOllamaLoginPage.java @@ -0,0 +1,53 @@ +package com.developer.nefarious.zjoule.plugin.login.pages; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +public class SecondOllamaLoginPage extends WizardPage { + + public static final String PAGE_ID = "Ollama Login Second Page"; + + private Combo modelDropdown; + + private List modelsForSelection = new ArrayList<>(); + + public SecondOllamaLoginPage() { + super(PAGE_ID); + + setTitle("Ollama Setup"); + setDescription("Select the Ollama model."); + setPageComplete(false); // Initially set the page as incomplete + } + + @Override + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(new GridLayout(2, false)); + + Label modelLabel = new Label(container, SWT.NONE); + modelLabel.setText("Select the Model:"); + + modelDropdown = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY); + modelDropdown.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + modelDropdown.addListener(SWT.Selection, event -> selectModel()); + + setControl(container); + } + + private void selectModel() { + setPageComplete(true); + } + + public void setModelsForSelection(List modelsForSelection) { + modelDropdown.setItems(modelsForSelection.toArray(new String[0])); + } + +}