Search in sources :

Example 46 with Command

use of org.zkoss.bind.annotation.Command in project collect by openforis.

the class CodeListsVM method exportCodeList.

@Command
public void exportCodeList() throws IOException {
    CollectSurvey survey = getSurvey();
    CodeListExportProcess codeListExportProcess = new CodeListExportProcess(codeListManager);
    File tempFile = File.createTempFile("code_list_" + editedItem.getName(), ".csv");
    FileOutputStream os = new FileOutputStream(tempFile);
    codeListExportProcess.exportToCSV(os, survey, editedItem.getId());
    Filedownload.save(tempFile, CSV_CONTENT_TYPE);
}
Also used : CodeListExportProcess(org.openforis.collect.manager.dataexport.codelist.CodeListExportProcess) FileOutputStream(java.io.FileOutputStream) CollectSurvey(org.openforis.collect.model.CollectSurvey) File(java.io.File) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 47 with Command

use of org.zkoss.bind.annotation.Command in project collect by openforis.

the class CodeListsVM method batchImportFileUploaded.

@Command
public void batchImportFileUploaded(@ContextParam(ContextType.TRIGGER_EVENT) UploadEvent event) {
    Media media = event.getMedia();
    String fileName = media.getName();
    String extension = FilenameUtils.getExtension(fileName);
    File tempFile = OpenForisIOUtils.copyToTempFile(media.getStreamData(), extension);
    batchImportJob = new CodeListBatchImportJob();
    batchImportJob.setJobManager(jobManager);
    batchImportJob.setCodeListManager(codeListManager);
    batchImportJob.setSurvey(survey);
    batchImportJob.setOverwriteData(true);
    batchImportJob.setFile(tempFile);
    jobManager.start(batchImportJob);
    jobStatusPopUp = JobStatusPopUpVM.openPopUp(Labels.getLabel("survey.code_list.batch_import"), batchImportJob, true);
}
Also used : CodeListBatchImportJob(org.openforis.collect.io.metadata.codelist.CodeListBatchImportJob) Media(org.zkoss.util.media.Media) File(java.io.File) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 48 with Command

use of org.zkoss.bind.annotation.Command in project collect by openforis.

the class SchemaLayoutSimpleVM method addTab.

@Command
@NotifyChange({ "treeModel", "selectedTab" })
public void addTab(@BindingParam("parent") UITabSet parent) {
    if (rootTabSet != null) {
        if (parent == null) {
            parent = rootTabSet;
            treeModel.deselect();
        }
        CollectSurvey survey = getSurvey();
        UIOptions uiOptions = survey.getUIOptions();
        UITab tab = uiOptions.createTab();
        String label = Labels.getLabel("survey.schema.node.layout.default_tab_label");
        tab.setLabel(currentLanguageCode, label);
        parent.addTab(tab);
        treeModel.appendNodeToSelected(tab);
        selectedTab = tab;
        dispatchTabSetChangedCommand();
    }
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) CollectSurvey(org.openforis.collect.model.CollectSurvey) NotifyChange(org.zkoss.bind.annotation.NotifyChange) Command(org.zkoss.bind.annotation.Command) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 49 with Command

use of org.zkoss.bind.annotation.Command in project collect by openforis.

the class SchemaLayoutSimpleVM method removeTab.

@Command
public void removeTab() {
    String confirmMessageKey = null;
    if (!selectedTab.getTabs().isEmpty()) {
        confirmMessageKey = "survey.layout.tab.remove.confirm.nested_tabs_present";
    } else {
        CollectSurvey survey = getSurvey();
        UIOptions uiOpts = survey.getUIOptions();
        List<NodeDefinition> nodesPerTab = uiOpts.getNodesPerTab(selectedTab, false);
        if (!nodesPerTab.isEmpty()) {
            confirmMessageKey = "survey.layout.tab.remove.confirm.associated_nodes_present";
        }
    }
    if (confirmMessageKey != null) {
        MessageUtil.ConfirmParams params = new MessageUtil.ConfirmParams(new MessageUtil.ConfirmHandler() {

            @Override
            public void onOk() {
                performRemoveSelectedTab();
            }
        }, confirmMessageKey);
        params.setOkLabelKey("global.delete_item");
        MessageUtil.showConfirm(params);
    } else {
        performRemoveSelectedTab();
    }
}
Also used : MessageUtil(org.openforis.collect.designer.util.MessageUtil) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) Command(org.zkoss.bind.annotation.Command) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 50 with Command

use of org.zkoss.bind.annotation.Command in project collect by openforis.

the class SurveyConfigurationEditVM method applyChanges.

@Command
@NotifyChange({ "editedTabDefinition", "editedTab", "selectedTab" })
public void applyChanges() {
    CollectSurvey survey = getSurvey();
    UIConfiguration uiConfiguration = survey.getUIConfiguration();
    if (newTab) {
        if (editedTabDefinition != null) {
            uiConfiguration.addTabDefinition(editedTabDefinition);
            treeModel.appendToSelected(editedTabDefinition);
            selectedTab = editedTabDefinition;
        } else if (editedTab != null) {
            selectedTab.addTab(editedTab);
            treeModel.appendToSelected(editedTab);
            selectedTab = editedTab;
        }
    } else {
        String tabName = selectedTab.getName();
        if (editedTabDefinition != null) {
            String newName = editedTabDefinition.getName();
            UITabDefinition newTabDefn = uiConfiguration.updateTabDefinition(tabName, newName);
            // TODO avoid use of side effect...
            // treeModel.updateSelectedNode(newTabDefn);
            selectedTab = newTabDefn;
        } else {
            selectedTab.setName(editedTab.getName());
            ((UITab) selectedTab).setLabel(editedTab.getLabel());
        // TODO avoid use of side effect...
        // treeModel.updateSelectedNode(editedTab);
        }
    }
    newTab = false;
    HashMap<String, Object> args = new HashMap<String, Object>();
    args.put("tab", selectedTab);
    BindUtils.postGlobalCommand(null, null, TAB_DEFINITIONS_UPDATED_COMMAND, args);
}
Also used : UITab(org.openforis.collect.model.ui.UITab) HashMap(java.util.HashMap) UIConfiguration(org.openforis.collect.model.ui.UIConfiguration) UITabDefinition(org.openforis.collect.model.ui.UITabDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) NotifyChange(org.zkoss.bind.annotation.NotifyChange) Command(org.zkoss.bind.annotation.Command)

Aggregations

Command (org.zkoss.bind.annotation.Command)62 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)44 NotifyChange (org.zkoss.bind.annotation.NotifyChange)26 File (java.io.File)12 CollectSurvey (org.openforis.collect.model.CollectSurvey)10 MessageUtil (org.openforis.collect.designer.util.MessageUtil)9 UITab (org.openforis.collect.metamodel.ui.UITab)6 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)6 FileInputStream (java.io.FileInputStream)5 ConfirmParams (org.openforis.collect.designer.util.MessageUtil.ConfirmParams)5 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)5 SurveyObject (org.openforis.idm.metamodel.SurveyObject)5 Media (org.zkoss.util.media.Media)5 Window (org.zkoss.zul.Window)5 UserCredential (es.bsc.compss.ui.auth.UserCredential)4 IOException (java.io.IOException)4 Date (java.util.Date)4 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)4 SessionStatus (org.openforis.collect.designer.session.SessionStatus)3 ConfirmHandler (org.openforis.collect.designer.util.MessageUtil.ConfirmHandler)3