Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Uploader
Commits
1ca24a1b
Commit
1ca24a1b
authored
Jun 25, 2014
by
Matija Obreza
Browse files
Columns databinding
parent
89f45299
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
1ca24a1b
...
...
@@ -121,6 +121,16 @@
<artifactId>
com.ibm.icu
</artifactId>
<version>
3.8.0
</version>
</dependency>
<dependency>
<groupId>
org.eclipse.maven
</groupId>
<artifactId>
org.eclipse.osgi.services
</artifactId>
<version>
3.8.0
</version>
</dependency>
<dependency>
<groupId>
org.eclipse.maven
</groupId>
<artifactId>
org.eclipse.osgi
</artifactId>
<version>
3.8.0
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
src/main/java/org/genesys2/anno/gui/AbstractModelObject.java
View file @
1ca24a1b
...
...
@@ -20,31 +20,29 @@ import java.beans.PropertyChangeListener;
import
java.beans.PropertyChangeSupport
;
public
abstract
class
AbstractModelObject
{
private
final
PropertyChangeSupport
propertyChangeSupport
=
new
PropertyChangeSupport
(
this
);
private
final
PropertyChangeSupport
propertyChangeSupport
=
new
PropertyChangeSupport
(
this
);
public
void
addPropertyChangeListener
(
PropertyChangeListener
listener
)
{
// System.out.println("Adding listener to " + this.getClass() + " of " + listener);
propertyChangeSupport
.
addPropertyChangeListener
(
listener
);
}
public
void
addPropertyChangeListener
(
String
propertyName
,
PropertyChangeListener
listener
)
{
public
void
addPropertyChangeListener
(
String
propertyName
,
PropertyChangeListener
listener
)
{
// System.out.println("Adding property listener '" + propertyName + "' to " + this.getClass() + " of " +
listener)
;
propertyChangeSupport
.
addPropertyChangeListener
(
propertyName
,
listener
);
}
public
void
removePropertyChangeListener
(
PropertyChangeListener
listener
)
{
// System.out.println("Removing property listener from " + this.getClass() + " of " + listener);
propertyChangeSupport
.
removePropertyChangeListener
(
listener
);
}
public
void
removePropertyChangeListener
(
String
propertyName
,
PropertyChangeListener
listener
)
{
propertyChangeSupport
.
removePropertyChangeListener
(
propertyName
,
listener
);
public
void
removePropertyChangeListener
(
String
propertyName
,
PropertyChangeListener
listener
)
{
// System.out.println("Removing property listener '" + propertyName + "' from " + this.getClass() + " of " + listener);
propertyChangeSupport
.
removePropertyChangeListener
(
propertyName
,
listener
);
}
protected
void
firePropertyChange
(
String
propertyName
,
Object
oldValue
,
Object
newValue
)
{
propertyChangeSupport
.
firePropertyChange
(
propertyName
,
oldValue
,
newValue
);
protected
void
firePropertyChange
(
String
propertyName
,
Object
oldValue
,
Object
newValue
)
{
propertyChangeSupport
.
firePropertyChange
(
propertyName
,
oldValue
,
newValue
);
}
}
src/main/java/org/genesys2/anno/gui/AppWindow.java
View file @
1ca24a1b
...
...
@@ -418,9 +418,6 @@ public class AppWindow {
CTabItem
newSheetTab
=
SheetTabFactory
.
createComposite
(
tabFolder
,
currentSheet
);
final
SheetDisplay
sheetDisplay
=
(
SheetDisplay
)
newSheetTab
.
getControl
();
// Load stuff
threadPool
.
execute
(
new
Runnable
()
{
...
...
@@ -429,17 +426,7 @@ public class AppWindow {
try
{
final
List
<
Object
[]>
rows
=
dataSourceLoader
.
loadRows
(
currentSheet
,
100
);
// for (Object[] row : rows) {
// System.err.println(ArrayUtils.toString(row));
// }
// Need to update sheetDisplay
display
.
asyncExec
(
new
Runnable
()
{
public
void
run
()
{
sheetDisplay
.
setRows
(
rows
);
}
});
currentSheet
.
updateData
(
rows
);
}
catch
(
UnsupportedDataFormatException
e
)
{
e
.
printStackTrace
();
...
...
src/main/java/org/genesys2/anno/gui/DataSourceSheet.java
View file @
1ca24a1b
...
...
@@ -22,6 +22,8 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
org.genesys2.anno.model.Column
;
public
class
DataSourceSheet
extends
AbstractModelObject
{
private
File
sourceFile
;
private
String
sheetName
;
...
...
@@ -29,6 +31,8 @@ public class DataSourceSheet extends AbstractModelObject {
private
Map
<
String
,
String
>
columnTerms
=
new
HashMap
<
String
,
String
>();
private
boolean
headersIncluded
=
true
;
private
int
headerRowIndex
=
0
;
private
List
<
Object
[]>
sampleData
;
private
List
<
Column
>
columns
=
new
ArrayList
<
Column
>();
public
DataSourceSheet
(
File
sourceFile
)
{
this
.
sourceFile
=
new
File
(
sourceFile
.
getAbsolutePath
());
...
...
@@ -84,4 +88,73 @@ public class DataSourceSheet extends AbstractModelObject {
this
.
headerRowIndex
=
headerRowIndex
;
firePropertyChange
(
"headerRowIndex"
,
null
,
headerRowIndex
);
}
public
void
updateData
(
List
<
Object
[]>
rows
)
{
int
columnCount
=
0
;
for
(
Object
[]
row
:
rows
)
{
if
(
row
!=
null
)
columnCount
=
Math
.
max
(
columnCount
,
row
.
length
);
}
Object
[]
headers
=
null
;
if
(
headersIncluded
)
{
this
.
sampleData
=
rows
.
subList
(
headerRowIndex
+
1
,
rows
.
size
());
try
{
Object
[]
headerRow
=
rows
.
get
(
headerRowIndex
);
headers
=
headerRow
;
}
catch
(
IndexOutOfBoundsException
e
)
{
}
}
else
{
this
.
sampleData
=
rows
;
}
// Make sure we have the Columns in the list
ensureColumns
(
columnCount
,
headers
);
System
.
err
.
println
(
"Firing sampleData change"
);
firePropertyChange
(
"sampleData"
,
null
,
this
.
sampleData
);
}
private
void
ensureColumns
(
int
columnCount
,
Object
[]
headerRow
)
{
boolean
changed
=
false
;
for
(
int
i
=
columns
.
size
()
-
1
;
i
>=
0
&&
i
>
columnCount
;
i
--)
{
System
.
err
.
println
(
"Removing extra columns"
);
columns
.
remove
(
i
);
changed
=
true
;
}
for
(
int
i
=
columns
.
size
();
i
<
columnCount
;
i
++)
{
System
.
err
.
println
(
"Adding column "
+
i
);
columns
.
add
(
new
Column
());
changed
=
true
;
}
for
(
int
i
=
columns
.
size
()
-
1
;
i
>=
0
;
i
--)
{
String
headerColumnName
=
(
headerRow
!=
null
&&
headerRow
.
length
>
i
?
String
.
valueOf
(
headerRow
[
i
])
:
null
);
Column
c
=
columns
.
get
(
i
);
c
.
setPreferredName
(
headerColumnName
==
null
?
"Column "
+
i
:
headerColumnName
);
}
// fire change
if
(
changed
)
firePropertyChange
(
"columns"
,
null
,
columns
);
}
public
List
<
Object
[]>
getSampleData
()
{
return
sampleData
;
}
public
List
<
Column
>
getColumns
()
{
return
this
.
columns
;
}
public
void
setColumns
(
List
<
Column
>
columns
)
{
this
.
columns
=
columns
;
firePropertyChange
(
"columns"
,
null
,
this
.
columns
);
}
public
Column
getColumn
(
int
columnIndex
)
{
return
this
.
columns
.
get
(
columnIndex
);
}
}
src/main/java/org/genesys2/anno/gui/SheetDisplay.java
View file @
1ca24a1b
This diff is collapsed.
Click to expand it.
src/main/java/org/genesys2/anno/model/Column.java
View file @
1ca24a1b
...
...
@@ -19,7 +19,9 @@ package org.genesys2.anno.model;
import
java.util.HashSet
;
import
java.util.Set
;
public
class
Column
{
import
org.genesys2.anno.gui.AbstractModelObject
;
public
class
Column
extends
AbstractModelObject
{
private
String
preferredName
;
private
String
rdfTerm
;
private
String
description
;
...
...
@@ -32,8 +34,7 @@ public class Column {
public
Column
()
{
}
public
Column
(
String
preferredName
,
ColumnDataType
dataType
,
boolean
multiple
,
boolean
unique
,
String
rdfTerm
)
{
public
Column
(
String
preferredName
,
ColumnDataType
dataType
,
boolean
multiple
,
boolean
unique
,
String
rdfTerm
)
{
this
.
preferredName
=
preferredName
;
this
.
dataType
=
dataType
;
this
.
multiple
=
multiple
;
...
...
@@ -47,6 +48,7 @@ public class Column {
public
void
setPreferredName
(
String
preferredName
)
{
this
.
preferredName
=
preferredName
;
firePropertyChange
(
"preferredName"
,
null
,
this
.
preferredName
);
}
public
String
getRdfTerm
()
{
...
...
@@ -55,6 +57,7 @@ public class Column {
public
void
setRdfTerm
(
String
rdfTerm
)
{
this
.
rdfTerm
=
rdfTerm
;
firePropertyChange
(
"rdfTerm"
,
null
,
this
.
rdfTerm
);
}
public
String
getDescription
()
{
...
...
@@ -63,6 +66,7 @@ public class Column {
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
firePropertyChange
(
"description"
,
null
,
this
.
description
);
}
public
ColumnDataType
getDataType
()
{
...
...
@@ -71,6 +75,7 @@ public class Column {
public
void
setDataType
(
ColumnDataType
dataType
)
{
this
.
dataType
=
dataType
;
firePropertyChange
(
"dataType"
,
null
,
this
.
dataType
);
}
public
boolean
isUnique
()
{
...
...
@@ -79,6 +84,7 @@ public class Column {
public
void
setUnique
(
boolean
unique
)
{
this
.
unique
=
unique
;
firePropertyChange
(
"unique"
,
null
,
this
.
unique
);
}
public
boolean
isMultiple
()
{
...
...
@@ -87,6 +93,7 @@ public class Column {
public
void
setMultiple
(
boolean
multiple
)
{
this
.
multiple
=
multiple
;
firePropertyChange
(
"multiple"
,
null
,
this
.
multiple
);
}
public
Set
<
ColumnValidator
>
getValidators
()
{
...
...
@@ -103,5 +110,6 @@ public class Column {
public
void
setPattern
(
String
pattern
)
{
this
.
pattern
=
pattern
;
firePropertyChange
(
"pattern"
,
null
,
this
.
pattern
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment