Search in sources :

Example 86 with DirectoryDialog

use of org.eclipse.swt.widgets.DirectoryDialog in project knime-core by knime.

the class WorkflowImportSelectionPage method handleDirBrowseButtonPressed.

private void handleDirBrowseButtonPressed() {
    DirectoryDialog dialog = new DirectoryDialog(getShell());
    // get initial root
    // 1. already something entered?
    String fileName = m_fromDirTextUI.getText().trim();
    if (fileName.isEmpty()) {
        // 2. something stored?
        fileName = initialDirLocation;
    }
    if (fileName.isEmpty()) {
        // set to workspace root
        fileName = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
    }
    File initialDir = new File(fileName);
    if (initialDir.exists()) {
        if (!initialDir.isDirectory()) {
            initialDir = initialDir.getParentFile();
        }
        dialog.setFilterPath(initialDir.getAbsolutePath());
    }
    final String selectedDir = dialog.open();
    // null if dialog was canceled/error occurred
    if (selectedDir != null) {
        collectWorkflowsFromDir(selectedDir);
    }
    validateWorkflows();
}
Also used : ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 87 with DirectoryDialog

use of org.eclipse.swt.widgets.DirectoryDialog in project yamcs-studio by yamcs.

the class SingleSourceHelper method handleTextInputFigureFileSelector.

public static void handleTextInputFigureFileSelector(TextInputFigure textInput) {
    String startPath = textInput.getStartPath();
    String currentPath = textInput.getCurrentPath();
    switch(textInput.getFileReturnPart()) {
        case DIRECTORY:
        case FULL_PATH:
            currentPath = textInput.getText();
            break;
        default:
            if (currentPath == null) {
                if (startPath == null)
                    currentPath = textInput.getText();
                else
                    currentPath = startPath;
            }
            break;
    }
    switch(textInput.getFileSource()) {
        case WORKSPACE:
            ResourceSelectionDialog dialog = new ResourceSelectionDialog(Display.getCurrent().getActiveShell(), "Select workspace file", // $NON-NLS-2$
            textInput.getFileReturnPart() == FileReturnPart.DIRECTORY ? null : new String[] { "*.*" });
            if (currentPath != null)
                dialog.setSelectedResource(new Path(currentPath));
            if (dialog.open() == Window.OK) {
                IPath path = dialog.getSelectedResource();
                currentPath = path.toPortableString();
                String fileString = currentPath;
                switch(textInput.getFileReturnPart()) {
                    case NAME_ONLY:
                        fileString = path.removeFileExtension().lastSegment();
                        break;
                    case NAME_EXT:
                        fileString = path.lastSegment();
                        break;
                    case FULL_PATH:
                    case DIRECTORY:
                    default:
                        break;
                }
                textInput.setText(fileString);
                textInput.setCurrentPath(currentPath);
                textInput.fireManualValueChange(textInput.getText());
            }
            break;
        case LOCAL:
            IPath[] paths = null;
            if (textInput.getFileReturnPart() == FileReturnPart.DIRECTORY) {
                DirectoryDialog directoryDialog = new DirectoryDialog(Display.getCurrent().getActiveShell());
                directoryDialog.setFilterPath(currentPath);
                String directory = directoryDialog.open();
                if (directory != null)
                    paths = new Path[] { new Path(directory) };
            } else {
                FileDialog fileDialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.MULTI);
                if (currentPath != null)
                    ((FileDialog) fileDialog).setFileName(currentPath);
                String firstPath = fileDialog.open();
                if (firstPath != null) {
                    paths = new Path[fileDialog.getFileNames().length];
                    paths[0] = new Path(firstPath);
                    for (int i = 1; i < paths.length; i++) {
                        paths[i] = paths[0].removeLastSegments(1).append(fileDialog.getFileNames()[i]);
                    }
                }
            }
            if (paths != null) {
                currentPath = paths[0].toOSString();
                StringBuilder result = new StringBuilder();
                switch(textInput.getFileReturnPart()) {
                    case NAME_ONLY:
                        for (int i = 0; i < paths.length; i++) {
                            if (i > 0)
                                result.append(SEPARATOR);
                            result.append(paths[i].removeFileExtension().lastSegment());
                        }
                        break;
                    case NAME_EXT:
                        for (int i = 0; i < paths.length; i++) {
                            if (i > 0)
                                result.append(SEPARATOR);
                            result.append(paths[i].lastSegment());
                        }
                        break;
                    case FULL_PATH:
                    case DIRECTORY:
                    default:
                        for (int i = 0; i < paths.length; i++) {
                            if (i > 0)
                                result.append(SEPARATOR);
                            result.append(paths[i].toOSString());
                        }
                        break;
                }
                textInput.setText(result.toString());
                textInput.setCurrentPath(currentPath);
                textInput.fireManualValueChange(textInput.getText());
            }
            break;
        default:
            break;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ResourceSelectionDialog(org.csstudio.ui.util.dialogs.ResourceSelectionDialog) IPath(org.eclipse.core.runtime.IPath) FileDialog(org.eclipse.swt.widgets.FileDialog) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 88 with DirectoryDialog

use of org.eclipse.swt.widgets.DirectoryDialog in project yamcs-studio by yamcs.

the class SelectWorkspaceDialog method createWorkspaceSection.

private void createWorkspaceSection(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    parent.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    parent.setLayoutData(gd);
    workspaces = new Combo(parent, SWT.DROP_DOWN);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    workspaces.setLayoutData(gd);
    // Fill w/ current workspace history, select the first one
    workspaces.setItems(recentWorkspaces);
    workspaces.select(0);
    Button browse = new Button(parent, SWT.PUSH);
    browse.setText("Browse");
    browse.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dialog = new DirectoryDialog(getShell());
            dialog.setText("Select Workspace");
            dialog.setMessage("Select existing workspace");
            dialog.setFilterPath(getInitialBrowsePath());
            String dir = dialog.open();
            if (dir != null) {
                workspaces.setText(dir);
            }
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Aggregations

DirectoryDialog (org.eclipse.swt.widgets.DirectoryDialog)88 SelectionEvent (org.eclipse.swt.events.SelectionEvent)51 Button (org.eclipse.swt.widgets.Button)49 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)48 GridData (org.eclipse.swt.layout.GridData)48 GridLayout (org.eclipse.swt.layout.GridLayout)47 Text (org.eclipse.swt.widgets.Text)47 Composite (org.eclipse.swt.widgets.Composite)42 Label (org.eclipse.swt.widgets.Label)40 Group (org.eclipse.swt.widgets.Group)27 File (java.io.File)25 ModifyListener (org.eclipse.swt.events.ModifyListener)22 ModifyEvent (org.eclipse.swt.events.ModifyEvent)21 Combo (org.eclipse.swt.widgets.Combo)21 FileDialog (org.eclipse.swt.widgets.FileDialog)11 TableViewer (org.eclipse.jface.viewers.TableViewer)8 Table (org.eclipse.swt.widgets.Table)8 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)7 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7