-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapted with dcf web service framework
- Loading branch information
1 parent
611aec2
commit ae1b023
Showing
12 changed files
with
366 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package data_collection; | ||
|
||
import org.eclipse.jface.viewers.IStructuredContentProvider; | ||
import org.eclipse.jface.viewers.Viewer; | ||
|
||
import data_collection.DcfDataCollectionsList; | ||
|
||
public class DataCollectionContentProvider implements IStructuredContentProvider { | ||
|
||
@Override | ||
public void dispose() {} | ||
|
||
@Override | ||
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {} | ||
|
||
@Override | ||
public Object[] getElements(Object arg0) { | ||
|
||
if (arg0 instanceof DcfDataCollectionsList) { | ||
DcfDataCollectionsList list = (DcfDataCollectionsList) arg0; | ||
return list.toArray(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package data_collection; | ||
|
||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
|
||
import org.eclipse.jface.viewers.ColumnLabelProvider; | ||
import org.eclipse.jface.viewers.ILabelProviderListener; | ||
import org.eclipse.swt.graphics.Image; | ||
|
||
import dataset.Dataset; | ||
|
||
/** | ||
* Label provider of the {@link Dataset} | ||
* @author avonva | ||
* | ||
*/ | ||
public class DataCollectionLabelProvider extends ColumnLabelProvider { | ||
|
||
public static final String STD_DATE_FORMAT = "yyyy-MM-dd"; | ||
|
||
private String key; | ||
public DataCollectionLabelProvider(String key) { | ||
this.key = key; | ||
} | ||
|
||
@Override | ||
public void addListener(ILabelProviderListener arg0) {} | ||
|
||
@Override | ||
public void dispose() {} | ||
|
||
@Override | ||
public boolean isLabelProperty(Object arg0, String arg1) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void removeListener(ILabelProviderListener arg0) {} | ||
|
||
@Override | ||
public Image getImage(Object arg0) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getText(Object arg0) { | ||
|
||
IDcfDataCollection dc = (IDcfDataCollection) arg0; | ||
|
||
String text = null; | ||
switch(key) { | ||
case "id": | ||
text = String.valueOf(dc.getId()); | ||
break; | ||
case "code": | ||
text = dc.getCode(); | ||
break; | ||
case "description": | ||
text = dc.getDescription(); | ||
break; | ||
case "activeFrom": | ||
DateFormat sdf = new SimpleDateFormat(STD_DATE_FORMAT); | ||
text = sdf.format(dc.getActiveFrom()); | ||
break; | ||
case "activeTo": | ||
sdf = new SimpleDateFormat(STD_DATE_FORMAT); | ||
text = sdf.format(dc.getActiveTo()); | ||
break; | ||
case "category": | ||
text = dc.getCategory(); | ||
break; | ||
case "resId": | ||
text = dc.getResourceId(); | ||
break; | ||
default: | ||
text = ""; | ||
break; | ||
} | ||
|
||
return text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package data_collection; | ||
|
||
import org.eclipse.jface.viewers.DoubleClickEvent; | ||
import org.eclipse.jface.viewers.IDoubleClickListener; | ||
import org.eclipse.jface.viewers.ISelection; | ||
import org.eclipse.jface.viewers.ISelectionChangedListener; | ||
import org.eclipse.jface.viewers.IStructuredSelection; | ||
import org.eclipse.jface.viewers.SelectionChangedEvent; | ||
import org.eclipse.jface.viewers.TableViewer; | ||
import org.eclipse.jface.viewers.TableViewerColumn; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.SelectionAdapter; | ||
import org.eclipse.swt.events.SelectionEvent; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.widgets.Button; | ||
import org.eclipse.swt.widgets.Dialog; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.swt.widgets.Shell; | ||
|
||
import i18n_messages.Messages; | ||
|
||
/** | ||
* Dialog showing a list of data collections | ||
* @author avonva | ||
* | ||
*/ | ||
public class DataCollectionsListDialog extends Dialog { | ||
|
||
private IDcfDataCollectionsList<IDcfDataCollection> list; | ||
private IDcfDataCollection selectedDc; | ||
|
||
public DataCollectionsListDialog(IDcfDataCollectionsList<IDcfDataCollection> list, Shell parent, int style) { | ||
super(parent, style); | ||
this.list = list; | ||
} | ||
|
||
public DataCollectionsListDialog(IDcfDataCollectionsList<IDcfDataCollection> list, Shell parent) { | ||
this(list, parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); | ||
} | ||
|
||
private void createContents(Shell shell) { | ||
|
||
TableViewer table = new TableViewer(shell, SWT.BORDER | SWT.SINGLE | ||
| SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.NONE); | ||
|
||
table.getTable().setHeaderVisible(true); | ||
table.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | ||
table.setContentProvider(new DataCollectionContentProvider()); | ||
|
||
table.addDoubleClickListener(new IDoubleClickListener() { | ||
@Override | ||
public void doubleClick(DoubleClickEvent arg0) { | ||
select(shell, arg0.getSelection()); | ||
} | ||
}); | ||
|
||
String[][] headers = new String[][] { | ||
{"code", Messages.get("dc.header.code")}, | ||
{"description", Messages.get("dc.header.description")}, | ||
{"activeFrom", Messages.get("dc.header.active.from")}, | ||
{"activeTo", Messages.get("dc.header.active.to")} | ||
}; | ||
|
||
for (String[] header : headers) { | ||
// Add the column to the parent table | ||
TableViewerColumn col = new TableViewerColumn(table, SWT.NONE); | ||
col.getColumn().setText(header[1]); | ||
col.setLabelProvider(new DataCollectionLabelProvider(header[0])); | ||
col.getColumn().setWidth(150); | ||
} | ||
|
||
table.setInput(list); | ||
|
||
Button button = new Button(shell, SWT.PUSH); | ||
button.setText(Messages.get("dc.dialog.button")); | ||
button.setEnabled(false); | ||
button.addSelectionListener(new SelectionAdapter() { | ||
@Override | ||
public void widgetSelected(SelectionEvent e) { | ||
select(shell, table.getSelection()); | ||
} | ||
}); | ||
button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false)); | ||
|
||
table.addSelectionChangedListener(new ISelectionChangedListener() { | ||
|
||
@Override | ||
public void selectionChanged(SelectionChangedEvent arg0) { | ||
button.setEnabled(!arg0.getSelection().isEmpty()); | ||
} | ||
}); | ||
} | ||
|
||
private void select(Shell shell, ISelection selection) { | ||
|
||
if (selection.isEmpty()) | ||
return; | ||
|
||
IStructuredSelection iSel = (IStructuredSelection) selection; | ||
|
||
selectedDc = (IDcfDataCollection) iSel.getFirstElement(); | ||
|
||
shell.close(); | ||
} | ||
|
||
public IDcfDataCollection open() { | ||
|
||
Shell shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.APPLICATION_MODAL); | ||
shell.setLayout(new GridLayout(1, false)); | ||
shell.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false)); | ||
|
||
shell.setText(Messages.get("dc.dialog.title")); | ||
shell.setImage(getParent().getImage()); | ||
|
||
createContents(shell); | ||
|
||
shell.pack(); | ||
shell.open(); | ||
|
||
Display display = getParent().getDisplay(); | ||
while (!shell.isDisposed()) { | ||
if (!display.readAndDispatch()) { | ||
display.sleep(); | ||
} | ||
} | ||
|
||
return selectedDc; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package data_collection; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.Collection; | ||
|
||
import app_config.PropertiesReader; | ||
|
||
public class GetAvailableDataCollections { | ||
|
||
/** | ||
* Get the available data collections codes starting from the | ||
* starting year of the data collection defined in the configuration | ||
* file. | ||
* @return | ||
*/ | ||
public static Collection<String> getCodes() { | ||
|
||
Collection<String> dcCodes = new ArrayList<>(); | ||
|
||
// add test data collection | ||
dcCodes.add(PropertiesReader.getTestDataCollectionCode()); | ||
|
||
// add all the data collections from the starting year | ||
// to today | ||
Calendar today = Calendar.getInstance(); | ||
int currentYear = today.get(Calendar.YEAR); | ||
int startingYear = PropertiesReader.getDataCollectionStartingYear(); | ||
|
||
// if other years are needed | ||
if (currentYear >= startingYear) { | ||
|
||
// add also the other years | ||
for (int i = currentYear; i >= startingYear; --i) { | ||
dcCodes.add(PropertiesReader.getDataCollectionCode(String.valueOf(i))); | ||
} | ||
} | ||
|
||
return dcCodes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.