Skip to content

Commit

Permalink
feat: implement ollama login pages
Browse files Browse the repository at this point in the history
  • Loading branch information
nickchecan committed Jan 16, 2025
1 parent da29299 commit f8b7e88
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> modelsForSelection) {
modelDropdown.setItems(modelsForSelection.toArray(new String[0]));
}

}

0 comments on commit f8b7e88

Please sign in to comment.