Skip to content

Commit

Permalink
q meta data: react on label clicks; v3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
msrocka committed Mar 12, 2020
1 parent 636ef1e commit 4de141b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: App
Bundle-SymbolicName: epd-editor;singleton:=true
Bundle-Version: 3.0.1
Bundle-Version: 3.1.0
Bundle-Activator: app.rcp.Activator
Eclipse-BundleShape: dir
Require-Bundle: org.eclipse.ui,
Expand Down
2 changes: 1 addition & 1 deletion app.product
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>

<product name="EPD Editor" uid="epd.editor" id="epd-editor.product" application="epd-editor.application" version="3.0.1" useFeatures="false" includeLaunchers="true">
<product name="EPD Editor" uid="epd.editor" id="epd-editor.product" application="epd-editor.application" version="3.1.0" useFeatures="false" includeLaunchers="true">

<aboutInfo>
<text>
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</property>
<property
name="aboutText"
value="EPD Editor 3.0&#x0A;Copyright (c) 2018 GreenDelta. All rights reserved.&#x0A;&#x0A;This product includes software developed in the EPD Editor&#x0A;project and other open source software.&#x0A;Visit https://github.com/GreenDelta/epd-editor">
value="EPD Editor 3.1&#x0A;Copyright (c) 2020 GreenDelta. All rights reserved.&#x0A;&#x0A;This product includes software developed in the EPD Editor&#x0A;project and other open source software.&#x0A;Visit https://github.com/GreenDelta/epd-editor">
</property>
</product>
</extension>
Expand Down
30 changes: 25 additions & 5 deletions src/app/editors/epd/qmeta/QMetaDataPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormPage;
Expand Down Expand Up @@ -36,7 +38,7 @@ public class QMetaDataPage extends FormPage {
private Composite body;

public QMetaDataPage(EpdEditor editor) {
super(editor, "QMetaDataPage", "Q metadata");
super(editor, "QMetaDataPage", "Q Metadata");
this.editor = editor;
if (editor.dataSet.qMetaData == null) {
editor.dataSet.qMetaData = new QMetaData();
Expand All @@ -47,7 +49,7 @@ public QMetaDataPage(EpdEditor editor) {
@Override
protected void createFormContent(IManagedForm mform) {
tk = mform.getToolkit();
ScrolledForm form = UI.formHeader(mform, "Q metadata");
ScrolledForm form = UI.formHeader(mform, "Q Metadata");
body = UI.formBody(form, mform.getToolkit());

// Note that we have two kinds of `QQuestion` objects here:
Expand Down Expand Up @@ -102,8 +104,17 @@ private void oneInList(QGroup group) {
Button button = tk.createButton(comp, "", SWT.RADIO);
button.setLayoutData(
new GridData(SWT.LEFT, SWT.TOP, false, false));
tk.createLabel(
Label label = tk.createLabel(
comp, Strings.wrap(config[i].text, 120));
Controls.onClick(label, _e -> {
if (button.getSelection())
return;
for (Button other : buttons) {
other.setSelection(false);
}
button.setSelection(true);
button.notifyListeners(SWT.Selection, new Event());
});
if (Objects.equals(selected.get(), config[i])) {
QQuestion selectedQ = selected.get();
if (selectedQ.answer == null) {
Expand Down Expand Up @@ -162,9 +173,10 @@ private void multiChecks(QGroup group) {
question.answer.yesNo = false;
}

// create the check button
Button button = tk.createButton(comp, "", SWT.CHECK);
button.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
tk.createLabel(comp, Strings.wrap(config[i].text, 120));
button.setLayoutData(new GridData(
SWT.LEFT, SWT.TOP, false, false));
button.setSelection(question.answer.yesNo != null
&& question.answer.yesNo);
Controls.onSelect(button, _e -> {
Expand All @@ -175,6 +187,14 @@ private void multiChecks(QGroup group) {
}
editor.setDirty();
});

// create the label; also react on clicks on the label
Label label = tk.createLabel(comp,
Strings.wrap(config[i].text, 120));
Controls.onClick(label, _e -> {
button.setSelection(!button.getSelection());
button.notifyListeners(SWT.Selection, new Event());
});
UI.filler(comp);

Text comment = commentText(comp, tk);
Expand Down
14 changes: 14 additions & 0 deletions src/app/util/Controls.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import java.util.function.Consumer;

import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Scale;
Expand Down Expand Up @@ -74,4 +77,15 @@ public void linkActivated(HyperlinkEvent e) {
}
});
}

public static void onClick(Label label, Consumer<MouseEvent> fn) {
if (label == null || fn == null)
return;
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
fn.accept(e);
}
});
}
}

0 comments on commit 4de141b

Please sign in to comment.