Commit 23fbea3f authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

Advanced settings GUI

parent 18d749b2
......@@ -35,7 +35,6 @@ 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.Control;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
......@@ -45,6 +44,9 @@ import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.genesys2.anno.model.InstCodeSettings;
import org.genesys2.anno.model.OAuthSettings;
......@@ -93,7 +95,7 @@ public class SettingsDialog extends Dialog {
private Text txtClientSecret;
private Text txtScope;
private Text txtInstCodesToIgnore;
private Composite grpInstCodes;
private Table instCodesTable;
/**
* Create the dialog.
......@@ -206,24 +208,30 @@ public class SettingsDialog extends Dialog {
Composite composite = new Composite(tabContents, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
composite.setLayoutData(new GridData(SWT.TOP, SWT.TOP, true, true));
renderAdvancedControllSection(composite);
Group instCodesGroup = new Group(composite, SWT.BORDER);
instCodesGroup.setLayout(new GridLayout());
Group instCodesGroup = new Group(composite, SWT.NONE);
instCodesGroup.setLayout(new GridLayout(2, false));
instCodesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
instCodesGroup.setText("Selected institute codes");
grpInstCodes = new Composite(instCodesGroup, SWT.FILL);
grpInstCodes.setLayout(new GridLayout(6, true));
grpInstCodes.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
renderInstCodesList(instCodesGroup);
renderInstCodesList(composite);
composite.pack();
tabContents.setContent(composite);
tabContents.setMinSize(composite.computeSize(SWT.FILL, SWT.FILL));
instCodesGroup.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
composite.setSize(composite.computeSize(SWT.DEFAULT, tabFolder.getSize().y - tabContents.getSize().y - 32));
tabContents.setMinSize(composite.getSize());
shell.addListener(SWT.Close, new Listener() {
public void handleEvent(Event event) {
try {
settings.save(workspacePath + "/local.properties");
} catch (IOException err) {
System.err.println("Failed to save props: " + err.getMessage());
}
}
});
}
private void renderAdvancedControllSection(Composite composite) {
......@@ -231,10 +239,10 @@ public class SettingsDialog extends Dialog {
Group controlSection = new Group(composite, SWT.BORDER);
controlSection.setLayout(new GridLayout(1, false));
controlSection.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
controlSection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
controlSection.setText("Institute codes filtering");
Composite radioButtonsComposite = new Composite(controlSection, SWT.NONE);
Composite radioButtonsComposite = new Composite(controlSection, SWT.FILL);
radioButtonsComposite.setLayout(new GridLayout(2, false));
Button isWhitelistButton = new Button(radioButtonsComposite, SWT.RADIO);
......@@ -256,83 +264,119 @@ public class SettingsDialog extends Dialog {
});
isBlacklitButton.setSelection(instCodeSettings.isBlackList());
isBlacklitButton.setText("Blacklist");
}
Button saveBtn = new Button(composite, SWT.NONE);
saveBtn.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
saveBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
settings.save(workspacePath + "/local.properties");
} catch (IOException err) {
System.err.println("Failed to load props: " + err.getMessage());
}
}
});
saveBtn.setText("Save");
private void renderInstCodesList(Composite parent) {
InstCodeSettings instCodeSettings = settings.getInstCodeSettings();
Composite addCodeGroup = new Composite(parent, SWT.NONE);
addCodeGroup.setLayout(new GridLayout(3, false));
addCodeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
txtInstCodesToIgnore = new Text(controlSection, SWT.BORDER);
Label addText = new Label(addCodeGroup, SWT.NONE);
addText.setText("New entry");
txtInstCodesToIgnore = new Text(addCodeGroup, SWT.BORDER);
txtInstCodesToIgnore.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
txtInstCodesToIgnore.setTextLimit(6);
txtInstCodesToIgnore.addListener(SWT.FocusOut, new Listener() {
txtInstCodesToIgnore.addKeyListener(new KeyAdapter() {
@Override
public void handleEvent(Event event) {
if (!txtInstCodesToIgnore.getText().trim().isEmpty()) {
instCodeSettings.getInstCodes().add(txtInstCodesToIgnore.getText().trim());
public void keyReleased(KeyEvent e) {
final int ENTER_KEY_CODE = 13;
if (e.keyCode == ENTER_KEY_CODE && !txtInstCodesToIgnore.getText().trim().isEmpty()) {
if (instCodeSettings.getInstCodes().add(txtInstCodesToIgnore.getText().trim())) {
TableItem item = new TableItem(instCodesTable, SWT.NULL);
item.setText(txtInstCodesToIgnore.getText().trim());
item.setText(0, txtInstCodesToIgnore.getText().trim());
for (TableColumn column : instCodesTable.getColumns()) {
column.pack();
}
instCodesTable.redraw();
}
txtInstCodesToIgnore.setText("");
renderInstCodesList(composite);
}
}
});
txtInstCodesToIgnore.addKeyListener(new KeyAdapter() {
Button addToListBtn = new Button(addCodeGroup, SWT.NONE);
addToListBtn.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
addToListBtn.setText("Add to list");
addToListBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void keyReleased(KeyEvent e) {
final int ENTER_KEY_CODE = 13;
if (e.keyCode == ENTER_KEY_CODE && !txtInstCodesToIgnore.getText().trim().isEmpty()) {
instCodeSettings.getInstCodes().add(txtInstCodesToIgnore.getText().trim());
public void widgetSelected(SelectionEvent event) {
if (!txtInstCodesToIgnore.getText().trim().isEmpty()) {
if (instCodeSettings.getInstCodes().add(txtInstCodesToIgnore.getText().trim())) {
TableItem item = new TableItem(instCodesTable, SWT.NULL);
item.setText(txtInstCodesToIgnore.getText().trim());
item.setText(0, txtInstCodesToIgnore.getText().trim());
for (TableColumn column : instCodesTable.getColumns()) {
column.pack();
column.setWidth(200);
}
instCodesTable.redraw();
}
txtInstCodesToIgnore.setText("");
renderInstCodesList(composite);
}
}
});
}
private void renderInstCodesList(Composite parent) {
InstCodeSettings instCodeSettings = settings.getInstCodeSettings();
Set<String> instCodes = instCodeSettings.getInstCodes();
Label separator = new Label(parent, SWT.HORIZONTAL | SWT.SEPARATOR);
separator.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
if (grpInstCodes != null) {
for (Control control : grpInstCodes.getChildren()) {
control.dispose();
}
instCodesTable = new Table(parent, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
instCodesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
instCodesTable.setHeaderVisible(true);
String[] titles = {"Institute code"};
for (String header : titles) {
TableColumn column = new TableColumn(instCodesTable, SWT.NULL);
column.setWidth(240);
column.setResizable(false);
column.setText(header);
}
Set<String> instCodes = instCodeSettings.getInstCodes();
for (String instCode : instCodes) {
Group someGroup = new Group(grpInstCodes, SWT.FILL);
someGroup.setLayout(new GridLayout(2, false));
someGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label lblGenesysServer = new Label(someGroup, SWT.NONE);
lblGenesysServer.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
lblGenesysServer.setText(instCode);
Button removeInstCodeButton = new Button(someGroup, SWT.PUSH);
removeInstCodeButton.setData(instCode);
removeInstCodeButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, true));
removeInstCodeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
instCodes.remove(instCode);
renderInstCodesList(parent);
}
});
removeInstCodeButton.setData(instCode);
removeInstCodeButton.setText("X");
TableItem item = new TableItem(instCodesTable, SWT.NULL);
item.setText(instCode);
item.setText(0, instCode);
item.getParent().pack();
}
grpInstCodes.pack();
Button removeBtn = new Button(parent, SWT.NONE);
removeBtn.setEnabled(false);
removeBtn.setLayoutData(new GridData(SWT.END, SWT.TOP, true, true));
removeBtn.setText("Remove selected");
removeBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
for (int i = 0; i < instCodesTable.getItemCount(); i++) {
TableItem item = instCodesTable.getItem(i);
if (item.getChecked()) {
settings.getInstCodeSettings().getInstCodes().remove(item.getText());
instCodesTable.remove(i);
}
}
parent.redraw();
}
});
instCodesTable.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (event.detail == SWT.CHECK) {
for (TableItem item : instCodesTable.getItems()) {
if (item.getChecked()) {
removeBtn.setEnabled(true);
return;
}
}
removeBtn.setEnabled(false);
}
}
});
parent.pack();
shell.layout(true, true);
}
......
Markdown is supported
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