2013-10-24 16:55:27 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.user.td.sdmximportwidget.client;
|
|
|
|
|
2013-11-21 10:38:11 +01:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
|
2013-10-24 16:55:27 +02:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportSession;
|
|
|
|
import org.gcube.portlets.user.td.sdmximportwidget.client.general.WizardCard;
|
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.user.client.Command;
|
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
import com.sencha.gxt.widget.core.client.FramedPanel;
|
2013-10-24 18:55:33 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
|
2013-10-24 16:55:27 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.button.TextButton;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
|
2013-10-24 18:55:33 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent;
|
2013-10-24 16:55:27 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
2013-10-24 18:55:33 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
|
2013-10-24 16:55:27 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
|
|
|
import com.sencha.gxt.widget.core.client.form.FieldLabel;
|
|
|
|
import com.sencha.gxt.widget.core.client.form.FieldSet;
|
|
|
|
import com.sencha.gxt.widget.core.client.form.TextArea;
|
|
|
|
import com.sencha.gxt.widget.core.client.form.TextField;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2013-10-25 14:54:36 +02:00
|
|
|
* @author "Giancarlo Panichi" <a
|
|
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
|
|
*
|
2013-10-24 16:55:27 +02:00
|
|
|
*/
|
|
|
|
public class SDMXTableDetailCard extends WizardCard {
|
2013-10-25 14:54:36 +02:00
|
|
|
|
|
|
|
protected final String TABLEDETAILPANELWIDTH = "100%";
|
|
|
|
protected final String TABLEDETAILPANELHEIGHT = "100%";
|
|
|
|
protected final String FORMWIDTH = "538px";
|
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
protected SDMXImportSession importSession;
|
|
|
|
protected SDMXTableDetailCard thisCard;
|
2013-10-25 14:54:36 +02:00
|
|
|
|
|
|
|
protected static final AgenciesProperties agenciesProperties = GWT
|
|
|
|
.create(AgenciesProperties.class);
|
2013-10-24 16:55:27 +02:00
|
|
|
protected VerticalLayoutContainer p = new VerticalLayoutContainer();
|
|
|
|
protected VerticalPanel tableDetailPanel;
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
protected TextField name;
|
|
|
|
protected TextArea description;
|
|
|
|
protected TextArea rights;
|
|
|
|
protected TextField agencyName;
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
protected TextButton checkButton;
|
|
|
|
|
2013-10-25 14:54:36 +02:00
|
|
|
// protected ComboBox<Agencies> combo=null;
|
|
|
|
|
|
|
|
TabResource detail = new TabResource();
|
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
public SDMXTableDetailCard(final SDMXImportSession importSession) {
|
|
|
|
super("SDMX Table Detail", "");
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
this.importSession = importSession;
|
2013-10-25 14:54:36 +02:00
|
|
|
thisCard = this;
|
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
tableDetailPanel = new VerticalPanel();
|
|
|
|
|
|
|
|
tableDetailPanel.setSpacing(4);
|
2013-10-25 14:54:36 +02:00
|
|
|
tableDetailPanel.setWidth(TABLEDETAILPANELWIDTH);
|
|
|
|
tableDetailPanel.setHeight(TABLEDETAILPANELHEIGHT);
|
|
|
|
|
|
|
|
FramedPanel form = new FramedPanel();
|
|
|
|
form.setHeadingText("Details");
|
|
|
|
form.setWidth(FORMWIDTH);
|
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
FieldSet fieldSet = new FieldSet();
|
|
|
|
fieldSet.setHeadingText("Information");
|
|
|
|
fieldSet.setCollapsible(false);
|
2013-10-25 14:54:36 +02:00
|
|
|
form.add(fieldSet);
|
|
|
|
|
|
|
|
// VerticalLayoutContainer p = new VerticalLayoutContainer();
|
2013-10-24 16:55:27 +02:00
|
|
|
fieldSet.add(p);
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
name = new TextField();
|
|
|
|
name.setAllowBlank(false);
|
|
|
|
name.setEmptyText("Enter a name...");
|
|
|
|
name.setValue(importSession.getSelectedCodelist().getName());
|
|
|
|
p.add(new FieldLabel(name, "Name"), new VerticalLayoutData(1, -1));
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
description = new TextArea();
|
|
|
|
description.setAllowBlank(false);
|
|
|
|
description.setEmptyText("Enter a description...");
|
2013-10-25 14:54:36 +02:00
|
|
|
description.setValue(importSession.getSelectedCodelist()
|
|
|
|
.getDescription());
|
|
|
|
p.add(new FieldLabel(description, "Description"),
|
|
|
|
new VerticalLayoutData(1, -1));
|
|
|
|
|
|
|
|
rights = new TextArea();
|
2013-10-24 16:55:27 +02:00
|
|
|
rights.setEmptyText("Enter rights...");
|
|
|
|
rights.setAllowBlank(false);
|
|
|
|
p.add(new FieldLabel(rights, "Rights"), new VerticalLayoutData(1, -1));
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
/*
|
2013-10-25 14:54:36 +02:00
|
|
|
* ListStore<Agencies> agenciesStore = new
|
|
|
|
* ListStore<Agencies>(agenciesProperties.key());
|
|
|
|
*
|
|
|
|
* RpcProxy<PagingLoadConfig, PagingLoadResult<Agencies>> proxy = new
|
|
|
|
* RpcProxy<PagingLoadConfig, PagingLoadResult<Agencies>>() {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* public void load(PagingLoadConfig loadConfig, final
|
|
|
|
* AsyncCallback<PagingLoadResult<Agencies>> callback) {
|
|
|
|
* loadData(loadConfig, callback); } };
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* final PagingLoader<PagingLoadConfig, PagingLoadResult<Agencies>>
|
|
|
|
* loader = new PagingLoader<PagingLoadConfig,
|
|
|
|
* PagingLoadResult<Agencies>>(proxy);
|
|
|
|
*
|
|
|
|
* loader.setRemoteSort(false); loader.addLoadHandler(new
|
|
|
|
* LoadResultListStoreBinding<PagingLoadConfig, Agencies,
|
|
|
|
* PagingLoadResult<Agencies>>(agenciesStore));
|
|
|
|
*
|
|
|
|
* //agenciesStore.addAll(TestData.getStates());
|
|
|
|
*
|
|
|
|
* combo = new ComboBox<Agencies>(agenciesStore,
|
|
|
|
* agenciesProperties.nameLabel());
|
|
|
|
* addHandlersForEventObservation(combo,
|
|
|
|
* agenciesProperties.nameLabel());
|
|
|
|
*
|
|
|
|
* combo.setLoader(loader); combo.setEmptyText("Enter Agency...");
|
|
|
|
* combo.setTriggerAction(TriggerAction.ALL);
|
|
|
|
* combo.setAllowBlank(false); combo.setForceSelection(true);
|
|
|
|
* combo.setVisible(true);
|
|
|
|
*/
|
2013-10-24 16:55:27 +02:00
|
|
|
|
2013-10-25 14:54:36 +02:00
|
|
|
// HorizontalLayoutContainer agenciesSelect= selectAgencies();
|
|
|
|
// p.add(new FieldLabel(combo, "Agencies"), new VerticalLayoutData(1,
|
|
|
|
// -1));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FieldLabel comboLabel=new FieldLabel(combo, "");
|
|
|
|
* comboLabel.setLabelSeparator(""); p.add(comboLabel, new
|
|
|
|
* VerticalLayoutData(1, -1));
|
|
|
|
*/
|
|
|
|
|
|
|
|
agencyName = new TextField();
|
|
|
|
agencyName.setVisible(true);
|
2013-10-24 16:55:27 +02:00
|
|
|
agencyName.setEmptyText("Enter Agency...");
|
|
|
|
agencyName.setValue(importSession.getSelectedCodelist().getAgencyId());
|
2013-10-25 14:54:36 +02:00
|
|
|
FieldLabel agencyNameLabel = new FieldLabel(agencyName, "Agency");
|
|
|
|
agencyNameLabel.setLabelSeparator("");
|
|
|
|
p.add(agencyNameLabel, new VerticalLayoutData(1, -1));
|
|
|
|
|
|
|
|
checkButton = new TextButton("Save");
|
2013-10-24 16:55:27 +02:00
|
|
|
checkButton.addSelectHandler(new SelectHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
|
|
checkData();
|
|
|
|
}
|
|
|
|
});
|
2013-10-25 14:54:36 +02:00
|
|
|
form.addButton(checkButton);
|
|
|
|
|
|
|
|
tableDetailPanel.add(form);
|
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
setContent(tableDetailPanel);
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
}
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
protected void checkData() {
|
|
|
|
if (name.getValue() == null || name.getValue().isEmpty()
|
2013-10-25 14:54:36 +02:00
|
|
|
|| !name.isValid() || description.getValue() == null
|
|
|
|
|| description.getValue().isEmpty() || !description.isValid()
|
2013-10-24 16:55:27 +02:00
|
|
|
|| rights.getValue() == null || rights.getValue().isEmpty()
|
2013-10-25 14:54:36 +02:00
|
|
|
|| !rights.isValid() || agencyName.getValue() == null
|
|
|
|
|| agencyName.getValue().isEmpty() || !agencyName.isValid()) {
|
|
|
|
AlertMessageBox d = new AlertMessageBox("Attention!",
|
|
|
|
"Fill in all fields");
|
2013-10-24 18:55:33 +02:00
|
|
|
d.addHideHandler(new HideHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onHide(HideEvent event) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
d.show();
|
2013-10-24 16:55:27 +02:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
name.setReadOnly(true);
|
|
|
|
description.setReadOnly(true);
|
|
|
|
rights.setReadOnly(true);
|
|
|
|
agencyName.setReadOnly(true);
|
|
|
|
checkButton.disable();
|
|
|
|
getWizardWindow().setEnableNextButton(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 14:54:36 +02:00
|
|
|
/*
|
|
|
|
* protected void loadData(PagingLoadConfig loadConfig, final
|
|
|
|
* AsyncCallback<PagingLoadResult<Agencies>> callback) {
|
|
|
|
* TDGXTServiceAsync.INSTANCE.getAgencies(new
|
|
|
|
* AsyncCallback<List<Agencies>>() {
|
|
|
|
*
|
|
|
|
* @Override public void onFailure(Throwable caught) {
|
|
|
|
* callback.onFailure(caught); }
|
|
|
|
*
|
|
|
|
* @Override public void onSuccess(List<Agencies> result) {
|
|
|
|
* Log.trace("loaded "+result.size()+" agencies"); for(int i=0;
|
|
|
|
* i<result.size(); i++){ Agencies ag=result.get(i);
|
|
|
|
* //if(ag.getId().compareTo()) }
|
|
|
|
*
|
|
|
|
* callback.onSuccess(new PagingLoadResultBean<Agencies>(result,
|
|
|
|
* result.size(), 0)); } }); }
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to add handlers to observe events that occur on each combobox
|
|
|
|
*
|
|
|
|
* private <T> void addHandlersForEventObservation(final ComboBox<T> combo,
|
|
|
|
* final LabelProvider<T> labelProvider) { combo.addValueChangeHandler(new
|
|
|
|
* ValueChangeHandler<T>() {
|
|
|
|
*
|
|
|
|
* @Override public void onValueChange(ValueChangeEvent<T> event) {
|
|
|
|
*
|
|
|
|
* Info.display("Value Changed", "New value: " + (event.getValue()
|
|
|
|
* == null ? combo.getValue() :
|
|
|
|
* labelProvider.getLabel(event.getValue()) + "!")); } });
|
|
|
|
*
|
|
|
|
* combo.addSelectionHandler(new SelectionHandler<T>() {
|
|
|
|
* @Override public void onSelection(SelectionEvent<T> event) {
|
|
|
|
* Info.display("Agency Selected", "You selected " +
|
|
|
|
* (event.getSelectedItem() == null ? combo.getValue() :
|
|
|
|
* labelProvider.getLabel(event.getSelectedItem()) + "!")); } });
|
|
|
|
* }
|
|
|
|
*/
|
2013-10-24 16:55:27 +02:00
|
|
|
|
|
|
|
@Override
|
2013-10-25 14:54:36 +02:00
|
|
|
public void setup() {
|
2013-10-24 16:55:27 +02:00
|
|
|
Command sayNextCard = new Command() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute() {
|
|
|
|
detail.setName(name.getCurrentValue());
|
2013-10-25 14:54:36 +02:00
|
|
|
// detail.setAgency(combo.getSelectedText());
|
2013-10-24 16:55:27 +02:00
|
|
|
detail.setAgency(agencyName.getCurrentValue());
|
|
|
|
detail.setDescription(description.getCurrentValue());
|
|
|
|
detail.setRight(rights.getCurrentValue());
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
importSession.setTabResource(detail);
|
|
|
|
SDMXOperationInProgressCard sdmxOperationInProgressCard = new SDMXOperationInProgressCard(
|
|
|
|
importSession);
|
2013-10-25 14:54:36 +02:00
|
|
|
getWizardWindow().addCard(sdmxOperationInProgressCard);
|
2013-10-24 16:55:27 +02:00
|
|
|
Log.info("NextCard SDMXOperationInProgressCard");
|
|
|
|
getWizardWindow().nextCard();
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
}
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
};
|
2013-10-25 14:54:36 +02:00
|
|
|
|
|
|
|
getWizardWindow().setNextButtonCommand(sayNextCard);
|
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
Command sayPreviousCard = new Command() {
|
|
|
|
public void execute() {
|
|
|
|
try {
|
|
|
|
getWizardWindow().previousCard();
|
|
|
|
getWizardWindow().removeCard(thisCard);
|
|
|
|
Log.info("Remove SDMXTableDetailCard");
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.error("sayPreviousCard :" + e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 14:54:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
getWizardWindow().setPreviousButtonCommand(sayPreviousCard);
|
|
|
|
getWizardWindow().setEnableNextButton(false);
|
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
}
|
2013-10-25 14:54:36 +02:00
|
|
|
|
2013-10-24 16:55:27 +02:00
|
|
|
/*
|
2013-10-25 14:54:36 +02:00
|
|
|
* private HorizontalLayoutContainer selectAgencies(){
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* HorizontalLayoutContainer documentSelectionPanel = new
|
|
|
|
* HorizontalLayoutContainer();
|
|
|
|
*
|
|
|
|
* Radio radioAgenciesAlready = new Radio();
|
|
|
|
*
|
|
|
|
* radioAgenciesAlready.setBoxLabel("Present");
|
|
|
|
* radioAgenciesAlready.setValue(true);
|
|
|
|
* radioAgenciesAlready.setName("Agencies");
|
|
|
|
*
|
|
|
|
* Radio radioAgencyNew = new Radio(); radioAgencyNew.setBoxLabel("New");
|
|
|
|
* radioAgencyNew.setName("AgencyNew");
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* documentSelectionPanel.add(radioAgenciesAlready);
|
|
|
|
* documentSelectionPanel.add(radioAgencyNew);
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* ToggleGroup toggle = new ToggleGroup(); toggle.add(radioAgenciesAlready);
|
|
|
|
* toggle.add(radioAgencyNew);
|
|
|
|
*
|
|
|
|
* toggle.addValueChangeHandler(new ValueChangeHandler<HasValue<Boolean>>()
|
|
|
|
* {
|
|
|
|
*
|
|
|
|
* @Override public void onValueChange(ValueChangeEvent<HasValue<Boolean>>
|
|
|
|
* event) { try { ToggleGroup group = (ToggleGroup) event.getSource(); Radio
|
|
|
|
* radio = (Radio) group.getValue(); Log.info("Document Selected:" +
|
|
|
|
* radio.getName()); if (radio.getName().compareTo("AgencyNew") == 0) {
|
|
|
|
* //agencyName.setVisible(true); //combo.setVisible(false); // } else { if
|
|
|
|
* (radio.getName().compareTo("Agency") == 0) {
|
|
|
|
* //agencyName.setVisible(false); //combo.setVisible(true); // } else {
|
|
|
|
*
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* } catch (Exception e) { Log.error("ToggleGroup: onValueChange " +
|
|
|
|
* e.getLocalizedMessage()); }
|
|
|
|
*
|
|
|
|
* } });
|
|
|
|
*
|
|
|
|
* return documentSelectionPanel;
|
|
|
|
*
|
|
|
|
* }
|
2013-10-24 16:55:27 +02:00
|
|
|
*/
|
|
|
|
}
|