public code v1
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>flintstones.group</groupId>
|
||||
<artifactId>flintstones.bundles</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>flintstones.helper.ui</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Ui</name>
|
||||
</project>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.helper.ui</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ds.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1779484362614</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
@@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -0,0 +1,28 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Ui
|
||||
Bundle-SymbolicName: flintstones.helper.ui;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: org.eclipse.e4.core.contexts,
|
||||
org.eclipse.e4.core.di,
|
||||
org.eclipse.e4.ui.model.workbench,
|
||||
org.eclipse.wb.swt,
|
||||
org.eclipse.osgi,
|
||||
org.eclipse.jface;visibility:=reexport,
|
||||
org.eclipse.equinox.registry,
|
||||
javax.inject,
|
||||
flintstones.helper.html,
|
||||
org.eclipse.swt,
|
||||
org.eclipse.nebula.widgets.tablecombo,
|
||||
javax.annotation,
|
||||
flintstones.entity.extensionenum,
|
||||
flintstones.model.ui.service,
|
||||
org.eclipse.nebula.widgets.nebulaslider,
|
||||
flintstones.helper.data,
|
||||
org.apache.commons.lang,
|
||||
org.lorissecuro.ui
|
||||
Export-Package:
|
||||
flintstones.helper.ui.components,
|
||||
flintstones.helper.ui.components.listeners
|
||||
Automatic-Module-Name: flintstones.helper.ui
|
||||
@@ -0,0 +1,4 @@
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
source.. = src/
|
||||
@@ -0,0 +1,64 @@
|
||||
package flintstones.helper.ui.components;
|
||||
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.lorissecuro.ui.CustomButton;
|
||||
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
public class ActionButton {
|
||||
|
||||
CustomButton button;
|
||||
|
||||
public ActionButton(Composite bas, int style, int fontSize) {
|
||||
|
||||
button = new CustomButton(bas,style);
|
||||
addStyles(fontSize);
|
||||
}
|
||||
|
||||
private void addStyles(int fontSize) {
|
||||
|
||||
// NORMAL
|
||||
button.setBorderWidth(2);
|
||||
button.setBorder2Width(0);
|
||||
|
||||
// PRESSED
|
||||
button.setBackgroundPressed(UiService.COLOR_MAIN);
|
||||
button.setForegroundPressed(UiService.COLOR_MAIN_FG);
|
||||
button.setBorderWidthPressed(2);
|
||||
|
||||
// HOVER
|
||||
button.setBackgroundHover(UiService.COLOR_MAIN_HOVER);
|
||||
button.setBorderWidthHover(2);
|
||||
button.setBorder2WidthHover(0);
|
||||
|
||||
// SELECTED
|
||||
button.setBackgroundSelected(UiService.COLOR_MAIN);
|
||||
button.setForegroundSelected(UiService.COLOR_MAIN_FG);
|
||||
|
||||
button.setColorTransition(false);
|
||||
|
||||
UiService.setFont(button, UiService.FONT_BUTTON);
|
||||
UiService.setFontSize(button, fontSize);
|
||||
|
||||
}
|
||||
|
||||
public CustomButton getButton() {
|
||||
return button;
|
||||
}
|
||||
|
||||
public void setText(String label) {
|
||||
button.setText(label);
|
||||
}
|
||||
|
||||
public void setSelection(boolean b) {
|
||||
button.setSelection(b);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean b) {
|
||||
button.setEnabled(b);
|
||||
}
|
||||
|
||||
public void setHeight(int i) {
|
||||
button.heightHint = i;
|
||||
}
|
||||
}
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
package flintstones.helper.ui.components;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.VerifyEvent;
|
||||
import org.eclipse.swt.events.VerifyListener;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import flintstones.helper.DoubleHelper;
|
||||
import flintstones.helper.ui.components.listeners.WItemChanged;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
public class DecimalSpinner {
|
||||
|
||||
private double value = 0.0;
|
||||
private double stepBase = 1.0;
|
||||
private double stepPlus = 10.0;
|
||||
private double stepExtra = 100.0;
|
||||
private int decPlaces = 0;
|
||||
double min = -100000.0;
|
||||
double max = 100000.0;
|
||||
|
||||
Composite base;
|
||||
Text input;
|
||||
|
||||
WItemChanged changeListener;
|
||||
|
||||
public DecimalSpinner(Composite parent, double minv, double maxv, int decimalPlaces) {
|
||||
|
||||
stepBase = 1 / Math.pow(10, decimalPlaces);
|
||||
stepPlus = stepBase * 10;
|
||||
stepExtra = stepBase * 100;
|
||||
decPlaces = decimalPlaces;
|
||||
min = minv;
|
||||
max = maxv;
|
||||
|
||||
base = new Composite(parent, SWT.BORDER);
|
||||
GridLayout layout = UiService.setGridLayout(base, 3, false);
|
||||
UiService.setGridData(base, -1, 0, false, false);
|
||||
UiService.setMargin(base, 0);
|
||||
|
||||
layout.horizontalSpacing = 0;
|
||||
layout.marginBottom = 0;
|
||||
layout.marginHeight = 0;
|
||||
layout.marginLeft = 0;
|
||||
layout.marginRight = 0;
|
||||
layout.marginTop = 0;
|
||||
layout.marginWidth = 0;
|
||||
layout.verticalSpacing = 0;
|
||||
|
||||
base.setLayout(layout);
|
||||
|
||||
// LESS BUTTON
|
||||
Button lessButton = new Button(base, SWT.PUSH);
|
||||
lessButton.setImage(UiService.getImage("action_reduce.png").createImage());
|
||||
lessButton.addMouseListener(new MouseAdapter() {
|
||||
public void mouseDown(MouseEvent e) {
|
||||
double usedStep = getStep(e.button);
|
||||
double newValue = value - usedStep;
|
||||
setValue(newValue);
|
||||
}
|
||||
});
|
||||
lessButton.setToolTipText("LC: -" + stepBase + " MC: -" + stepPlus + " RC: -" + stepExtra);
|
||||
|
||||
// INPUT
|
||||
input = new Text(base, SWT.SINGLE | SWT.CENTER);
|
||||
input.setText(DoubleHelper.Draw(value, decimalPlaces + 5));
|
||||
input.addVerifyListener(new VerifyListener() {
|
||||
@Override
|
||||
public void verifyText(VerifyEvent e) {
|
||||
|
||||
final String oldS = input.getText();
|
||||
String newS = oldS.substring(0, e.start) + e.text + oldS.substring(e.end);
|
||||
|
||||
if (newS.equals("")) {
|
||||
e.doit = true;
|
||||
setValue(0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (newS.contains("d") || newS.contains("f")) {
|
||||
e.doit = false;
|
||||
return;
|
||||
}
|
||||
|
||||
newS = newS.replace(",", ".");
|
||||
if (newS.endsWith("."))
|
||||
newS += "0";
|
||||
|
||||
double finalValue = 0.0;
|
||||
try {
|
||||
finalValue = Double.parseDouble(newS);
|
||||
} catch (NumberFormatException ex) {
|
||||
e.doit = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (finalValue < min || finalValue > max) {
|
||||
e.doit = false;
|
||||
return;
|
||||
}
|
||||
|
||||
updateValue(finalValue);
|
||||
|
||||
// System.out.println("MOD: " + value);
|
||||
// System.out.println(min + " -- " + max);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
UiService.setGridData(input, 0, 0, false, true);
|
||||
|
||||
// MORE BUTTON
|
||||
Button moreButton = new Button(base, SWT.PUSH);
|
||||
moreButton.setImage(UiService.getImage("action_add.png").createImage());
|
||||
moreButton.addMouseListener(new MouseAdapter() {
|
||||
public void mouseDown(MouseEvent e) {
|
||||
double usedStep = getStep(e.button);
|
||||
double newValue = value + usedStep;
|
||||
setValue(newValue);
|
||||
}
|
||||
});
|
||||
moreButton.setToolTipText("LC: +" + stepBase + " MC: +" + stepPlus + " RC: +" + stepExtra);
|
||||
|
||||
}
|
||||
|
||||
private void updateValue(double updatedValue) {
|
||||
value = updatedValue;
|
||||
if (changeListener != null)
|
||||
changeListener.onWidgetChange();
|
||||
}
|
||||
|
||||
public void setValue(double val) {
|
||||
|
||||
if (val < max && val > min) {
|
||||
UiService.setBackgroundColor(base, UiService.COLOR_BG_NORMAL);
|
||||
UiService.setBackgroundColor(input, UiService.COLOR_BG_NORMAL);
|
||||
String cleanValue = DoubleHelper.Draw(val, decPlaces, true);
|
||||
input.setText(cleanValue);
|
||||
|
||||
updateValue(val);
|
||||
|
||||
correctSelection();
|
||||
// System.out.println("Clean value " + value);
|
||||
|
||||
} else {
|
||||
UiService.setBackgroundColor(base, UiService.COLOR_BG_WRONG);
|
||||
UiService.setBackgroundColor(input, UiService.COLOR_BG_NORMAL);
|
||||
}
|
||||
|
||||
// System.out.println("Underlying value " + value);
|
||||
// System.out.println(min + " -- " + max);
|
||||
}
|
||||
|
||||
private void correctSelection() {
|
||||
if (input.getText().equals("0"))
|
||||
input.setSelection(1);
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
double curr = DoubleHelper.ParseDouble(input.getText());
|
||||
if (curr != value)
|
||||
updateValue(curr);
|
||||
return value;
|
||||
}
|
||||
|
||||
private double getStep(int mouseButton) {
|
||||
double usedStep = stepBase;
|
||||
switch (mouseButton) {
|
||||
case 1:
|
||||
usedStep = stepBase;
|
||||
break;
|
||||
case 2:
|
||||
usedStep = stepPlus;
|
||||
break;
|
||||
case 3:
|
||||
usedStep = stepExtra;
|
||||
break;
|
||||
}
|
||||
return usedStep;
|
||||
}
|
||||
|
||||
public void setChangeListener(WItemChanged lis) {
|
||||
changeListener = lis;
|
||||
}
|
||||
}
|
||||
+411
@@ -0,0 +1,411 @@
|
||||
package flintstones.helper.ui.components;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.jface.dialogs.IInputValidator;
|
||||
import org.eclipse.jface.dialogs.InputDialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Cursor;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Scale;
|
||||
|
||||
import flintstones.helper.DoubleHelper;
|
||||
import flintstones.helper.html.table.HtmlTextTable;
|
||||
import flintstones.helper.ui.components.listeners.WEvent;
|
||||
import flintstones.helper.ui.components.listeners.WItemBeforeOperation;
|
||||
import flintstones.helper.ui.components.listeners.WItemChanged;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
/**
|
||||
* The Class WCollector.
|
||||
*/
|
||||
public class SliderCollector {
|
||||
|
||||
Scale input;
|
||||
Label inputValue;
|
||||
|
||||
/** The add button. */
|
||||
Button addButton;
|
||||
|
||||
/** The delete button. */
|
||||
Button deleteButton;
|
||||
|
||||
/** The table. */
|
||||
HtmlTextTable table;
|
||||
|
||||
/** The table headers. */
|
||||
String[] tableHeaders;
|
||||
|
||||
/** The values. */
|
||||
ArrayList<Double> values = new ArrayList<>();
|
||||
|
||||
/** The change listener. */
|
||||
WItemChanged changeListener;
|
||||
|
||||
/** The operation listener. */
|
||||
WItemBeforeOperation checkListener;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new w collector.
|
||||
*
|
||||
* @param parent the parent
|
||||
*/
|
||||
public SliderCollector(Composite parent) {
|
||||
preInit(parent, 0, 100, 0);
|
||||
}
|
||||
|
||||
public SliderCollector(Composite parent, double min, double max) {
|
||||
preInit(parent, min, max, 0);
|
||||
}
|
||||
|
||||
public SliderCollector(Composite parent, double min, double max, int decimalPlaces) {
|
||||
preInit(parent, min, max, decimalPlaces);
|
||||
}
|
||||
|
||||
int min = 0;
|
||||
int max;
|
||||
double desp;
|
||||
int mult;
|
||||
int decPlaces;
|
||||
|
||||
private void preInit(Composite parent, double minValue, double maxValue, int decimalPlaces) {
|
||||
cacheTranslation(minValue, maxValue, decimalPlaces);
|
||||
init(parent);
|
||||
}
|
||||
|
||||
private void cacheTranslation(double minValue, double maxValue, int decimalPlaces) {
|
||||
if (minValue == maxValue)
|
||||
throw new RuntimeException("Differents please");
|
||||
|
||||
if (minValue > maxValue)
|
||||
throw new RuntimeException("Ordered please");
|
||||
|
||||
double Xmax = Math.abs(minValue - maxValue);
|
||||
desp = -minValue;
|
||||
|
||||
mult = (int) Math.pow(10, decimalPlaces);
|
||||
|
||||
max = (int) Xmax * mult;
|
||||
decPlaces = decimalPlaces;
|
||||
}
|
||||
|
||||
public void reSet(double minValue, double maxValue, int decimalPlaces) {
|
||||
cacheTranslation(minValue, maxValue, decimalPlaces);
|
||||
|
||||
input.setMinimum(min);
|
||||
input.setMaximum(max);
|
||||
inputValue.setText(getValue() + " ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the values.
|
||||
*
|
||||
* @param values the new values
|
||||
*/
|
||||
public void setValues(Double[] values) {
|
||||
ArrayList<Double> arrayList = new ArrayList<Double>(Arrays.asList(values));
|
||||
this.values = arrayList;
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the headers.
|
||||
*
|
||||
* @param headers the new headers
|
||||
*/
|
||||
public void setHeaders(String headers[]) {
|
||||
tableHeaders = headers;
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits the.
|
||||
*/
|
||||
private void init(Composite parent) {
|
||||
|
||||
Composite base = new Composite(parent, SWT.BORDER);
|
||||
UiService.setGridLayout(base, 1);
|
||||
UiService.setGridData(base, 9, 9, true, true);
|
||||
|
||||
Composite row1 = new Composite(base, 0);
|
||||
UiService.setGridLayout(row1, 4);
|
||||
UiService.setGridData(row1, 9, 9, true, false);
|
||||
UiService.setBackgroundColor(base, UiService.getColor(255, 255, 255));
|
||||
|
||||
input = new Scale(row1, 0);
|
||||
input.setMinimum(min);
|
||||
input.setMaximum(max);
|
||||
UiService.setGridData(input, 9, 0, true, false);
|
||||
|
||||
inputValue = new Label(row1, 0);
|
||||
inputValue.setText("XX.XXXXXXXX");
|
||||
// input.setToolTipText("Pulsa [INTRO] para añadir un elemento");
|
||||
// input.addListener(SWT.Traverse, onEnterListener());
|
||||
|
||||
input.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
inputValue.setText(getValue() + "");
|
||||
}
|
||||
});
|
||||
|
||||
inputValue.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseUp(MouseEvent event) {
|
||||
super.mouseUp(event);
|
||||
|
||||
if (event.getSource() instanceof Label) {
|
||||
Label label = (Label) event.getSource();
|
||||
String text = label.getText().trim();
|
||||
|
||||
InputDialog dialog = new InputDialog(Display.getDefault().getActiveShell(), "Editando valor",
|
||||
"Introduce un valor", text, new IInputValidator() {
|
||||
|
||||
@Override
|
||||
public String isValid(String newText) {
|
||||
Double val = DoubleHelper.ParseDouble(newText);
|
||||
if (val > min && val < max)
|
||||
return null;
|
||||
return "Valor no valido";
|
||||
}
|
||||
});
|
||||
dialog.open();
|
||||
String newVal = dialog.getValue();
|
||||
if(newVal != null) {
|
||||
|
||||
// ADD to table
|
||||
Double val = DoubleHelper.ParseDouble(newVal);
|
||||
addData(val);
|
||||
|
||||
inputValue.setText(newVal + " ");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
inputValue.addListener(SWT.MouseMove, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
final Cursor cursor = new Cursor(Display.getDefault(), SWT.CURSOR_HAND);
|
||||
inputValue.setCursor(cursor);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
addButton = new Button(row1, SWT.PUSH);
|
||||
// addButton.setText(" + ");
|
||||
addButton.setImage(UiService.getIcon("action_add").createImage());
|
||||
addButton.addListener(SWT.Selection, onAddClickListener());
|
||||
|
||||
UiService.setGridData(addButton, 1, 0, false, false);
|
||||
|
||||
deleteButton = new Button(row1, SWT.PUSH);
|
||||
// deleteButton.setText(" X ");
|
||||
deleteButton.setImage(UiService.getIcon("action_delete").createImage());
|
||||
deleteButton.addListener(SWT.Selection, onDeleteClickListener());
|
||||
|
||||
UiService.setGridData(addButton, 1, 0, false, false);
|
||||
// UiService.setBackgroundColor(deleteButton, 200, 0, 0);
|
||||
|
||||
Composite row2 = new Composite(base, 0);
|
||||
UiService.setGridLayout(row2, 1);
|
||||
UiService.setGridData(row2, 9, 9, true, true);
|
||||
|
||||
table = new HtmlTextTable(row2, new String[] {}, true);
|
||||
table.render();
|
||||
|
||||
//
|
||||
inputValue.setText(getValue() + " ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be executed.
|
||||
*
|
||||
* @param operationType the operation type
|
||||
* @param before the before
|
||||
* @param after the after
|
||||
* @return true, if successful
|
||||
*/
|
||||
private boolean canBeExecuted(WEvent operationType, String before, String after) {
|
||||
boolean ok = true;
|
||||
|
||||
if (checkListener != null && !checkListener.shouldBeExecuted(operationType, before, after))
|
||||
ok = false;
|
||||
|
||||
if (ok) {
|
||||
input.getParent().setBackground(UiService.COLOR_BG_NORMAL);
|
||||
} else {
|
||||
input.getParent().setBackground(UiService.COLOR_BG_WRONG);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the data.
|
||||
*/
|
||||
|
||||
private void addData(double data) {
|
||||
|
||||
String dataS = data + "";// .getText();
|
||||
|
||||
if (!canBeExecuted(WEvent.ADD, dataS, ""))
|
||||
return;
|
||||
|
||||
// if(operationListener != null)
|
||||
// dataS = operationListener.getModifiedValue(WEvent.ADD, dataS, "");
|
||||
|
||||
values.add(data);
|
||||
refreshTable();
|
||||
|
||||
if (changeListener != null)
|
||||
changeListener.onWidgetChange();
|
||||
}
|
||||
|
||||
private void addData() {
|
||||
|
||||
double data = getValue();
|
||||
addData(data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear data.
|
||||
*/
|
||||
private void clearData() {
|
||||
|
||||
if (checkListener != null && !checkListener.shouldBeExecuted(WEvent.CLEAR, "", ""))
|
||||
return;
|
||||
|
||||
input.getParent().setBackground(UiService.COLOR_BG_NORMAL);
|
||||
|
||||
values.clear();
|
||||
|
||||
if (changeListener != null)
|
||||
changeListener.onWidgetChange();
|
||||
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear.
|
||||
*/
|
||||
public void clear() {
|
||||
values.clear();
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh table.
|
||||
*/
|
||||
private void refreshTable() {
|
||||
|
||||
if (table == null)
|
||||
return;
|
||||
|
||||
int headerLength = tableHeaders != null ? tableHeaders.length : 0;
|
||||
|
||||
Composite row = table.getParent();
|
||||
Arrays.stream(row.getChildren()).forEach(k -> k.dispose());
|
||||
|
||||
String[] data = new String[values.size() > headerLength ? values.size() : headerLength];
|
||||
Arrays.fill(data, "");
|
||||
|
||||
Double[] filledData = getData();
|
||||
for (int i = 0; i < filledData.length; i++)
|
||||
data[i] = filledData[i] + "";
|
||||
|
||||
if (tableHeaders != null)
|
||||
table = new HtmlTextTable(row, data, tableHeaders, true);
|
||||
else
|
||||
table = new HtmlTextTable(row, data, true);
|
||||
|
||||
table.render();
|
||||
row.layout();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data.
|
||||
*
|
||||
* @return the data
|
||||
*/
|
||||
public Double[] getData() {
|
||||
return values.toArray(new Double[values.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* On delete click listener.
|
||||
*
|
||||
* @return the listener
|
||||
*/
|
||||
private Listener onDeleteClickListener() {
|
||||
return new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
if (e.type == SWT.Selection)
|
||||
clearData();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* On add click listener.
|
||||
*
|
||||
* @return the listener
|
||||
*/
|
||||
private Listener onAddClickListener() {
|
||||
return new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
if (e.type == SWT.Selection)
|
||||
addData();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the change listener.
|
||||
*
|
||||
* @param listener the new change listener
|
||||
*/
|
||||
public void setChangeListener(WItemChanged listener) {
|
||||
changeListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the operation listener.
|
||||
*
|
||||
* @param listener the new operation listener
|
||||
*/
|
||||
public void setBeforeOperationListener(WItemBeforeOperation listener) {
|
||||
checkListener = listener;
|
||||
}
|
||||
|
||||
// public void setOperationListener(WItemOperation listener) {
|
||||
// operationListener = listener;
|
||||
// }
|
||||
//
|
||||
// CORRECT VALUES ONLY HERE
|
||||
private double getValue() {
|
||||
double val = input.getSelection();
|
||||
val = val / mult;
|
||||
val = val - desp;
|
||||
val = DoubleHelper.Round(val, decPlaces);
|
||||
return val;
|
||||
}
|
||||
|
||||
public Composite getBase() {
|
||||
return input.getParent();
|
||||
}
|
||||
}
|
||||
+275
@@ -0,0 +1,275 @@
|
||||
package flintstones.helper.ui.components;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.nebula.widgets.tablecombo.TableCombo;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
import flintstones.entity.extensionenum.ExtensionEnum;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
/**
|
||||
* The Class TableComboStatus.
|
||||
*/
|
||||
public class TableComboStatus {
|
||||
|
||||
/**
|
||||
* The Enum Status.
|
||||
*/
|
||||
public static enum Status implements ExtensionEnum {
|
||||
|
||||
/** The Wrong. */
|
||||
Wrong,
|
||||
/** The Unknown. */
|
||||
Unknown,
|
||||
/** The Right. */
|
||||
Right
|
||||
}
|
||||
|
||||
/** The ui service. */
|
||||
|
||||
/** The combo. */
|
||||
public TableCombo combo;
|
||||
|
||||
/** The unknown image. */
|
||||
Image unknownImage;
|
||||
|
||||
/** The right image. */
|
||||
Image rightImage;
|
||||
|
||||
/** The wrong image. */
|
||||
Image wrongImage;
|
||||
|
||||
/** The parent. */
|
||||
Composite parent;
|
||||
|
||||
/** The style. */
|
||||
int style;
|
||||
|
||||
/** The combo selection adapter. */
|
||||
SelectionAdapter comboSelectionAdapter;
|
||||
|
||||
/**
|
||||
* Instantiates a new table combo status.
|
||||
*
|
||||
* @param parent the parent
|
||||
* @param style the style
|
||||
*/
|
||||
public TableComboStatus(Composite parent, int style) {
|
||||
|
||||
Composite intermediate = new Composite(parent, 0);
|
||||
intermediate.setLayout(new FillLayout());
|
||||
this.parent = intermediate;
|
||||
this.style = style;
|
||||
addNewCombo();
|
||||
|
||||
unknownImage = UiService.getIcon("status_unknown").createImage();
|
||||
wrongImage = UiService.getIcon("status_wrong").createImage();
|
||||
rightImage = UiService.getIcon("status_right").createImage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the selection listener.
|
||||
*
|
||||
* @param comboSelectionAdapter the combo selection adapter
|
||||
*/
|
||||
public void addSelectionListener(SelectionAdapter comboSelectionAdapter) {
|
||||
this.comboSelectionAdapter = comboSelectionAdapter;
|
||||
combo.addSelectionListener(comboSelectionAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the table item.
|
||||
*
|
||||
* @param text the text
|
||||
* @param image the image
|
||||
*/
|
||||
private void addTableItem(String text, Image image) {
|
||||
TableItem ti = new TableItem(combo.getTable(), 0);
|
||||
ti.setText(text);
|
||||
ti.setImage(image);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the items.
|
||||
*
|
||||
* @param array the new items
|
||||
*/
|
||||
public void setItems(String[] array) {
|
||||
addNewCombo();
|
||||
Stream.of(array).forEach(k -> addTableItem(k, unknownImage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position.
|
||||
*
|
||||
* @param text the text
|
||||
* @return the position
|
||||
*/
|
||||
public int getPosition(String text) {
|
||||
int pos = -1;
|
||||
for (int i = 0; i < combo.getTable().getItems().length; i++) {
|
||||
String itemText = combo.getTable().getItems()[i].getText();
|
||||
if (text.equals(itemText)) {
|
||||
pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the image for status.
|
||||
*
|
||||
* @param status the status
|
||||
* @return the image for status
|
||||
*/
|
||||
private Image getImageForStatus(Status status) {
|
||||
|
||||
if (status.equals(Status.Wrong))
|
||||
return wrongImage;
|
||||
if (status.equals(Status.Unknown))
|
||||
return unknownImage;
|
||||
if (status.equals(Status.Right))
|
||||
return rightImage;
|
||||
|
||||
return unknownImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status.
|
||||
*
|
||||
* @param pos the pos
|
||||
* @param status the status
|
||||
*/
|
||||
public void setStatus(int pos, Status status) {
|
||||
Image img = getImageForStatus(status);
|
||||
combo.getTable().getItems()[pos].setImage(img);
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status.
|
||||
*
|
||||
* @param item the item
|
||||
* @param status the status
|
||||
*/
|
||||
public void setStatus(String item, Status status) {
|
||||
int pos = getPosition(item);
|
||||
setStatus(pos, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status.
|
||||
*
|
||||
* @param item the item
|
||||
* @param status the status
|
||||
*/
|
||||
public boolean getStatus(String item) {
|
||||
int pos = getPosition(item);
|
||||
int status = getStatus(pos);
|
||||
|
||||
if(status == 1)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select.
|
||||
*
|
||||
* @param pos the pos
|
||||
*/
|
||||
public void select(int pos) {
|
||||
combo.select(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh table.
|
||||
*/
|
||||
private void refreshTable() {
|
||||
|
||||
int lastSelected = combo.getSelectionIndex();
|
||||
ArrayList<String> itemsText = new ArrayList<>();
|
||||
ArrayList<Image> itemsImage = new ArrayList<>();
|
||||
for (TableItem ti : combo.getTable().getItems()) {
|
||||
itemsText.add(ti.getText());
|
||||
itemsImage.add(ti.getImage());
|
||||
}
|
||||
|
||||
combo.getTable().removeAll();
|
||||
|
||||
for (int i = 0; i < itemsText.size(); i++) {
|
||||
addTableItem(itemsText.get(i), itemsImage.get(i));
|
||||
}
|
||||
|
||||
// Draw again the selected item
|
||||
combo.select(lastSelected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status.
|
||||
*
|
||||
* @return the status
|
||||
*/
|
||||
public boolean getStatus() {
|
||||
TableItem[] items = combo.getTable().getItems();
|
||||
for (int i = 0; i < items.length; i++)
|
||||
if (getStatus(i) != 1)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status.
|
||||
*
|
||||
* @param pos the pos
|
||||
* @return the status
|
||||
*/
|
||||
private int getStatus(int pos) {
|
||||
if (combo.getTable().getItems()[pos].getImage().equals(rightImage))
|
||||
return 1;
|
||||
else if (combo.getTable().getItems()[pos].getImage().equals(unknownImage))
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text.
|
||||
*
|
||||
* @return the text
|
||||
*/
|
||||
public String getText() {
|
||||
return combo.getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the new combo.
|
||||
*/
|
||||
private void addNewCombo() {
|
||||
|
||||
if (combo != null && !combo.isDisposed())
|
||||
combo.dispose();
|
||||
|
||||
combo = new TableCombo(parent, style);
|
||||
|
||||
if (comboSelectionAdapter != null)
|
||||
combo.addSelectionListener(comboSelectionAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent.
|
||||
*
|
||||
* @return the parent
|
||||
*/
|
||||
public Composite getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package flintstones.helper.ui.components;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
import flintstones.helper.ui.components.listeners.IToggle;
|
||||
|
||||
public class ToggleButton {
|
||||
|
||||
Button button;
|
||||
|
||||
boolean isState1 = true;
|
||||
|
||||
public ToggleButton(Composite base, int style, IToggle toggle) {
|
||||
button = new Button(base,style);
|
||||
|
||||
button.setText(getButtonSpaces(toggle));
|
||||
button.setText(toggle.getBaseText());
|
||||
button.setImage(toggle.getBaseImage());
|
||||
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
if(isState1) {
|
||||
button.setText(toggle.getAltText());
|
||||
button.setImage(toggle.getAltImage());
|
||||
toggle.onBaseTextClick();
|
||||
|
||||
} else {
|
||||
button.setText(toggle.getBaseText());
|
||||
button.setImage(toggle.getBaseImage());
|
||||
toggle.onAltTextClick();
|
||||
}
|
||||
toggle.always();
|
||||
isState1 = !isState1;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private String getButtonSpaces(IToggle toggle) {
|
||||
int spaces = toggle.getBaseText().length() > toggle.getAltText().length() ? toggle.getBaseText().length() : toggle.getAltText().length();
|
||||
return StringUtils.leftPad("", spaces*3);
|
||||
}
|
||||
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package flintstones.helper.ui.components;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
public class ValidatedField {
|
||||
|
||||
private Label titleLabel;
|
||||
private WLabel errorLabel;
|
||||
private Text input;
|
||||
|
||||
public ValidatedField(Composite row, String label) {
|
||||
this(row, label, "");
|
||||
}
|
||||
|
||||
public ValidatedField(Composite base, String label, String defaultText) {
|
||||
|
||||
UiService.setMargin(base, 0);
|
||||
// UiService.setBackgroundColor(base, 0, 0, 100);
|
||||
|
||||
addRow1(base, label);
|
||||
addRow2(base,defaultText);
|
||||
|
||||
}
|
||||
|
||||
private void addRow1(Composite base, String label) {
|
||||
|
||||
Composite row = new Composite(base, SWT.NONE);
|
||||
UiService.setGridData(row, 9, -1, true, false);
|
||||
UiService.setGridLayout(row, 2);
|
||||
// UiService.setBackgroundColor(row, 0, 100, 0);
|
||||
UiService.setMargin(row, 0);
|
||||
|
||||
titleLabel = addLabel(row, label);
|
||||
errorLabel = addErrorLabel(row);
|
||||
|
||||
}
|
||||
|
||||
private void addRow2(Composite base, String defaultText) {
|
||||
|
||||
Composite row = new Composite(base, SWT.NONE);
|
||||
UiService.setGridData(row, 9, -1, true, false);
|
||||
UiService.setGridLayout(row, 1);
|
||||
// UiService.setBackgroundColor(row, 100, 0, 0);
|
||||
UiService.setMargin(row, 0);
|
||||
|
||||
input = addInput(row);
|
||||
setText(defaultText);
|
||||
|
||||
}
|
||||
|
||||
private Label addLabel(Composite row, String text) {
|
||||
|
||||
Label label = new Label(row, SWT.NONE);
|
||||
label.setText(text);
|
||||
UiService.setGridData(label, -1, 0, false, false);
|
||||
UiService.setFont(label, UiService.FONT_SECTION_TITLE);
|
||||
|
||||
return label;
|
||||
|
||||
}
|
||||
|
||||
private WLabel addErrorLabel(Composite row) {
|
||||
|
||||
Composite subBase = new Composite(row, SWT.NONE);
|
||||
UiService.setGridLayout(subBase, 1);
|
||||
UiService.setGridDataAuto(subBase);
|
||||
|
||||
WLabel label = new WLabel(subBase, SWT.NONE);
|
||||
UiService.setGridData(label, -1, 0, false, false);
|
||||
UiService.setFont(label, UiService.FONT_TEXT_ERROR);
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
private Text addInput(Composite row) {
|
||||
Text input = new Text(row, SWT.BORDER);
|
||||
UiService.setGridData(input, 9, -1, true, false);
|
||||
return input;
|
||||
}
|
||||
|
||||
public Text getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return input.getText();
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
|
||||
if(text == null)
|
||||
text = "";
|
||||
|
||||
String clean = text.trim();
|
||||
|
||||
if(!getText().equals(clean))
|
||||
input.setText(clean);
|
||||
}
|
||||
|
||||
public void setTitle(String label) {
|
||||
titleLabel.setText(label);
|
||||
}
|
||||
|
||||
public void setError(String text) {
|
||||
|
||||
if(text == null || text.equals("")) {
|
||||
input.setBackground(UiService.COLOR_BG_NORMAL);
|
||||
errorLabel.setText("");
|
||||
return ;
|
||||
}
|
||||
|
||||
input.setBackground(UiService.COLOR_BG_WRONG);
|
||||
errorLabel.setText(text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
package flintstones.helper.ui.components;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.dnd.Clipboard;
|
||||
import org.eclipse.swt.dnd.TextTransfer;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import flintstones.helper.StringHelper;
|
||||
import flintstones.helper.data.Config;
|
||||
import flintstones.helper.html.table.HtmlTextTable;
|
||||
import flintstones.helper.ui.components.listeners.WEvent;
|
||||
import flintstones.helper.ui.components.listeners.WItemAfterOperation;
|
||||
import flintstones.helper.ui.components.listeners.WItemBeforeOperation;
|
||||
import flintstones.helper.ui.components.listeners.WItemChanged;
|
||||
import flintstones.helper.ui.components.listeners.WItemOperation;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* The Class WCollector.
|
||||
*/
|
||||
public class WCollector {
|
||||
|
||||
/** The input. */
|
||||
Text input;
|
||||
|
||||
/** The add button. */
|
||||
Button addButton;
|
||||
|
||||
/** The delete button. */
|
||||
Button deleteButton;
|
||||
|
||||
/** The table. */
|
||||
HtmlTextTable table;
|
||||
|
||||
/** The table headers. */
|
||||
String[] tableHeaders;
|
||||
|
||||
/** The values. */
|
||||
ArrayList<String> values = new ArrayList<>();
|
||||
|
||||
WItemChanged changeListener;
|
||||
WItemOperation operationListener;
|
||||
WItemBeforeOperation checkListener;
|
||||
WItemAfterOperation afterListener;
|
||||
|
||||
Config config = new Config().defaultEnabled("paste");
|
||||
|
||||
/**
|
||||
* Instantiates a new w collector.
|
||||
*
|
||||
* @param parent the parent
|
||||
*/
|
||||
public WCollector(Composite parent) {
|
||||
init(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the values.
|
||||
*
|
||||
* @param values the new values
|
||||
*/
|
||||
public void setValues( ArrayList<String> values ) {
|
||||
this.values = values;
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the headers.
|
||||
*
|
||||
* @param headers the new headers
|
||||
*/
|
||||
public void setHeaders(String headers[]) {
|
||||
tableHeaders = headers;
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits the.
|
||||
*/
|
||||
private void init(Composite parent) {
|
||||
|
||||
Composite base = new Composite(parent, SWT.NONE);
|
||||
UiService.setGridLayout(base, 1);
|
||||
UiService.setGridData(base, 9, 9, true, true);
|
||||
|
||||
Composite row1 = new Composite(base, 0);
|
||||
int cols = config.is("paste") ? 4 : 3;
|
||||
UiService.setGridLayout(row1, cols);
|
||||
UiService.setGridData(row1, 9, 9, true, false);
|
||||
|
||||
input = new Text(row1, SWT.BORDER);
|
||||
input.setToolTipText("Pulsa [INTRO] para añadir un elemento");
|
||||
input.addListener(SWT.Traverse, onEnterListener());
|
||||
|
||||
UiService.setGridData(input, 9, 0, true, false);
|
||||
|
||||
addButton = new Button(row1, SWT.PUSH);
|
||||
// addButton.setText(" + ");
|
||||
addButton.setImage( UiService.getIcon("action_add").createImage() );
|
||||
addButton.addListener(SWT.Selection, onAddClickListener());
|
||||
|
||||
UiService.setGridData(addButton, 1, 0, false, false);
|
||||
|
||||
deleteButton = new Button(row1, SWT.PUSH);
|
||||
// deleteButton.setText(" X ");
|
||||
deleteButton.setImage( UiService.getIcon("action_delete").createImage() );
|
||||
deleteButton.addListener(SWT.Selection, onDeleteClickListener());
|
||||
|
||||
UiService.setGridData(deleteButton, 1, 0, false, false);
|
||||
// UiService.setBackgroundColor(deleteButton, 200, 0, 0);
|
||||
|
||||
if(config.is("paste")) {
|
||||
Button pasteButton = new Button(row1,SWT.PUSH);
|
||||
pasteButton.setImage( UiService.getIcon("action_paste").createImage() );
|
||||
UiService.setGridData(pasteButton, 1, 0, false, false);
|
||||
pasteButton.addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
Clipboard clipboard = new Clipboard(Display.getCurrent());
|
||||
String plainText = (String) clipboard.getContents(TextTransfer.getInstance());
|
||||
|
||||
if(plainText == null) {
|
||||
input.setText("");
|
||||
} else {
|
||||
String[] items = StringHelper.SplitSplit(plainText);
|
||||
for(String text : items) {
|
||||
input.setText(text);
|
||||
addData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Composite row2 = new Composite(base, 0);
|
||||
UiService.setGridLayout(row2, 1);
|
||||
UiService.setGridData(row2, 9, 9, true, true);
|
||||
|
||||
table = new HtmlTextTable(row2, new String[] {}, true);
|
||||
table.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be executed.
|
||||
*
|
||||
* @param operationType the operation type
|
||||
* @param before the before
|
||||
* @param after the after
|
||||
* @return true, if successful
|
||||
*/
|
||||
private boolean canBeExecuted(WEvent operationType, String before, String after) {
|
||||
boolean ok = true;
|
||||
|
||||
if(checkListener != null && !checkListener.shouldBeExecuted(operationType, before, after))
|
||||
ok = false;
|
||||
|
||||
if(ok){
|
||||
input.setBackground(UiService.COLOR_BG_NORMAL);
|
||||
} else {
|
||||
input.setBackground(UiService.COLOR_BG_WRONG);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the data.
|
||||
*/
|
||||
private void addData() {
|
||||
|
||||
String data = input.getText();
|
||||
if(data.equals(""))
|
||||
return ;
|
||||
|
||||
if(!canBeExecuted(WEvent.ADD, data, ""))
|
||||
return ;
|
||||
|
||||
if(operationListener != null)
|
||||
data = operationListener.getModifiedValue(WEvent.ADD, data, "");
|
||||
|
||||
if (!data.equals("")) {
|
||||
values.add(data);
|
||||
input.setText("");
|
||||
refreshTable();
|
||||
|
||||
if( changeListener != null )
|
||||
changeListener.onWidgetChange();
|
||||
}
|
||||
|
||||
if(afterListener != null)
|
||||
afterListener.afterOperation(WEvent.ADD, data, getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear data.
|
||||
*/
|
||||
private void clearData() {
|
||||
|
||||
if(checkListener != null && !checkListener.shouldBeExecuted(WEvent.CLEAR, "", ""))
|
||||
return ;
|
||||
|
||||
values.clear();
|
||||
|
||||
if( changeListener != null )
|
||||
changeListener.onWidgetChange();
|
||||
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear.
|
||||
*/
|
||||
public void clear() {
|
||||
values.clear();
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh table.
|
||||
*/
|
||||
private void refreshTable() {
|
||||
|
||||
if(table == null)
|
||||
return ;
|
||||
|
||||
int headerLength = tableHeaders != null ? tableHeaders.length : 0;
|
||||
|
||||
Composite row = table.getParent();
|
||||
Arrays.stream(row.getChildren()).forEach(k -> k.dispose());
|
||||
|
||||
String[] data = new String[ values.size() > headerLength ? values.size() : headerLength ];
|
||||
Arrays.fill(data, "");
|
||||
|
||||
String[] filledData = getData();
|
||||
for(int i = 0; i < filledData.length ; i++ )
|
||||
data[i] = filledData[i];
|
||||
|
||||
|
||||
if(tableHeaders != null)
|
||||
table = new HtmlTextTable(row, data, tableHeaders, true);
|
||||
else
|
||||
table = new HtmlTextTable(row, data, true);
|
||||
|
||||
table.render();
|
||||
row.layout();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data.
|
||||
*
|
||||
* @return the data
|
||||
*/
|
||||
public String[] getData() {
|
||||
return values.toArray(new String[values.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* On delete click listener.
|
||||
*
|
||||
* @return the listener
|
||||
*/
|
||||
private Listener onDeleteClickListener() {
|
||||
return new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
if (e.type == SWT.Selection)
|
||||
clearData();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* On add click listener.
|
||||
*
|
||||
* @return the listener
|
||||
*/
|
||||
private Listener onAddClickListener() {
|
||||
return new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
if (e.type == SWT.Selection)
|
||||
addData();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* On enter listener.
|
||||
*
|
||||
* @return the listener
|
||||
*/
|
||||
private Listener onEnterListener() {
|
||||
return new Listener() {
|
||||
@Override
|
||||
public void handleEvent(Event event) {
|
||||
if (event.detail == SWT.TRAVERSE_RETURN) // Hit Enter
|
||||
addData();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the change listener.
|
||||
*
|
||||
* @param listener the new change listener
|
||||
*/
|
||||
public void setChangeListener(WItemChanged listener) {
|
||||
changeListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the operation listener.
|
||||
*
|
||||
* @param listener the new operation listener
|
||||
*/
|
||||
public void setBeforeOperationListener(WItemBeforeOperation listener) {
|
||||
checkListener = listener;
|
||||
}
|
||||
|
||||
public void setOperationListener(WItemOperation listener) {
|
||||
operationListener = listener;
|
||||
}
|
||||
|
||||
public void setAfterListener(WItemAfterOperation listener) {
|
||||
afterListener = listener;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean status) {
|
||||
table.setEnabled(status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package flintstones.helper.ui.components;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.CLabel;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class WLabel extends CLabel {
|
||||
|
||||
private Composite parent;
|
||||
|
||||
public WLabel(Composite parent) {
|
||||
this(parent, SWT.NONE);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public WLabel(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
this.parent = parent;
|
||||
this.setTopMargin(0);
|
||||
this.setBottomMargin(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String string) {
|
||||
super.setText(string);
|
||||
this.parent.layout();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
super.setText(""); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkSubclass() {
|
||||
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package flintstones.helper.ui.components.listeners;
|
||||
|
||||
import flintstones.helper.ui.components.TableComboStatus.Status;
|
||||
|
||||
public interface IStatusProvider {
|
||||
Status getStatusFor(String name);
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package flintstones.helper.ui.components.listeners;
|
||||
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
public interface IToggle {
|
||||
|
||||
String getBaseText();
|
||||
|
||||
String getAltText();
|
||||
|
||||
Image getBaseImage();
|
||||
|
||||
Image getAltImage();
|
||||
|
||||
void onAltTextClick();
|
||||
|
||||
void onBaseTextClick();
|
||||
|
||||
void always();
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package flintstones.helper.ui.components.listeners;
|
||||
|
||||
public enum WEvent {
|
||||
ADD, CLEAR
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package flintstones.helper.ui.components.listeners;
|
||||
|
||||
public interface WItemAfterOperation {
|
||||
|
||||
// Based on javascript functional interfaces
|
||||
void afterOperation(WEvent operationType, String element, String[] arr);
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package flintstones.helper.ui.components.listeners;
|
||||
|
||||
/**
|
||||
* The Interface WItemBeforeOperation.
|
||||
*/
|
||||
public interface WItemBeforeOperation {
|
||||
|
||||
/**
|
||||
* Should be executed.
|
||||
*
|
||||
* @param operationType the operation type
|
||||
* @param before the before
|
||||
* @param after the after
|
||||
* @return true, if successful
|
||||
*/
|
||||
boolean shouldBeExecuted(WEvent operationType, String before, String after);
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package flintstones.helper.ui.components.listeners;
|
||||
|
||||
/**
|
||||
* The Interface WItemChanged.
|
||||
*/
|
||||
public interface WItemChanged {
|
||||
|
||||
/**
|
||||
* On widget change.
|
||||
*/
|
||||
void onWidgetChange();
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package flintstones.helper.ui.components.listeners;
|
||||
|
||||
public interface WItemOperation {
|
||||
|
||||
String getModifiedValue(WEvent operationType, String before, String after);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user