Search in sources :

Example 1 with EHadoopFileTypes

use of org.talend.designer.hdfsbrowse.model.EHadoopFileTypes in project tbd-studio-se by Talend.

the class HDFSFileSelectorForm method updateItem.

private void updateItem(final TreeItem item, boolean checked, boolean isEvent, IProgressMonitor monitor) {
    if (monitor != null && monitor.isCanceled()) {
        return;
    }
    IHDFSNode node = (IHDFSNode) item.getData();
    if (node == null) {
        return;
    }
    EHadoopFileTypes type = node.getType();
    if (type != EHadoopFileTypes.FILE) {
        item.setChecked(checked);
    }
    if (type == EHadoopFileTypes.FOLDER) {
        for (TreeItem treeItem : item.getItems()) {
            updateItem(treeItem, checked, true, monitor);
        }
    } else if (type == EHadoopFileTypes.FILE) {
        String pattern = getNameFilter();
        SearchPattern matcher = new SearchPattern();
        matcher.setPattern(pattern);
        if (!matcher.matches(node.getValue())) {
            return;
        }
        if (checked) {
            // $NON-NLS-1$
            item.setText(4, Messages.getString("HDFSFileSelectorForm.Pending"));
            parentWizardPage.setPageComplete(false);
            refreshTable(item, -1);
            item.setChecked(true);
        } else {
            clearTreeItem(item);
            item.setChecked(false);
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) EHadoopFileTypes(org.talend.designer.hdfsbrowse.model.EHadoopFileTypes) SearchPattern(org.eclipse.ui.dialogs.SearchPattern) IHDFSNode(org.talend.designer.hdfsbrowse.model.IHDFSNode)

Example 2 with EHadoopFileTypes

use of org.talend.designer.hdfsbrowse.model.EHadoopFileTypes in project tbd-studio-se by Talend.

the class HDFSFileSelectorForm method addFieldsListeners.

/*
     * (non-Javadoc)
     *
     * @see org.talend.repository.ui.swt.utils.AbstractForm#addFieldsListeners()
     */
@Override
protected void addFieldsListeners() {
    nameFilter.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            schemaTreeViewer.refresh();
        }
    });
    schemaTree.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (e.detail == SWT.CHECK) {
                final TreeItem treeItem = (TreeItem) e.item;
                IHDFSNode node = (IHDFSNode) treeItem.getData();
                final boolean promptNeeded = treeItem.getChecked();
                EHadoopFileTypes type = node.getType();
                if (type != EHadoopFileTypes.FILE) {
                    treeItem.setGrayed(promptNeeded);
                }
                if (type == EHadoopFileTypes.FILE) {
                    if (promptNeeded) {
                        treeItem.setText(3, EMPTY_STRING);
                        // $NON-NLS-1$
                        treeItem.setText(4, Messages.getString("HDFSFileSelectorForm.Pending"));
                        parentWizardPage.setPageComplete(false);
                        selectedNode = (IHDFSNode) treeItem.getData();
                        refreshTable(treeItem, -1);
                    } else {
                        clearTreeItem(treeItem);
                    }
                } else if (type == EHadoopFileTypes.FOLDER) {
                    if (!promptNeeded) {
                        threadExecutor.clearRunnable(node.getPath());
                    }
                    long checkedSize = fetchAllChildren(new TreeItem[] { treeItem });
                    boolean continueCheck = true;
                    if (promptNeeded && INFORM_SIZE < checkedSize) {
                        continueCheck = MessageDialog.openConfirm(getShell(), Messages.getString("HDFSFileSelectorForm.title.confirm"), // $NON-NLS-1$
                        Messages.getString("HDFSFileSelectorForm.confirm.executeConfirm", // $NON-NLS-1$
                        new Object[] { INFORM_SIZE }));
                    }
                    if (continueCheck) {
                        selectedNode = (IHDFSNode) treeItem.getData();
                        updateItems(treeItem.getItems(), promptNeeded, true);
                    } else {
                        treeItem.setGrayed(!promptNeeded);
                        treeItem.setChecked(!promptNeeded);
                    }
                }
            }
        }
    });
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EHadoopFileTypes(org.talend.designer.hdfsbrowse.model.EHadoopFileTypes) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IHDFSNode(org.talend.designer.hdfsbrowse.model.IHDFSNode)

Example 3 with EHadoopFileTypes

use of org.talend.designer.hdfsbrowse.model.EHadoopFileTypes in project tbd-studio-se by Talend.

the class HDFSFileSelectorForm method refreshItem.

private void refreshItem(TreeItem item) {
    if (item != null && item.getData() != null) {
        EHadoopFileTypes type = ((IHDFSNode) item.getData()).getType();
        if (type == EHadoopFileTypes.FILE) {
            item.setChecked(false);
            if (item.getData() != null) {
                IHDFSNode node = (IHDFSNode) item.getData();
                if (isExistTable(node)) {
                    item.setChecked(true);
                    Integer num = tableColumnNums.get(item.getText(0));
                    if (num != null) {
                        // get column num from previous result
                        item.setText(3, num.toString());
                        // $NON-NLS-1$
                        item.setText(4, Messages.getString("HDFSFileSelectorForm.title.success"));
                    } else {
                        // retrieve column num again
                        refreshTable(item, -1);
                    }
                }
            }
        }
    }
}
Also used : EHadoopFileTypes(org.talend.designer.hdfsbrowse.model.EHadoopFileTypes) IHDFSNode(org.talend.designer.hdfsbrowse.model.IHDFSNode)

Example 4 with EHadoopFileTypes

use of org.talend.designer.hdfsbrowse.model.EHadoopFileTypes in project tbd-studio-se by Talend.

the class FileSelectorTreeViewerProvider method getColumnText.

public String getColumnText(Object element, int columnIndex) {
    IHDFSNode content = (IHDFSNode) element;
    EHadoopFileTypes type = content.getType();
    switch(columnIndex) {
        case 0:
            return StringUtils.trimToEmpty(content.getValue());
        case 1:
            return StringUtils.trimToEmpty(type.getValue());
        case 2:
            if (content instanceof HDFSFile) {
                HDFSFile file = (HDFSFile) content;
                return StringUtils.trimToEmpty(file.getSize());
            } else {
                return EMPTY_STRING;
            }
        default:
            return EMPTY_STRING;
    }
}
Also used : EHadoopFileTypes(org.talend.designer.hdfsbrowse.model.EHadoopFileTypes) HDFSFile(org.talend.designer.hdfsbrowse.model.HDFSFile) IHDFSNode(org.talend.designer.hdfsbrowse.model.IHDFSNode)

Example 5 with EHadoopFileTypes

use of org.talend.designer.hdfsbrowse.model.EHadoopFileTypes in project tbd-studio-se by Talend.

the class HDFSFileSelectorForm method restoreCheckItems.

protected void restoreCheckItems(TreeItem treeItem, List<String> checkedItems) {
    // If all the checked items are updated then no need to restore.
    if (checkedItems.size() == 0) {
        return;
    }
    IHDFSNode node = (IHDFSNode) treeItem.getData();
    if (node == null) {
        return;
    }
    EHadoopFileTypes type = node.getType();
    if (type == EHadoopFileTypes.FOLDER) {
        for (TreeItem item : treeItem.getItems()) {
            IHDFSNode childNode = (IHDFSNode) item.getData();
            if (childNode == null) {
                node.getChildren();
            }
            restoreCheckItems(item, checkedItems);
        }
    } else if (type == EHadoopFileTypes.FILE) {
        refreshItem(treeItem);
        checkedItems.remove(node.getTable().getName());
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) EHadoopFileTypes(org.talend.designer.hdfsbrowse.model.EHadoopFileTypes) IHDFSNode(org.talend.designer.hdfsbrowse.model.IHDFSNode)

Aggregations

EHadoopFileTypes (org.talend.designer.hdfsbrowse.model.EHadoopFileTypes)6 IHDFSNode (org.talend.designer.hdfsbrowse.model.IHDFSNode)6 TreeItem (org.eclipse.swt.widgets.TreeItem)3 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SearchPattern (org.eclipse.ui.dialogs.SearchPattern)1 HDFSFile (org.talend.designer.hdfsbrowse.model.HDFSFile)1