Search in sources :

Example 1 with FileSystemElement

use of org.eclipse.ui.dialogs.FileSystemElement in project linuxtools by eclipse.

the class ContainerCopyToPage method setupSelectionsBasedOnSelectedTypes.

/**
 * Update the tree to only select those elements that match the selected
 * types
 */
@SuppressWarnings("rawtypes")
@Override
protected void setupSelectionsBasedOnSelectedTypes() {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getContainer().getShell());
    final Map selectionMap = new Hashtable();
    final IElementFilter filter = new IElementFilter() {

        @Override
        public void filterElements(Collection files, IProgressMonitor monitor) throws InterruptedException {
            if (files == null) {
                throw new InterruptedException();
            }
            Iterator filesList = files.iterator();
            while (filesList.hasNext()) {
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                checkFile(filesList.next());
            }
        }

        @Override
        public void filterElements(Object[] files, IProgressMonitor monitor) throws InterruptedException {
            if (files == null) {
                throw new InterruptedException();
            }
            for (int i = 0; i < files.length; i++) {
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                checkFile(files[i]);
            }
        }

        @SuppressWarnings("unchecked")
        private void checkFile(Object fileElement) {
            MinimizedFileSystemElement file = (MinimizedFileSystemElement) fileElement;
            if (isExportableExtension(file.getFileNameExtension())) {
                List elements = new ArrayList();
                FileSystemElement parent = file.getParent();
                if (selectionMap.containsKey(parent)) {
                    elements = (List) selectionMap.get(parent);
                }
                elements.add(file);
                selectionMap.put(parent, elements);
            }
        }
    };
    IRunnableWithProgress runnable = monitor -> {
        monitor.beginTask(CopyToContainerMessages.ImportPage_filterSelections, IProgressMonitor.UNKNOWN);
        getSelectedResources(filter, monitor);
    };
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException exception) {
        // Couldn't start. Do nothing.
        return;
    } catch (InterruptedException exception) {
        // Got interrupted. Do nothing.
        return;
    }
    // make sure that all paint operations caused by closing the progress
    // dialog get flushed, otherwise extra pixels will remain on the screen
    // until
    // updateSelections is completed
    getShell().update();
    // a new process.
    if (selectionMap != null) {
        updateSelections(selectionMap);
    }
}
Also used : WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ContainerFileProxy(org.eclipse.linuxtools.internal.docker.core.ContainerFileProxy) BusyIndicator(org.eclipse.swt.custom.BusyIndicator) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) ContainerDirectorySelectionDialog(org.eclipse.linuxtools.internal.docker.ui.ContainerDirectorySelectionDialog) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ContainerFileSystemProvider(org.eclipse.linuxtools.internal.docker.ui.ContainerFileSystemProvider) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) FocusListener(org.eclipse.swt.events.FocusListener) Event(org.eclipse.swt.widgets.Event) ArrayList(java.util.ArrayList) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) BidiUtils(org.eclipse.jface.util.BidiUtils) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) GridData(org.eclipse.swt.layout.GridData) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Hashtable(java.util.Hashtable) MinimizedFileSystemElement(org.eclipse.linuxtools.internal.docker.ui.MinimizedFileSystemElement) Text(org.eclipse.swt.widgets.Text) WizardResourceImportPage(org.eclipse.ui.dialogs.WizardResourceImportPage) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Iterator(java.util.Iterator) IDEFileSystemStructureProvider(org.eclipse.linuxtools.internal.docker.ui.IDEFileSystemStructureProvider) Button(org.eclipse.swt.widgets.Button) NLS(org.eclipse.osgi.util.NLS) PlatformUI(org.eclipse.ui.PlatformUI) FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement) Collection(java.util.Collection) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IImportStructureProvider(org.eclipse.ui.wizards.datatransfer.IImportStructureProvider) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) SWTImagesFactory(org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory) Path(org.eclipse.core.runtime.Path) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) KeyListener(org.eclipse.swt.events.KeyListener) Label(org.eclipse.swt.widgets.Label) IElementFilter(org.eclipse.ui.ide.dialogs.IElementFilter) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Hashtable(java.util.Hashtable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) IElementFilter(org.eclipse.ui.ide.dialogs.IElementFilter) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MinimizedFileSystemElement(org.eclipse.linuxtools.internal.docker.ui.MinimizedFileSystemElement) Iterator(java.util.Iterator) MinimizedFileSystemElement(org.eclipse.linuxtools.internal.docker.ui.MinimizedFileSystemElement) FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 2 with FileSystemElement

use of org.eclipse.ui.dialogs.FileSystemElement in project linuxtools by eclipse.

the class SelectFilesOperation method run.

/**
 * Runs the operation.
 */
@Override
public void run(IProgressMonitor monitor) throws InterruptedException {
    try {
        this.monitor = monitor;
        monitor.beginTask(JobMessages.getString(POPULATING_CONTAINER_FILES), IProgressMonitor.UNKNOWN);
        result = createElement(null, root);
        if (result == null) {
            result = new FileSystemElement(provider.getLabel(root), null, provider.isFolder(root));
            result.setFileSystemObject(root);
        }
    } finally {
        monitor.done();
    }
}
Also used : FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement)

Example 3 with FileSystemElement

use of org.eclipse.ui.dialogs.FileSystemElement in project erlide_eclipse by erlang.

the class ErlangWizardResourceImportPage method createFileSelectionGroup.

/**
 * Create the import source selection widget
 */
protected void createFileSelectionGroup(final Composite parent) {
    // Just create with a dummy root.
    selectionGroup = new ResourceTreeAndListGroup(parent, // $NON-NLS-1$
    new FileSystemElement("Dummy", null, true), getFolderProvider(), new WorkbenchLabelProvider(), getFileProvider(), new WorkbenchLabelProvider(), SWT.NONE, DialogUtil.inRegularFontMode(parent));
    final ICheckStateListener listener = new ICheckStateListener() {

        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            updateWidgetEnablements();
        }
    };
    final WorkbenchViewerComparator comparator = new WorkbenchViewerComparator();
    selectionGroup.setTreeComparator(comparator);
    selectionGroup.setListComparator(comparator);
    selectionGroup.addCheckStateListener(listener);
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) WorkbenchViewerComparator(org.eclipse.ui.model.WorkbenchViewerComparator) ResourceTreeAndListGroup(org.erlide.ui.util.ResourceTreeAndListGroup)

Example 4 with FileSystemElement

use of org.eclipse.ui.dialogs.FileSystemElement in project linuxtools by eclipse.

the class ContainerCopyFromPage method createControl.

@Override
public void createControl(Composite parent) {
    // page group
    Composite composite = new Composite(parent, SWT.NULL);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(composite);
    GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(6, 6).applyTo(composite);
    Label targetLabel = new Label(composite, SWT.NULL);
    targetLabel.setText(WizardMessages.getString(TARGET_LABEL));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(false, false).applyTo(targetLabel);
    targetText = new Text(composite, SWT.BORDER | SWT.SINGLE);
    targetText.addModifyListener(Listener);
    targetText.setToolTipText(WizardMessages.getString(TARGET_TOOLTIP));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(targetText);
    browseButton = new Button(composite, SWT.NONE);
    browseButton.setText(WizardMessages.getString(BROWSE_LABEL));
    browseButton.addSelectionListener(onBrowseSelect());
    GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).span(1, 1).grab(false, false).applyTo(browseButton);
    // Create a fake parent of the root to be the dialog input element.
    // Use an empty label so that display of the element's full name
    // doesn't include a confusing label
    // $NON-NLS-1$
    FileSystemElement input = new FileSystemElement("", null, true);
    input.addChild(root);
    root.setParent(input);
    Composite selectionComposite = null;
    if (canBrowseContainer) {
        selectionComposite = new Composite(composite, SWT.NULL);
        GridLayout selectionLayout = new GridLayout();
        selectionComposite.setLayout(selectionLayout);
        selectionGroup = new CheckboxTreeAndListGroup(selectionComposite, input, getFolderProvider(), getDynamicFolderProvider(), new WorkbenchLabelProvider(), getFileProvider(), new WorkbenchLabelProvider(), SWT.NONE, // since this page has no
        SIZING_SELECTION_WIDGET_WIDTH, // other significantly-sized
        SIZING_SELECTION_WIDGET_HEIGHT);
        // hardcode the combined
        // widget's
        // size, otherwise it will open too small
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(3, 1).grab(true, false).applyTo(selectionComposite);
    } else {
        Label sourceLabel = new Label(composite, SWT.NONE);
        sourceLabel.setText(WizardMessages.getString(SOURCE_LABEL));
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(false, false).applyTo(sourceLabel);
        sourceText = new Text(composite, SWT.BORDER | SWT.SINGLE);
        sourceText.addModifyListener(Listener);
        sourceText.setToolTipText(WizardMessages.getString(SOURCE_TOOLTIP));
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(sourceText);
    }
    if (canBrowseContainer) {
        WorkbenchViewerComparator comparator = new WorkbenchViewerComparator();
        selectionGroup.setTreeComparator(comparator);
        selectionGroup.setListComparator(comparator);
        selectionGroup.addCheckStateListener(CheckListener);
    }
    setControl(composite);
    validate();
    setPageComplete(false);
    if (canBrowseContainer) {
        selectionGroup.aboutToOpen();
    }
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) MinimizedFileSystemElement(org.eclipse.linuxtools.internal.docker.ui.MinimizedFileSystemElement) FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement) Text(org.eclipse.swt.widgets.Text) WorkbenchViewerComparator(org.eclipse.ui.model.WorkbenchViewerComparator) CheckboxTreeAndListGroup(org.eclipse.linuxtools.internal.docker.ui.CheckboxTreeAndListGroup)

Example 5 with FileSystemElement

use of org.eclipse.ui.dialogs.FileSystemElement in project linuxtools by eclipse.

the class ContainerDirectorySelectionDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // page group
    Composite composite = (Composite) super.createDialogArea(parent);
    createMessageArea(composite);
    // Create a fake parent of the root to be the dialog input element.
    // Use an empty label so that display of the element's full name
    // doesn't include a confusing label
    // $NON-NLS-1$
    FileSystemElement input = new FileSystemElement("", null, true);
    input.addChild(root);
    root.setParent(input);
    selectionGroup = new ContainerTreeGroup(composite, input, getFolderProvider(), getDynamicFolderProvider(), new WorkbenchLabelProvider(), SWT.NONE, // since this page has no other significantly-sized
    SIZING_SELECTION_WIDGET_WIDTH, // widgets we need to hardcode the combined widget's
    SIZING_SELECTION_WIDGET_HEIGHT);
    // size, otherwise it will open too small
    ISelectionChangedListener listener = event -> getOkButton().setEnabled(event.getSelection() != null && !event.getSelection().isEmpty());
    WorkbenchViewerComparator comparator = new WorkbenchViewerComparator();
    selectionGroup.setTreeComparator(comparator);
    selectionGroup.addSelectionChangedListener(listener);
    return composite;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ContainerFileProxy(org.eclipse.linuxtools.internal.docker.core.ContainerFileProxy) Shell(org.eclipse.swt.widgets.Shell) FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement) WorkbenchViewerComparator(org.eclipse.ui.model.WorkbenchViewerComparator) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) IImportStructureProvider(org.eclipse.ui.wizards.datatransfer.IImportStructureProvider) ArrayList(java.util.ArrayList) List(java.util.List) Composite(org.eclipse.swt.widgets.Composite) SWT(org.eclipse.swt.SWT) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Control(org.eclipse.swt.widgets.Control) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement) WorkbenchViewerComparator(org.eclipse.ui.model.WorkbenchViewerComparator)

Aggregations

FileSystemElement (org.eclipse.ui.dialogs.FileSystemElement)7 ArrayList (java.util.ArrayList)4 Composite (org.eclipse.swt.widgets.Composite)4 Iterator (java.util.Iterator)3 List (java.util.List)3 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)3 SWT (org.eclipse.swt.SWT)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Button (org.eclipse.swt.widgets.Button)3 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)3 WorkbenchViewerComparator (org.eclipse.ui.model.WorkbenchViewerComparator)3 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)2 ContainerFileProxy (org.eclipse.linuxtools.internal.docker.core.ContainerFileProxy)2 MinimizedFileSystemElement (org.eclipse.linuxtools.internal.docker.ui.MinimizedFileSystemElement)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 GridData (org.eclipse.swt.layout.GridData)2 Control (org.eclipse.swt.widgets.Control)2 Shell (org.eclipse.swt.widgets.Shell)2 SelectionDialog (org.eclipse.ui.dialogs.SelectionDialog)2 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)2