Search in sources :

Example 6 with IHDFSNode

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

the class HDFSFileSelectorForm method refreshTable.

protected void refreshTable(final TreeItem treeItem, final int size) {
    IHDFSNode node = (IHDFSNode) treeItem.getData();
    if (!threadExecutor.isThreadRunning(treeItem)) {
        if (node.getType() == EHadoopFileTypes.FILE) {
            RetrieveColumnRunnable runnable = new RetrieveColumnRunnable(treeItem);
            threadExecutor.execute(runnable);
        }
    } else {
        RetrieveColumnRunnable runnable = threadExecutor.getRunnable(node.getPath());
        runnable.setCanceled(false);
    }
}
Also used : IHDFSNode(org.talend.designer.hdfsbrowse.model.IHDFSNode)

Example 7 with IHDFSNode

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

the class HDFSFileSelectorForm method addSchemaFields.

private void addSchemaFields() {
    schemaTreeViewer = new ContainerCheckedTreeViewer(scrolledCompositeFileViewer, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    schemaTreeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    schemaTreeViewer.setUseHashlookup(true);
    schemaTreeViewer.addFilter(new FileSelectorViewerFilter());
    schemaTree = schemaTreeViewer.getTree();
    schemaTree.setHeaderVisible(true);
    schemaTree.setLinesVisible(true);
    schemaTree.addListener(SWT.Expand, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TreeItem treeItem = (TreeItem) event.item;
            for (TreeItem item : treeItem.getItems()) {
                if (item.getData() != null) {
                    IHDFSNode node = (IHDFSNode) item.getData();
                    if (node.getType() == EHadoopFileTypes.FILE) {
                        if (isExistTable(node)) {
                            item.setChecked(true);
                            updateParentItemCheckStatus(item);
                        } else {
                            TreeEditor treeEditor = treeEditorMap.get(item);
                            if (treeEditor == null) {
                                item.setChecked(false);
                            }
                        }
                    } else {
                    // item.setGrayed(item.getChecked());
                    }
                }
            }
        }
    });
    int columnWidth1 = 250;
    int columnWidth2 = 100;
    int columnWidth3 = 110;
    int columnWidth4 = 130;
    int columnWidth5 = 140;
    TreeColumn fileName = new TreeColumn(schemaTree, SWT.LEFT);
    // $NON-NLS-1$
    fileName.setText(Messages.getString("HDFSFileSelectorForm.schemaTree.nameColumn"));
    fileName.setWidth(columnWidth1);
    TreeColumn fileType = new TreeColumn(schemaTree, SWT.LEFT);
    // $NON-NLS-1$
    fileType.setText(Messages.getString("HDFSFileSelectorForm.schemaTree.typeColumn"));
    fileType.setWidth(columnWidth2);
    TreeColumn fileSize = new TreeColumn(schemaTree, SWT.LEFT);
    // $NON-NLS-1$
    fileSize.setText(Messages.getString("HDFSFileSelectorForm.schemaTree.sizeColumn"));
    fileSize.setWidth(columnWidth3);
    TreeColumn nbColumns = new TreeColumn(schemaTree, SWT.LEFT);
    // $NON-NLS-1$
    nbColumns.setText(Messages.getString("HDFSFileSelectorForm.schemaTree.numberColumn"));
    nbColumns.setWidth(columnWidth4);
    TreeColumn creationStatus = new TreeColumn(schemaTree, SWT.LEFT);
    // $NON-NLS-1$
    creationStatus.setText(Messages.getString("HDFSFileSelectorForm.schemaTree.statusColumn"));
    creationStatus.setWidth(columnWidth5);
    AbstractMetadataExtractorViewProvider viewProvider = new FileSelectorTreeViewerProvider();
    schemaTreeViewer.setLabelProvider(viewProvider);
    schemaTreeViewer.setContentProvider(viewProvider);
    schemaTreeViewer.setInput(connectionBean = getConnectionBean());
    scrolledCompositeFileViewer.setContent(schemaTree);
    scrolledCompositeFileViewer.setMinSize(schemaTree.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
Also used : Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) Point(org.eclipse.swt.graphics.Point) AbstractMetadataExtractorViewProvider(org.talend.core.repository.model.provider.AbstractMetadataExtractorViewProvider) FileSelectorTreeViewerProvider(org.talend.designer.hdfsbrowse.ui.provider.FileSelectorTreeViewerProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn) GridData(org.eclipse.swt.layout.GridData) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) IHDFSNode(org.talend.designer.hdfsbrowse.model.IHDFSNode)

Example 8 with IHDFSNode

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

the class HDFSFileSelectorForm method updateParentItemCheckStatus.

private static void updateParentItemCheckStatus(TreeItem item) {
    TreeItem parentItem = item.getParentItem();
    if (parentItem == null) {
        return;
    }
    boolean hasCheckedItem = false;
    boolean hasUncheckedItem = false;
    for (TreeItem i : parentItem.getItems()) {
        if (hasCheckedItem && hasUncheckedItem) {
            break;
        }
        IHDFSNode node = (IHDFSNode) i.getData();
        if (node.getType() == EHadoopFileTypes.FOLDER && i.getGrayed() == true) {
            hasCheckedItem = true;
            hasUncheckedItem = true;
        }
        if (i.getChecked()) {
            hasCheckedItem = true;
        } else {
            hasUncheckedItem = true;
        }
    }
    if (!hasCheckedItem) {
        parentItem.setChecked(false);
    } else if (hasCheckedItem && hasUncheckedItem) {
        parentItem.setChecked(true);
        parentItem.setGrayed(true);
    } else {
        parentItem.setChecked(true);
        parentItem.setGrayed(false);
    }
    updateParentItemCheckStatus(parentItem);
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) IHDFSNode(org.talend.designer.hdfsbrowse.model.IHDFSNode)

Example 9 with IHDFSNode

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

the class HDFSFileSelectorForm method fetchAllChildren.

protected long fetchAllChildren(final TreeItem[] treeItems) {
    long childSize = 0;
    try {
        final StringBuffer fetchNumber = new StringBuffer();
        parentWizardPage.getWizard().getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        // $NON-NLS-1$
                        monitor.beginTask(Messages.getString("HDFSFileSelectorForm.fetchChildren"), IProgressMonitor.UNKNOWN);
                        long checkedSize = 0;
                        for (TreeItem tItem : treeItems) {
                            if (monitor != null && monitor.isCanceled()) {
                                break;
                            }
                            checkedSize += fetchAllChildren((IHDFSNode) tItem.getData(), monitor);
                        }
                        fetchNumber.append(checkedSize);
                        monitor.done();
                    }
                });
            // System.out.println("monitor:" + monitor.isCanceled());
            }
        });
        if (0 < fetchNumber.length()) {
            childSize = Long.valueOf(fetchNumber.toString());
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return childSize;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TreeItem(org.eclipse.swt.widgets.TreeItem) IHDFSNode(org.talend.designer.hdfsbrowse.model.IHDFSNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 10 with IHDFSNode

use of org.talend.designer.hdfsbrowse.model.IHDFSNode 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)

Aggregations

IHDFSNode (org.talend.designer.hdfsbrowse.model.IHDFSNode)13 TreeItem (org.eclipse.swt.widgets.TreeItem)6 EHadoopFileTypes (org.talend.designer.hdfsbrowse.model.EHadoopFileTypes)6 TreeEditor (org.eclipse.swt.custom.TreeEditor)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 Button (org.eclipse.swt.widgets.Button)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1 Text (org.eclipse.swt.widgets.Text)1 TreeColumn (org.eclipse.swt.widgets.TreeColumn)1 ContainerCheckedTreeViewer (org.eclipse.ui.dialogs.ContainerCheckedTreeViewer)1