Commit 87987e2f authored by Matija Obreza's avatar Matija Obreza
Browse files

Settings model and Settings dialog

parent 0856d8b4
......@@ -3,6 +3,7 @@ package org.genesys2.anno.gui;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.genesys2.anno.model.Settings;
import org.genesys2.anno.parser.CsvDataSourceParser;
import org.genesys2.anno.parser.XlsxDataSourceParser;
......@@ -17,6 +18,7 @@ public class AppConfig {
private DataSourceLoaderImpl dataSourceLoader;
private ExecutorService executorService = Executors.newFixedThreadPool(5);
private ColumnDefs columnDefs = new ColumnDefs();
private Settings settings = new Settings();
private AppConfig() {
dataSourceLoader = new DataSourceLoaderImpl();
......@@ -39,4 +41,8 @@ public class AppConfig {
public ColumnDefs getColumnDefs() {
return columnDefs;
}
public Settings getSettings() {
return settings;
}
}
......@@ -32,14 +32,26 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceAdapter;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.*;
import org.eclipse.wb.swt.SWTResourceManager;
import org.genesys2.anno.model.ColumnDef;
import org.json.JSONException;
import org.genesys2.anno.model.Settings;
import swing2swt.layout.BorderLayout;
import java.io.File;
......@@ -55,6 +67,7 @@ public class AppWindow {
private DataBindingContext m_bindingContext;
private DwcaBuilder builder = new DwcaBuilder();
private ColumnDefs columnDefs = AppConfig.instance.getColumnDefs();
private Settings settings = AppConfig.instance.getSettings();
private ExecutorService threadPool = Executors.newFixedThreadPool(4);
private static class ViewerLabelProvider extends LabelProvider {
......@@ -235,6 +248,15 @@ public class AppWindow {
MenuItem mntmOpen = new MenuItem(menu_1, SWT.NONE);
mntmOpen.setText("Open");
MenuItem mntmSettings = new MenuItem(menu_1, SWT.NONE);
mntmSettings.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doSettings();
}
});
mntmSettings.setText("Settings ...");
new MenuItem(menu_1, SWT.SEPARATOR);
mntmQuit = new MenuItem(menu_1, SWT.NONE);
......@@ -473,6 +495,15 @@ public class AppWindow {
});
loadWorkSpace.setText("Load workspace");
ToolItem tltmSettings = new ToolItem(toolBar, SWT.NONE);
tltmSettings.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doSettings();
}
});
tltmSettings.setText("Settings");
m_bindingContext = initDataBindings();
}
......@@ -530,6 +561,11 @@ public class AppWindow {
pushDialog.open();
}
protected void doSettings() {
SettingsDialog settingsDialog = new SettingsDialog(this.settings, shlGenesysMagic, SWT.NONE);
settingsDialog.open();
}
protected void doAutomap() {
final DataSourceSheet dss = getCurrentDataSourceSheet();
if (dss == null) {
......
package org.genesys2.anno.gui;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
import org.genesys2.anno.model.Settings;
import org.omg.CORBA.COMM_FAILURE;
import swing2swt.layout.BorderLayout;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.custom.ScrolledComposite;
public class SettingsDialog extends Dialog {
private DataBindingContext m_bindingContext;
private Settings settings;
protected Object result;
protected Shell shell;
private Text txtGenesysURL;
private Text txtAuthorizationEndpoint;
private Text txtTokenEndpoint;
private Text txtApiUrl;
private Text txtAccessToken;
private Text txtRefreshToken;
/**
* Create the dialog.
*
* @param parent
* @param style
*/
public SettingsDialog(Settings settings, Shell parent, int style) {
super(parent, style);
this.settings = settings;
setText("Preferences");
}
/**
* Open the dialog.
*
* @return the result
*/
public Object open() {
createContents();
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return result;
}
/**
* Create contents of the dialog.
*/
private void createContents() {
shell = new Shell(getParent(), SWT.SHELL_TRIM);
shell.setSize(665, 445);
shell.setText(getText());
shell.setLayout(new BorderLayout(0, 0));
TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
tabFolder.setLayoutData(BorderLayout.CENTER);
TabItem tbtmGenesysApi = new TabItem(tabFolder, SWT.NONE);
tbtmGenesysApi.setText("Genesys API");
ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.V_SCROLL);
scrolledComposite.setShowFocusedControl(true);
tbtmGenesysApi.setControl(scrolledComposite);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
Composite composite = new Composite(scrolledComposite, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
Group grpGenesysApiConfiguration = new Group(composite, SWT.NONE);
grpGenesysApiConfiguration.setLayout(new GridLayout(2, false));
grpGenesysApiConfiguration.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
grpGenesysApiConfiguration.setText("Genesys API configuration");
Label lblGenesysServer = new Label(grpGenesysApiConfiguration, SWT.NONE);
GridData gd_lblGenesysServer = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_lblGenesysServer.widthHint = 150;
lblGenesysServer.setLayoutData(gd_lblGenesysServer);
lblGenesysServer.setAlignment(SWT.RIGHT);
lblGenesysServer.setText("Genesys Server URL");
txtGenesysURL = new Text(grpGenesysApiConfiguration, SWT.BORDER);
txtGenesysURL.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblAuthorizationEndpoint = new Label(grpGenesysApiConfiguration, SWT.NONE);
lblAuthorizationEndpoint.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblAuthorizationEndpoint.setAlignment(SWT.RIGHT);
lblAuthorizationEndpoint.setText("Authorization endpoint");
txtAuthorizationEndpoint = new Text(grpGenesysApiConfiguration, SWT.BORDER);
txtAuthorizationEndpoint.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblTokenEndpoint = new Label(grpGenesysApiConfiguration, SWT.NONE);
lblTokenEndpoint.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblTokenEndpoint.setAlignment(SWT.RIGHT);
lblTokenEndpoint.setText("Token endpoint");
txtTokenEndpoint = new Text(grpGenesysApiConfiguration, SWT.BORDER);
txtTokenEndpoint.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblGenesysApiUrl = new Label(grpGenesysApiConfiguration, SWT.NONE);
lblGenesysApiUrl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblGenesysApiUrl.setAlignment(SWT.RIGHT);
lblGenesysApiUrl.setText("Genesys API URL");
txtApiUrl = new Text(grpGenesysApiConfiguration, SWT.BORDER);
txtApiUrl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Group grpOauthTokens = new Group(composite, SWT.NONE);
grpOauthTokens.setLayout(new GridLayout(2, false));
grpOauthTokens.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
grpOauthTokens.setText("OAuth Tokens");
Label lblAccessToken = new Label(grpOauthTokens, SWT.NONE);
lblAccessToken.setAlignment(SWT.RIGHT);
GridData gd_lblAccessToken = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
gd_lblAccessToken.widthHint = 150;
lblAccessToken.setLayoutData(gd_lblAccessToken);
lblAccessToken.setText("Access token");
txtAccessToken = new Text(grpOauthTokens, SWT.BORDER);
txtAccessToken.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblRefreshToken = new Label(grpOauthTokens, SWT.NONE);
lblRefreshToken.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblRefreshToken.setText("Refresh token");
txtRefreshToken = new Text(grpOauthTokens, SWT.BORDER);
txtRefreshToken.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Composite composite_1 = new Composite(composite, SWT.NONE);
GridData gd_composite_1 = new GridData(SWT.LEFT, SWT.TOP, true, false, 1, 1);
gd_composite_1.horizontalIndent = 160;
composite_1.setLayoutData(gd_composite_1);
composite_1.setLayout(new RowLayout(SWT.HORIZONTAL));
Button btnClearTokens = new Button(composite_1, SWT.NONE);
btnClearTokens.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
settings.getOauthSettings().clearTokens();
}
});
btnClearTokens.setText("Clear tokens");
Button btnAuthenticate = new Button(composite_1, SWT.NONE);
btnAuthenticate.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doAuthenticate();
}
});
btnAuthenticate.setText("Authenticate");
composite.pack();
scrolledComposite.setContent(composite);
scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
TabItem tbtmTodo = new TabItem(tabFolder, SWT.NONE);
tbtmTodo.setText("TODO");
m_bindingContext = initDataBindings();
}
protected void doAuthenticate() {
// TODO
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
IObservableValue observeTextTxtGenesysURLObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtGenesysURL);
IObservableValue oauthSettingsserverUrlSettingsObserveValue = BeanProperties.value("oauthSettings.serverUrl").observe(settings);
bindingContext.bindValue(observeTextTxtGenesysURLObserveWidget, oauthSettingsserverUrlSettingsObserveValue, null, null);
//
IObservableValue observeTextTxtAuthorizationEndpointObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtAuthorizationEndpoint);
IObservableValue oauthSettingsauthorizationEndpointSettingsObserveValue = BeanProperties.value("oauthSettings.authorizationEndpoint").observe(settings);
bindingContext.bindValue(observeTextTxtAuthorizationEndpointObserveWidget, oauthSettingsauthorizationEndpointSettingsObserveValue, null, null);
//
IObservableValue observeTextTxtTokenEndpointObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtTokenEndpoint);
IObservableValue oauthSettingstokenEndpointSettingsObserveValue = BeanProperties.value("oauthSettings.tokenEndpoint").observe(settings);
bindingContext.bindValue(observeTextTxtTokenEndpointObserveWidget, oauthSettingstokenEndpointSettingsObserveValue, null, null);
//
IObservableValue observeTextTxtApiUrlObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtApiUrl);
IObservableValue oauthSettingsapiUrlSettingsObserveValue = BeanProperties.value("oauthSettings.apiUrl").observe(settings);
bindingContext.bindValue(observeTextTxtApiUrlObserveWidget, oauthSettingsapiUrlSettingsObserveValue, null, null);
//
IObservableValue observeTextTxtAccessTokenObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtAccessToken);
IObservableValue oauthSettingsaccessTokenSettingsObserveValue = BeanProperties.value("oauthSettings.accessToken").observe(settings);
bindingContext.bindValue(observeTextTxtAccessTokenObserveWidget, oauthSettingsaccessTokenSettingsObserveValue, null, null);
//
IObservableValue observeTextTxtRefreshTokenObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtRefreshToken);
IObservableValue oauthSettingsrefreshTokenSettingsObserveValue = BeanProperties.value("oauthSettings.refreshToken").observe(settings);
bindingContext.bindValue(observeTextTxtRefreshTokenObserveWidget, oauthSettingsrefreshTokenSettingsObserveValue, null, null);
//
return bindingContext;
}
}
package org.genesys2.anno.model;
import org.genesys2.anno.gui.AbstractModelObject;
public class OAuthSettings extends AbstractModelObject {
private String serverUrl = "http://localhost:8080/";
private String authorizationEndpoint = "http://localhost:8080/oauth/authorize";
private String tokenEndpoint = "http://localhost:8080/oauth/token";
private String apiUrl = "http://localhost:8080/api/v0";
private String accessToken = "";
private String refreshToken = "";
public String getServerUrl() {
return serverUrl;
}
public void setServerUrl(String serverUrl) {
this.serverUrl = serverUrl;
setAuthorizationEndpoint(this.serverUrl + "/oauth/authorize");
setTokenEndpoint(this.serverUrl + "/oauth/token");
setApiUrl(this.serverUrl + "/api/v0");
firePropertyChange("serverUrl", null, this.serverUrl);
}
public String getAuthorizationEndpoint() {
return authorizationEndpoint;
}
public void setAuthorizationEndpoint(String authorizationEndpoint) {
this.authorizationEndpoint = authorizationEndpoint;
firePropertyChange("authorizationEndpoint", null, this.authorizationEndpoint);
}
public String getTokenEndpoint() {
return tokenEndpoint;
}
public void setTokenEndpoint(String tokenEndpoint) {
this.tokenEndpoint = tokenEndpoint;
firePropertyChange("tokenEndpoint", null, this.tokenEndpoint);
}
public String getApiUrl() {
return apiUrl;
}
public void setApiUrl(String apiUrl) {
this.apiUrl = apiUrl;
firePropertyChange("apiUrl", null, this.apiUrl);
}
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
firePropertyChange("accessToken", null, this.accessToken);
}
public String getRefreshToken() {
return refreshToken;
}
public void setRefreshToken(String refreshToken) {
this.refreshToken = refreshToken;
firePropertyChange("refreshToken", null, this.refreshToken);
}
public void clearTokens() {
setAccessToken("");
setRefreshToken("");
}
}
package org.genesys2.anno.model;
import org.genesys2.anno.gui.AbstractModelObject;
public class Settings extends AbstractModelObject {
private OAuthSettings oauthSettings = new OAuthSettings();
public OAuthSettings getOauthSettings() {
return oauthSettings;
}
public void setOauthSettings(OAuthSettings oauthSettings) {
this.oauthSettings = oauthSettings;
firePropertyChange("oauthSettings", null, this.oauthSettings);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment