public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -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.wtable</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Wtable</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.helper.wtable</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.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>1779484362616</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,16 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Wtable
Bundle-SymbolicName: flintstones.helper.wtable
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.swt;visibility:=reexport,
de.kupzog.ktable;visibility:=reexport
Export-Package: flintstones.helper.wcellrenderer,
flintstones.helper.wtable,
flintstones.helper.wtable.cell,
flintstones.helper.wtable.event,
flintstones.helper.wtable.example,
flintstones.helper.wtable.interfaces,
flintstones.helper.wtable.wcelleditor
Automatic-Module-Name: flintstones.helper.wtable
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
@@ -0,0 +1,26 @@
package flintstones.helper.wcellrenderer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.renderers.DefaultCellRenderer;
import de.kupzog.ktable.renderers.FixedCellRenderer;
/**
* @author Sinbad2
*
*/
public class WCellRendererDisabled extends FixedCellRenderer {
/**
* Disable cell / light shadow cell
*/
public WCellRendererDisabled() {
super(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS);
this.setBackground(Display.getCurrent()
.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER);
}
}
@@ -0,0 +1,26 @@
package flintstones.helper.wcellrenderer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.renderers.DefaultCellRenderer;
import de.kupzog.ktable.renderers.FixedCellRenderer;
/**
* @author Sinbad2
*
*/
public class WCellRendererEmpty extends FixedCellRenderer {
/**
* Emprty cell / white cell
*/
public WCellRendererEmpty() {
super(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS);
this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER);
this.setBackground(Display.getCurrent()
.getSystemColor(SWT.COLOR_WHITE));
}
}
@@ -0,0 +1,26 @@
package flintstones.helper.wcellrenderer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.renderers.DefaultCellRenderer;
import de.kupzog.ktable.renderers.FixedCellRenderer;
/**
* @author Sinbad2
*
*/
public class WCellRendererFilled extends FixedCellRenderer {
/**
* Filled cell / white cell with black text
*/
public WCellRendererFilled() {
super(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS);
this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER);
this.setBackground(Display.getCurrent()
.getSystemColor(SWT.COLOR_WHITE));
}
}
@@ -0,0 +1,23 @@
package flintstones.helper.wcellrenderer;
import org.eclipse.swt.SWT;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.renderers.DefaultCellRenderer;
import de.kupzog.ktable.renderers.FixedCellRenderer;
/**
* @author Sinbad2
*
*/
public class WCellRendererHeader extends FixedCellRenderer {
/**
* Header cell / gray cell
*/
public WCellRendererHeader() {
super(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD);
this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER);
}
}
@@ -0,0 +1,26 @@
package flintstones.helper.wcellrenderer;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.renderers.DefaultCellRenderer;
import de.kupzog.ktable.renderers.FixedCellRenderer;
/**
* @author Sinbad2
*
*/
public class WCellRendererRight extends FixedCellRenderer {
/**
* Red cell/wrong cell
*/
public WCellRendererRight() {
super(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS);
this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER);
this.setBackground(new Color(Display.getCurrent(), new RGB(240, 248, 255)));
}
}
@@ -0,0 +1,26 @@
package flintstones.helper.wcellrenderer;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.renderers.DefaultCellRenderer;
import de.kupzog.ktable.renderers.FixedCellRenderer;
/**
* @author Sinbad2
*
*/
public class WCellRendererWrong extends FixedCellRenderer {
/**
* Red cell/wrong cell
*/
public WCellRendererWrong() {
super(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS);
this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER);
this.setBackground(new Color(Display.getCurrent(), new RGB(255, 160, 160)));
}
}
@@ -0,0 +1,31 @@
package flintstones.helper.wtable;
import org.eclipse.swt.widgets.Composite;
import de.kupzog.ktable.KTable;
import de.kupzog.ktable.KTableModel;
/**
* The Class WTable, wrapper around ktable.
*/
public class WTable extends KTable {
/**
* Instantiates a new w table.
*
* @param parent the parent
* @param style the style
*/
public WTable(Composite parent, int style) {
super(parent, style);
}
/* (non-Javadoc)
*
* @see de.kupzog.ktable.KTable#setModel(de.kupzog.ktable.KTableModel) */
@Override
public void setModel(KTableModel model) {
super.setModel(model);
}
}
@@ -0,0 +1,100 @@
package flintstones.helper.wtable;
import java.util.ArrayList;
import java.util.HashMap;
/**
* @author Sinbad2
* Table content matrix
*/
class WTableContent {
private final HashMap<Integer, HashMap<Integer, Object>> items;
private final Integer sizeX;
private final Integer sizeY;
/**
* Builder
*/
public WTableContent() {
this.sizeX = 0;
this.sizeY = 0;
this.items = new HashMap<>();
}
/**
* Builder with content
* @param itemsArr content matrix
*/
WTableContent(ArrayList<ArrayList<Object>> itemsArr) {
// Obtener las dimensiones de la matriz
int maxI = 0;
int maxJ = 0;
int i;
for (i = 0; i < itemsArr.size(); i++)
for (int j = 0; j < itemsArr.get(i)
.size(); j++)
if (j > maxJ)
maxJ = j;
maxI = i;
maxJ++;
this.sizeX = maxI;
this.sizeY = maxJ;
this.items = new HashMap<>();
for (i = 0; i < itemsArr.size(); i++) {
this.items.put(i, new HashMap<Integer, Object>());
for (int j = 0; j < itemsArr.get(i)
.size(); j++)
this.items.get(i)
.put(j, itemsArr.get(i)
.get(j));
}
}
/**
* @return The number of cols
*/
public Integer sizeX() {
return this.sizeX;
}
/**
* @return The number of rows of the longer col
*/
public Integer sizeY() {
return this.sizeY;
}
/**
* @param col col
* @param row row
* @return The item at the table col,row
*/
public Object get(int col, int row) {
HashMap<Integer, Object> arr = this.items.get(col);
if (arr == null)
return null;
return arr.get(row);
}
/**
* @param col col
* @param row row
* @param item Sets the item at the table col,row
*/
public void set(int col, int row, Object item) {
HashMap<Integer, Object> arrAnterior = this.items.get(col);
if (arrAnterior == null)
arrAnterior = new HashMap<>();
arrAnterior.put(row, item);
this.items.put(col, arrAnterior);
}
}
@@ -0,0 +1,91 @@
package flintstones.helper.wtable;
import java.util.ArrayList;
/**
* The Class WTableHeader.
*/
class WTableHeader {
/** The items. */
public ArrayList<WTableHeaderItem> items;
/**
* Instantiates a new w table header.
*/
public WTableHeader() {
this.items = new ArrayList<>();
}
/**
* Instantiates a new w table header.
*
* @param headers
* the headers
*/
public WTableHeader(ArrayList<WTableHeaderItem> headers) {
this.items = headers;
}
/**
* Length.
*
* @return the integer
*/
// Nmero de items
public Integer Length() {
return this.items.size();
}
/**
* Wide.
*
* @return the integer
*/
// Si algn item tiene subgrupos es 2, sino es 1.
public Integer Wide() {
for (int i = 0; i < this.items.size(); i++)
if (this.items.get(i)
.hasSubItems())
return 2;
return 1;
}
/**
* Adds the.
*
* @param item
* Aade una cabecera
*/
public void add(WTableHeaderItem item) {
this.items.add(item);
}
/**
* @param index The position of the item
* @return The item at the given position
*/
public WTableHeaderItem get(int index) {
if (index < this.items.size())
return this.items.get(index);
return null;
}
/**
* Gets the main header text of a given index.
*
* @param index
* Posicin
* @return the main
*/
public String getMainText(int index) {
if (index < this.items.size())
return this.items.get(index)
.getMain();
return ""; //$NON-NLS-1$
}
}
@@ -0,0 +1,63 @@
package flintstones.helper.wtable;
/**
* @author XXXX
* Header cell of the table
*/
class WTableHeaderCell {
String text = ""; //$NON-NLS-1$
Boolean joinUp = false;
Boolean joinLeft = false;
WTableHeaderCell(String text) {
this.text = text;
}
WTableHeaderCell(String text, Boolean up, Boolean left) {
this.text = text;
this.joinUp = up;
this.joinLeft = left;
}
@Override
public String toString() {
String str = this.text + " " + this.joinUp + " " + this.joinLeft; //$NON-NLS-1$ //$NON-NLS-2$
return str;
}
/**
* @return Return true if the cell should join the cell at the left.
*/
public Boolean getJoinLeft() {
return this.joinLeft;
}
/**
* @param joinLeft True if the cell should join the cell at left
*/
public void setJoinLeft(Boolean joinLeft) {
this.joinLeft = joinLeft;
}
/**
* @return Return true if the cell should join the upper cell.
*/
public Boolean getJoinUp() {
return this.joinUp;
}
/**
* @param joinUp True if cell should join the upper cell
*/
public void setJoinUp(Boolean joinUp) {
this.joinUp = joinUp;
}
/**
* @return The cell label
*/
public String getText() {
return this.text;
}
}
@@ -0,0 +1,72 @@
package flintstones.helper.wtable;
/**
* The Class WTableHeaderItem.
*/
class WTableHeaderItem {
/** The main item. */
private final String mainItem;
/** The sub items. */
public String[] subItems;
/**
* Inicializa sin grupos.
*
* @param text
* the text
*/
WTableHeaderItem(String text) {
this.mainItem = text;
this.subItems = null;
}
/**
* Inicializa con grupos.
*
* @param text
* the text
* @param subgroups
* the subgroups
*/
public WTableHeaderItem(String text, String[] subgroups) {
this.mainItem = text;
this.subItems = subgroups;
}
/**
* Adds subitems in bulk
* @param arr List of headers
*/
public void addSub(String[] arr) {
this.subItems = arr;
}
/**
* Devuelve el texto de la cabecera principal. Si no hay grupo es el elemento,
* si hay grupo es el nombre del grupo.
*
* @return the main
*/
public String getMain() {
return this.mainItem;
}
/**
* @param index Position of the item
* @return Return the subheader for the given position
*/
public String getSub(int index) {
return this.subItems[index];
}
/**
* Checks for subgroups.
*
* @return the boolean
*/
public Boolean hasSubItems() {
return this.subItems != null;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,11 @@
package flintstones.helper.wtable.cell;
@SuppressWarnings("javadoc")
public class WTableCell {
@Override
public String toString() {
return ""; //$NON-NLS-1$
}
}
@@ -0,0 +1,65 @@
package flintstones.helper.wtable.cell;
import de.kupzog.ktable.KTableCellRenderer;
import flintstones.helper.wcellrenderer.WCellRendererDisabled;
import flintstones.helper.wcellrenderer.WCellRendererFilled;
import flintstones.helper.wcellrenderer.WCellRendererWrong;
import flintstones.helper.wtable.interfaces.IWTableCellStyle;
/**
* The Class WTableCellDeactivable.
*/
public class WTableCellDeactivable extends WTableCell implements IWTableCellStyle {
/** The renderer enabled. */
public KTableCellRenderer rendererEnabled;
/** The renderer disabled. */
public KTableCellRenderer rendererDisabled;
/** The renderer obligatory. */
public KTableCellRenderer rendererObligatory;
/** The enabled. */
public boolean enabled = false;
/**
* Instantiates a new w table cell deactivable.
*
* @param isEnabled the is enabled
*/
public WTableCellDeactivable(boolean isEnabled) {
rendererEnabled = new WCellRendererFilled();
rendererDisabled = new WCellRendererDisabled();
rendererObligatory = new WCellRendererWrong();
if(isEnabled)
enable();
disable();
}
/* (non-Javadoc)
* @see flintstones.helper.wtable.interfaces.IWTableCellStyle#getCellRenderer()
*/
@Override
public KTableCellRenderer getCellRenderer() {
if(enabled)
return rendererEnabled;
return rendererDisabled;
}
/**
* Disable.
*/
public void disable() {
enabled = false;
}
/**
* Enable.
*/
public void enable() {
enabled = true;
}
}
@@ -0,0 +1,14 @@
package flintstones.helper.wtable.event;
/**
* @author Sinbad 2
*
*/
public interface WTableCellClickListener {
/** Listener that notifys on cell clicked
* @param col col
* @param row row
* @param text text
*/
void cellClicked(int col, int row, Object text);
}
@@ -0,0 +1,16 @@
package flintstones.helper.wtable.event;
/**
* @author Sinbad2
*
*/
public interface WTableCellModifiedListener {
/**
* Listener thats notifys on cell changes.
* @param col col
* @param row row
* @param oldValue The older value of the cell
* @param newValue The new value of the cell
*/
void cellModified(int col, int row, Object oldValue, Object newValue);
}
@@ -0,0 +1,124 @@
package flintstones.helper.wtable.example;
import java.util.ArrayList;
import de.kupzog.ktable.KTable;
import flintstones.helper.wtable.WTableModel;
/**
* @author Sinbad2
* Example table to work with in a given composite
*/
@SuppressWarnings("nls")
public class ExampleTableModel {
private static final String[] vHeader1 = new String[] { "11", "12" };
private static final String[] vHeader = new String[] { "1", "2", "3", "4", "5" };
/**
* Builder that create some elements in memory to populate the table
*/
public ExampleTableModel() {
}
private static final String[] hHeader = new String[] { "a", "b", "c", "d", "e", "f" };
private static final String[] hSubHeader1 = new String[] { "a1", "a2" };
private static final String[] hSubHeader2 = new String[] { "d1", "d2" };
ArrayList<ArrayList<ItemWTable>> contentItems = new ArrayList<>();
ArrayList<ArrayList<ItemWTable>> abbreviation = new ArrayList<>();
ArrayList<ArrayList<ItemWTable>> placeHolder = new ArrayList<>();
/**
* Basic table with single headers
* @param _table A kTable instance
* @param exampleText Some text to be added in every cell
* @return A WTableModel ready for usage
*/
public WTableModel getBasicTable(KTable _table, String exampleText) {
WTableModel w = new WTableModel(_table);
// Cabeceras
w.setHorizontalHeaders(ExampleTableModel.hHeader);
w.setVerticalHeaders(ExampleTableModel.vHeader);
// Contenido
this.addContentPlaceholderAbbreviation(exampleText);
w.addContent(this.contentItems);
w.addAbbreviation(this.abbreviation);
w.addPlaceholder(this.placeHolder);
return w;
}
/**
* Basic table with single headers
* @param _table A kTable instance
* @param exampleText Some text to be added in every cell
* @param extraVHeader Should the extra vertical header be draw?
* @param extraHHeader Should the extra horizontal header be draw?
* @return A WTableModel ready for usage
*/
public WTableModel getFullTable(KTable _table, String exampleText, Boolean extraVHeader, Boolean extraHHeader) {
WTableModel w = new WTableModel(_table);
// Cabeceras
w.setHorizontalHeaders(ExampleTableModel.hHeader);
if (extraHHeader) {
w.addHorizontalSubHeaders(ExampleTableModel.hSubHeader1, 0);
w.addHorizontalSubHeaders(ExampleTableModel.hSubHeader2, 3);
}
w.setVerticalHeaders(ExampleTableModel.vHeader);
if (extraVHeader)
w.addVerticalSubHeaders(ExampleTableModel.vHeader1, 0);
// Contenido
this.addContentPlaceholderAbbreviation(exampleText);
// Vacia celdas para ver si es robusta
this.contentItems.set(3, new ArrayList<ItemWTable>());
this.placeHolder.set(2, new ArrayList<ItemWTable>());
w.addContent(this.contentItems);
w.addAbbreviation(this.abbreviation);
w.addPlaceholder(this.placeHolder);
return w;
}
private void addContent(String exampleText) {
for (int i = 0; i < 8; i++) {
this.contentItems.add(new ArrayList<ItemWTable>());
for (int j = 0; j < 8; j++)
this.contentItems.get(i)
.add(new ItemWTable("Cont " + exampleText, (1 + i) * (j + 1)));
}
}
private void addPlaceholder(String exampleText) {
for (int i = 0; i < 8; i++) {
this.placeHolder.add(new ArrayList<ItemWTable>());
for (int j = 0; j < 8; j++)
this.placeHolder.get(i)
.add(new ItemWTable("Dominio " + exampleText, (1 + i) * (j + 1)));
}
}
private void addAbbreviation() {
for (int i = 0; i < 8; i++) {
this.abbreviation.add(new ArrayList<ItemWTable>());
for (int j = 0; j < 8; j++)
this.abbreviation.get(i)
.add(new ItemWTable("D", i + j));
}
}
private void addContentPlaceholderAbbreviation(String exampleText) {
this.addPlaceholder(exampleText);
this.addContent(exampleText);
this.addAbbreviation();
}
}
@@ -0,0 +1,35 @@
package flintstones.helper.wtable.example;
/**
* The Class ItemWTable.
*/
class ItemWTable {
private final /** The text. */
String _text;
private final /** The id. */
int _id;
/**
* Instantiates a new item W table.
*
* @param text
* the text
* @param id
* the id
*/
public ItemWTable(String text, int id) {
this._text = text;
this._id = id;
}
/* (non-Javadoc)
*
* @see java.lang.Object#toString() */
@Override
public String toString() {
return this._text + " " + this._id; //$NON-NLS-1$
}
}
@@ -0,0 +1,19 @@
package flintstones.helper.wtable.exception;
/**
* @author Sinbad2
*
*/
public class InvalidTypeException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 2342304032009813014L;
/**
* @param text Error text
*/
public InvalidTypeException(String text) {
super("Clase incorrecta, debe ser ArrayList<ArrayList<Object>> y se ha recibido " + text); //$NON-NLS-1$
}
}
@@ -0,0 +1,12 @@
package flintstones.helper.wtable.interfaces;
/**
* This class should be used on items added to WTable. It will define the short text of them.
* Future revisions may limit the length of this text. (5 char max should be fine)
*/
public interface IWTableAbbreviation {
/**
* @return The cell label abbreviation
*/
String getAbbreviation();
}
@@ -0,0 +1,27 @@
package flintstones.helper.wtable.interfaces;
/**
* This class allows the user to define the content of a table cell.
* Usually should return a String to show it as table text.
* It allows having an object into the table and controlling the text of the table based on the object state.
* Can also be used to control if the current cell should change it content to the one returned from the KTableCellEditor
* and if this change should be notified to other listeners.
*/
public interface IWTableCellContent {
/**
* @param cellContent The cell content, need to be cast
* @return The cell content
*/
Object getContent(Object cellContent);
/**
* @return true to fire modifiedEvent
*/
boolean shouldFireModifiedEvent();
/**
* @return true to let the table change it content by itself
*/
boolean shouldSetContent();
}
@@ -0,0 +1,17 @@
package flintstones.helper.wtable.interfaces;
import de.kupzog.ktable.KTableCellEditor;
/**
* Allows to define the cell editor used to edit the current cell.
* Used along IWTableCellContent allows to show some text and rendering an editor when clicking the text.
*/
public interface IWTableCellEditor {
/**
* Gets the cell editor.
*
* @return the cell editor
*/
KTableCellEditor getCellEditor();
}
@@ -0,0 +1,16 @@
package flintstones.helper.wtable.interfaces;
/**
* The Interface IWTableCellEventClicked allows a cell to execute code when clicked.
*/
public interface IWTableCellEventClicked {
/**
* Cell clicked.
*
* @param col the col
* @param row the row
* @param content the content
*/
void cellClicked(int col, int row, Object content);
}
@@ -0,0 +1,17 @@
package flintstones.helper.wtable.interfaces;
/**
* The Interface IWTableCellEventModified allows a cell to execute code when modified.
*/
public interface IWTableCellEventModified {
/**
* Cell modified.
*
* @param col the col
* @param row the row
* @param oldContent the old content
* @param newContent the new content
*/
void cellModified(int col, int row, Object oldContent, Object newContent);
}
@@ -0,0 +1,18 @@
package flintstones.helper.wtable.interfaces;
import de.kupzog.ktable.KTableCellRenderer;
/**
* The Interface IWTableCellStyle lets you define the renderer of a cell.
* Usually used to change cell and font color, background.
*
*/
public interface IWTableCellStyle {
/**
* Gets the cell renderer.
*
* @return The cell label abbreviation
*/
KTableCellRenderer getCellRenderer();
}
@@ -0,0 +1,11 @@
package flintstones.helper.wtable.interfaces;
/**
* Allows to define a placeholder text in case that the items dont provide any.
*/
public interface IWTablePlaceholder {
/**
* @return The cell placeholder
*/
String getPlaceholder();
}
@@ -0,0 +1,17 @@
package flintstones.helper.wtable.interfaces;
import flintstones.helper.wtable.cell.WTableCell;
/**
* The Interface IWTableRow let you insert data in the wtable in rows that share some data.
*/
public interface IWTableRow {
/**
* Should return every cell of the row.
*
* @return the cells
*/
WTableCell[] getCells();
}
@@ -0,0 +1,145 @@
package flintstones.helper.wtable.ktable;
/*
FIX de la clase con el mismo nombre sin "FIX".
Arregla el combo
*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import de.kupzog.ktable.KTable;
import de.kupzog.ktable.KTableCellEditor;
/**
* A combobox cell editor.
*
* @author Friederich Kupzog
*/
public class KTableCellEditorComboFix extends KTableCellEditor {
protected CCombo m_Combo;
private String m_Items[];
private Cursor m_ArrowCursor;
private KeyAdapter keyListener = new KeyAdapter() {
public void keyPressed(KeyEvent e) {
try {
onKeyPressed(e);
} catch (Exception ex) {
// Do nothing
}
e.doit = false;
}
};
private TraverseListener travListener = new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
onTraverse(e);
}
};
// ATTENTION: Before the col/row parameters were mis-labeled.
public void open(KTable table, int col, int row, Rectangle rect) {
m_ArrowCursor = new Cursor(Display.getDefault(), SWT.CURSOR_ARROW);
super.open(table, col, row, rect);
String content =m_Model.getContentAt(m_Col, m_Row).toString();
m_Combo.setText(content);
m_Combo.setSelection(new Point(0, content.length()));
}
public void close(boolean save) {
if (save)
m_Model.setContentAt(m_Col, m_Row, m_Combo.getText());
m_Combo.removeKeyListener(keyListener);
m_Combo.removeTraverseListener(travListener);
super.close(save);
m_Combo = null;
m_ArrowCursor.dispose();
}
protected Control createControl() {
m_Combo = new CCombo(m_Table, SWT.READ_ONLY );
m_Combo.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
if (m_Items != null)
m_Combo.setItems(m_Items);
m_Combo.addKeyListener(keyListener);
m_Combo.addTraverseListener(travListener);
m_Combo.setCursor(m_ArrowCursor);
return m_Combo;
}
/**
* Overwrite the onTraverse method to ignore arrowup and arrowdown
* events so that they get interpreted by the editor control.<p>
* Comment that out if you want the up and down keys move the editor.<br>
* Hint by David Sciamma.
*/
protected void onTraverse(TraverseEvent e)
{
// set selection to the appropriate next element:
switch (e.keyCode)
{
case SWT.ARROW_UP: // Go to previous item
case SWT.ARROW_DOWN: // Go to next item
{
// Just don't treat the event
break;
}
default: {
super.onTraverse(e);
break;
}
}
}
public void setBounds(Rectangle rect)
{
super.setBounds(new Rectangle(rect.x, rect.y+1,
rect.width, rect.height-2));
}
public void setItems(String items[]) {
m_Items = items;
}
/* (non-Javadoc)
* @see de.kupzog.ktable.KTableCellEditor#setContent(java.lang.String)
*/
public void setContent(Object content) {
if (content instanceof Integer) {
m_Combo.select(((Integer)content).intValue());
} else if (content instanceof String) {
setSelectionToClosestMatch((String)content);
} else {
setSelectionToClosestMatch(content.toString());
}
}
private void setSelectionToClosestMatch(String content) {
content = content.toLowerCase();
String[] citems = m_Combo.getItems();
String[] items = new String[citems.length];
for (int i=0; i<citems.length; i++)
items[i] = citems[i].toLowerCase();
for (int length=content.length(); length>=0; length--) {
String part = content.substring(0, length);
for (int i=0; i<items.length; i++)
if (items[i].startsWith(part)) {
m_Combo.select(i);
return;
}
}
}
}
@@ -0,0 +1,31 @@
package flintstones.helper.wtable.wcelleditor;
import org.eclipse.swt.custom.CCombo;
import de.kupzog.ktable.KTableCellEditor;
import flintstones.helper.wtable.ktable.KTableCellEditorComboFix;
/**
* @author Sinbad2
* Combo cell editor
*/
public class WCellEditorCombo extends KTableCellEditorComboFix {
/**
* @param values Posible values of the combobox
*/
public WCellEditorCombo(String[] values) {
((KTableCellEditorComboFix) this).setItems(values);
}
@Override
public int getActivationSignals() {
return KTableCellEditor.SINGLECLICK;
}
public CCombo getCombo() {
CCombo combo = (CCombo) this.getControl();
return combo;
}
}
@@ -0,0 +1,94 @@
package flintstones.helper.wtable.wcelleditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Spinner;
import de.kupzog.ktable.KTable;
import de.kupzog.ktable.KTableCellEditor;
/**
* @author Sinbad 2
* Floating number spinner cell editor
*/
public class WCellEditorFloatingSpinner extends KTableCellEditor {
@Override
public int getActivationSignals() {
return KTableCellEditor.SINGLECLICK;
}
Spinner component;
private int digits = 3;
/**
* @param digits The number of floating digits
*/
public void setDigits(int digits) {
this.digits = digits;
}
// Cuando estas editanto el spinner, al pulsar en teclado
private final KeyAdapter keyListener = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
try {
WCellEditorFloatingSpinner.this.onKeyPressed(e);
} catch (Exception ex) {
// Do nothing
}
}
};
// Cuando estas editanto el spinner, al moverte a otra celda con teclado
private final TraverseListener travListener = e -> WCellEditorFloatingSpinner.this.onTraverse(e);
@Override
protected Control createControl() {
this.component = new Spinner(this.m_Table, SWT.NONE);
this.component.setDigits(this.digits);
// component.setMaximum(9);
// component.setMinimum(6);
this.component.addKeyListener(this.keyListener);
this.component.addTraverseListener(this.travListener);
return this.component;
}
@Override
public void setContent(Object content) {
this.component.setData(content);
}
@Override
public void open(KTable table, int col, int row, Rectangle rect) {
super.open(table, col, row, rect);
try {
Float val = Float.parseFloat(this.getEditorContent()
.replace(",", "."));// El la tabla se dibujan con coma pero para //$NON-NLS-1$ //$NON-NLS-2$
// parsearlos hace falta punto.
Integer i = (int) (val * Math.pow(10, this.digits));
this.component.setSelection(i);
} catch (java.lang.NumberFormatException e) {
this.component.setData(""); //$NON-NLS-1$
}
}
@Override
public void close(boolean save) {
if (save)
this.m_Model.setContentAt(this.m_Col, this.m_Row, this.component.getText());
super.close(save);
}
protected String getEditorContent() {
return this.m_Model.getContentAt(this.m_Col, this.m_Row)
.toString();
}
}
@@ -0,0 +1,83 @@
package flintstones.helper.wtable.wcelleditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Spinner;
import de.kupzog.ktable.KTable;
import de.kupzog.ktable.KTableCellEditor;
/**
* @author Sinbad2
* Spinner cell
*/
public class WCellEditorSpinner extends KTableCellEditor {
@Override
public int getActivationSignals() {
return KTableCellEditor.SINGLECLICK;
}
Spinner component;
// Cuando estas editanto el spinner, al pulsar en teclado
private final KeyAdapter keyListener = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
try {
WCellEditorSpinner.this.onKeyPressed(e);
} catch (Exception ex) {
// Do nothing
}
}
};
// Cuando estas editanto el spinner, al moverte a otra celda con teclado
private final TraverseListener travListener = e -> WCellEditorSpinner.this.onTraverse(e);
@Override
protected Control createControl() {
this.component = new Spinner(this.m_Table, SWT.NONE);
// component.setMaximum(9);
// component.setMinimum(6);
this.component.addKeyListener(this.keyListener);
this.component.addTraverseListener(this.travListener);
return this.component;
}
@Override
public void setContent(Object content) {
this.component.setData(content);
}
@Override
public void open(KTable table, int col, int row, Rectangle rect) {
super.open(table, col, row, rect);
try {
Integer val = Integer.parseInt(this.getEditorContent());
this.component.setSelection(val);
} catch (java.lang.NumberFormatException e) {
this.component.setData(""); //$NON-NLS-1$
}
/* m_Text.setText(getEditorContent()); m_Text.selectAll();
* m_Text.setVisible(true); m_Text.setFocus(); */
}
@Override
public void close(boolean save) {
if (save)
this.m_Model.setContentAt(this.m_Col, this.m_Row, this.component.getText());
super.close(save);
}
protected String getEditorContent() {
return this.m_Model.getContentAt(this.m_Col, this.m_Row)
.toString();
}
}