Skip to content

Commit

Permalink
adapted with dcf web service framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinoAvonEFSA committed Jan 19, 2018
1 parent 611aec2 commit ae1b023
Show file tree
Hide file tree
Showing 12 changed files with 366 additions and 51 deletions.
26 changes: 26 additions & 0 deletions src/data_collection/DataCollectionContentProvider.java
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;
}
}
82 changes: 82 additions & 0 deletions src/data_collection/DataCollectionLabelProvider.java
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;
}
}
130 changes: 130 additions & 0 deletions src/data_collection/DataCollectionsListDialog.java
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;
}
}
41 changes: 41 additions & 0 deletions src/data_collection/GetAvailableDataCollections.java
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;
}
}
6 changes: 3 additions & 3 deletions src/dataset/DatasetList.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @author avonva
*
*/
public class DatasetList extends ArrayList<IDataset> implements IDcfDatasetsList {
public class DatasetList extends ArrayList<IDataset> implements IDcfDatasetsList<IDataset> {

/**
*
Expand Down Expand Up @@ -298,7 +298,7 @@ public DatasetList getDownloadableDatasets(String validSenderIdPattern) {
}

@Override
public boolean addElem(IDcfDataset dataset) {
public boolean add(IDataset dataset) {

// we know its a dataset instance
Dataset d = (Dataset) dataset;
Expand All @@ -308,7 +308,7 @@ public boolean addElem(IDcfDataset dataset) {
}

@Override
public IDcfDataset create() {
public IDataset create() {
return new Dataset();
}
}
11 changes: 11 additions & 0 deletions src/i18n_messages/rcl_messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ dataset.header.sender.id=Sender id
dataset.header.status=DCF status
dataset.header.revision=Dataset revision

### data collections list dialog
dc.dialog.title=Your data collections
dc.dialog.button=Open datasets
dc.header.id=Id
dc.header.code=Code
dc.header.description=Description
dc.header.active.from=Active from
dc.header.active.to=Active to
dc.header.category=Category
dc.header.resource.id=Resource id

### progress bar
send.progress.title=Sending report

Expand Down
Loading

0 comments on commit ae1b023

Please sign in to comment.