Commit 577f1761 authored by Matija Obreza's avatar Matija Obreza

Merge branch '30-advanced-settings-gui' into 'master'

Advanced settings GUI

Closes #30

See merge request !24
parents 2fd3cd82 23fbea3f
...@@ -307,11 +307,8 @@ public class PushDialog extends Dialog { ...@@ -307,11 +307,8 @@ public class PushDialog extends Dialog {
for (int i = futures.size() - 1; i >= 0; i--) { for (int i = futures.size() - 1; i >= 0; i--) {
Future<?> future = futures.get(i); Future<?> future = futures.get(i);
if (future == null) { if (future == null || future.isDone() || future.isCancelled()) {
continue; futures.remove(i);
}
if (future.isDone() || future.isCancelled()) {
futures.remove(future);
} else { } else {
future.cancel(true); future.cancel(true);
} }
...@@ -526,11 +523,8 @@ public class PushDialog extends Dialog { ...@@ -526,11 +523,8 @@ public class PushDialog extends Dialog {
do { do {
for (int i = futures.size() - 1; i >= 0; i--) { for (int i = futures.size() - 1; i >= 0; i--) {
Future<?> future = futures.get(i); Future<?> future = futures.get(i);
if (future == null) { if (future == null || future.isDone()) {
continue; futures.remove(i);
}
if (future.isDone()) {
futures.remove(future);
} }
} }
......
...@@ -35,7 +35,6 @@ import org.eclipse.swt.layout.GridLayout; ...@@ -35,7 +35,6 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Dialog; import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Event;
...@@ -45,6 +44,9 @@ import org.eclipse.swt.widgets.Listener; ...@@ -45,6 +44,9 @@ import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem; 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.eclipse.swt.widgets.Text;
import org.genesys2.anno.model.InstCodeSettings; import org.genesys2.anno.model.InstCodeSettings;
import org.genesys2.anno.model.OAuthSettings; import org.genesys2.anno.model.OAuthSettings;
...@@ -93,7 +95,7 @@ public class SettingsDialog extends Dialog { ...@@ -93,7 +95,7 @@ public class SettingsDialog extends Dialog {
private Text txtClientSecret; private Text txtClientSecret;
private Text txtScope; private Text txtScope;
private Text txtInstCodesToIgnore; private Text txtInstCodesToIgnore;
private Composite grpInstCodes; private Table instCodesTable;
/** /**
* Create the dialog. * Create the dialog.
...@@ -206,24 +208,30 @@ public class SettingsDialog extends Dialog { ...@@ -206,24 +208,30 @@ public class SettingsDialog extends Dialog {
Composite composite = new Composite(tabContents, SWT.NONE); Composite composite = new Composite(tabContents, SWT.NONE);
composite.setLayout(new GridLayout(1, false)); 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); renderAdvancedControllSection(composite);
Group instCodesGroup = new Group(composite, SWT.BORDER); Group instCodesGroup = new Group(composite, SWT.NONE);
instCodesGroup.setLayout(new GridLayout()); instCodesGroup.setLayout(new GridLayout(2, false));
instCodesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); instCodesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
instCodesGroup.setText("Selected institute codes"); renderInstCodesList(instCodesGroup);
grpInstCodes = new Composite(instCodesGroup, SWT.FILL);
grpInstCodes.setLayout(new GridLayout(6, true));
grpInstCodes.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
renderInstCodesList(composite);
composite.pack(); composite.pack();
tabContents.setContent(composite); 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) { private void renderAdvancedControllSection(Composite composite) {
...@@ -231,10 +239,10 @@ public class SettingsDialog extends Dialog { ...@@ -231,10 +239,10 @@ public class SettingsDialog extends Dialog {
Group controlSection = new Group(composite, SWT.BORDER); Group controlSection = new Group(composite, SWT.BORDER);
controlSection.setLayout(new GridLayout(1, false)); 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"); 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)); radioButtonsComposite.setLayout(new GridLayout(2, false));
Button isWhitelistButton = new Button(radioButtonsComposite, SWT.RADIO); Button isWhitelistButton = new Button(radioButtonsComposite, SWT.RADIO);
...@@ -256,83 +264,119 @@ public class SettingsDialog extends Dialog { ...@@ -256,83 +264,119 @@ public class SettingsDialog extends Dialog {
}); });
isBlacklitButton.setSelection(instCodeSettings.isBlackList()); isBlacklitButton.setSelection(instCodeSettings.isBlackList());
isBlacklitButton.setText("Blacklist"); isBlacklitButton.setText("Blacklist");
}
Button saveBtn = new Button(composite, SWT.NONE); private void renderInstCodesList(Composite parent) {
saveBtn.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); InstCodeSettings instCodeSettings = settings.getInstCodeSettings();
saveBtn.addSelectionListener(new SelectionAdapter() {
@Override Composite addCodeGroup = new Composite(parent, SWT.NONE);
public void widgetSelected(SelectionEvent event) { addCodeGroup.setLayout(new GridLayout(3, false));
try { addCodeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
settings.save(workspacePath + "/local.properties");
} catch (IOException err) {
System.err.println("Failed to load props: " + err.getMessage());
}
}
});
saveBtn.setText("Save");
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.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
txtInstCodesToIgnore.setTextLimit(6); txtInstCodesToIgnore.setTextLimit(6);
txtInstCodesToIgnore.addListener(SWT.FocusOut, new Listener() { txtInstCodesToIgnore.addKeyListener(new KeyAdapter() {
@Override @Override
public void handleEvent(Event event) { public void keyReleased(KeyEvent e) {
if (!txtInstCodesToIgnore.getText().trim().isEmpty()) { final int ENTER_KEY_CODE = 13;
instCodeSettings.getInstCodes().add(txtInstCodesToIgnore.getText().trim()); 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(""); 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 @Override
public void keyReleased(KeyEvent e) { public void widgetSelected(SelectionEvent event) {
final int ENTER_KEY_CODE = 13; if (!txtInstCodesToIgnore.getText().trim().isEmpty()) {
if (e.keyCode == ENTER_KEY_CODE && !txtInstCodesToIgnore.getText().trim().isEmpty()) { if (instCodeSettings.getInstCodes().add(txtInstCodesToIgnore.getText().trim())) {
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(""); txtInstCodesToIgnore.setText("");
renderInstCodesList(composite);
} }
} }
}); });
}
private void renderInstCodesList(Composite parent) { Label separator = new Label(parent, SWT.HORIZONTAL | SWT.SEPARATOR);
InstCodeSettings instCodeSettings = settings.getInstCodeSettings(); separator.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
Set<String> instCodes = instCodeSettings.getInstCodes();
if (grpInstCodes != null) { instCodesTable = new Table(parent, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
for (Control control : grpInstCodes.getChildren()) { instCodesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
control.dispose(); 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) { for (String instCode : instCodes) {
Group someGroup = new Group(grpInstCodes, SWT.FILL);
someGroup.setLayout(new GridLayout(2, false)); TableItem item = new TableItem(instCodesTable, SWT.NULL);
someGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); item.setText(instCode);
item.setText(0, instCode);
Label lblGenesysServer = new Label(someGroup, SWT.NONE); item.getParent().pack();
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");
} }
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(); parent.pack();
shell.layout(true, true); 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