Search in sources :

Example 1 with ContainerSelectionDialog

use of org.eclipse.ui.dialogs.ContainerSelectionDialog in project dbeaver by serge-rider.

the class PrefPageProjectSettings method createContents.

@Override
protected Control createContents(final Composite parent) {
    Composite composite = UIUtils.createPlaceholder(parent, 1, 5);
    {
        UIUtils.createControlLabel(composite, "Resource locations");
        resourceTable = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
        resourceTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        resourceTable.setHeaderVisible(true);
        resourceTable.setLinesVisible(true);
        UIUtils.createTableColumn(resourceTable, SWT.LEFT, "Resource");
        UIUtils.createTableColumn(resourceTable, SWT.LEFT, "Folder");
        resourceTable.setHeaderVisible(true);
        resourceTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        handlerTableEditor = new TableEditor(resourceTable);
        handlerTableEditor.verticalAlignment = SWT.TOP;
        handlerTableEditor.horizontalAlignment = SWT.RIGHT;
        handlerTableEditor.grabHorizontal = true;
        handlerTableEditor.grabVertical = true;
        resourceTable.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseUp(MouseEvent e) {
                disposeOldEditor();
                final TableItem item = resourceTable.getItem(new Point(0, e.y));
                if (item == null) {
                    return;
                }
                int columnIndex = UIUtils.getColumnAtPos(item, e.x, e.y);
                if (columnIndex <= 0) {
                    return;
                }
                if (columnIndex == 1) {
                    final String resourcePath = item.getText(1);
                    if (project != null) {
                        final IFolder folder = project.getFolder(resourcePath);
                        ContainerSelectionDialog dialog = new ContainerSelectionDialog(resourceTable.getShell(), folder, true, "Select " + item.getText(0) + " root folder");
                        dialog.showClosedProjects(false);
                        dialog.setValidator(new ISelectionValidator() {

                            @Override
                            public String isValid(Object selection) {
                                if (selection instanceof IPath) {
                                    final File file = ((IPath) selection).toFile();
                                    if (file.isHidden() || file.getName().startsWith(".")) {
                                        return "Can't use hidden folders";
                                    }
                                    final String[] segments = ((IPath) selection).segments();
                                    if (!project.getName().equals(segments[0])) {
                                        return "Can't store resources in another project";
                                    }
                                }
                                return null;
                            }
                        });
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            final Object[] result = dialog.getResult();
                            if (result.length == 1 && result[0] instanceof IPath) {
                                final IPath plainPath = ((IPath) result[0]).removeFirstSegments(1).removeTrailingSeparator();
                                item.setText(1, plainPath.toString());
                            }
                        }
                    } else {
                        final Text editor = new Text(resourceTable, SWT.NONE);
                        editor.setText(resourcePath);
                        editor.selectAll();
                        handlerTableEditor.setEditor(editor, item, 1);
                        editor.setFocus();
                        editor.addFocusListener(new FocusAdapter() {

                            @Override
                            public void focusLost(FocusEvent e) {
                                item.setText(1, editor.getText());
                            }
                        });
                    }
                }
            }
        });
    }
    performDefaults();
    return composite;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) IPath(org.eclipse.core.runtime.IPath) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ISelectionValidator(org.eclipse.ui.dialogs.ISelectionValidator) Point(org.eclipse.swt.graphics.Point) TableEditor(org.eclipse.swt.custom.TableEditor) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) GridData(org.eclipse.swt.layout.GridData) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with ContainerSelectionDialog

use of org.eclipse.ui.dialogs.ContainerSelectionDialog in project sling by apache.

the class SlingProjectPropertyPage method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite c = new Composite(parent, SWT.NONE);
    c.setLayout(new GridLayout(3, false));
    new Label(c, SWT.NONE).setText("Content sync root directory");
    folderText = new Text(c, SWT.BORDER);
    folderText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    folderText.setText(ProjectUtil.getSyncDirectoryValue(getProject()).toString());
    folderText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateApplyButton();
        }
    });
    Button browseButton = new Button(c, SWT.PUSH);
    browseButton.setText("Browse...");
    browseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final IProject project = getProject();
            ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), project, false, null);
            dialog.showClosedProjects(false);
            dialog.setValidator(new ISelectionValidator() {

                @Override
                public String isValid(Object selection) {
                    if (!(selection instanceof IPath)) {
                        return null;
                    }
                    IPath path = (IPath) selection;
                    if (project.getFullPath().isPrefixOf(path)) {
                        return null;
                    }
                    return "The folder must be contained in the " + project.getName() + " project";
                }
            });
            dialog.open();
            Object[] results = dialog.getResult();
            if (results == null) {
                return;
            }
            IPath selectedPath = (IPath) results[0];
            folderText.setText(selectedPath.removeFirstSegments(1).toString());
        }
    });
    Dialog.applyDialogFont(c);
    return c;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) IPath(org.eclipse.core.runtime.IPath) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ISelectionValidator(org.eclipse.ui.dialogs.ISelectionValidator) Text(org.eclipse.swt.widgets.Text) IProject(org.eclipse.core.resources.IProject) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 3 with ContainerSelectionDialog

use of org.eclipse.ui.dialogs.ContainerSelectionDialog in project sling by apache.

the class ImportWizardPage method queryForLocation.

protected IPath queryForLocation(IProject initialSelection, String msg, String title) {
    ContainerSelectionDialog dialog = new ContainerSelectionDialog(getControl().getShell(), initialSelection, allowNewContainerName(), msg);
    if (title != null) {
        dialog.setTitle(title);
    }
    dialog.showClosedProjects(false);
    dialog.setValidator(new ISelectionValidator() {

        @Override
        public String isValid(Object selection) {
            if (!(selection instanceof IPath)) {
                return "Please select a valid import location";
            }
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IContainer container = (IContainer) root.findMember((IPath) selection);
            if (container instanceof IProject) {
                return "Please select a folder inside the project";
            }
            if (!ProjectHelper.isContentProject(container.getProject())) {
                return "Project " + container.getProject().getName() + " is not a content project";
            }
            if (!ProjectUtil.isInsideContentSyncRoot(container)) {
                return "Please select a folder inside the content sync root folder " + ProjectUtil.getSyncDirectory(container.getProject()).getProjectRelativePath();
            }
            return null;
        }
    });
    dialog.open();
    Object[] result = dialog.getResult();
    if (result != null && result.length == 1) {
        return (IPath) result[0];
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) ISelectionValidator(org.eclipse.ui.dialogs.ISelectionValidator) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject)

Example 4 with ContainerSelectionDialog

use of org.eclipse.ui.dialogs.ContainerSelectionDialog in project dbeaver by dbeaver.

the class PrefPageProjectSettings method createContents.

@Override
protected Control createContents(final Composite parent) {
    Composite composite = UIUtils.createPlaceholder(parent, 1, 5);
    {
        UIUtils.createControlLabel(composite, CoreMessages.pref_page_projects_settings_label_resource_location);
        resourceTable = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
        resourceTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        resourceTable.setHeaderVisible(true);
        resourceTable.setLinesVisible(true);
        UIUtils.createTableColumn(resourceTable, SWT.LEFT, CoreMessages.pref_page_projects_settings_label_resource);
        UIUtils.createTableColumn(resourceTable, SWT.LEFT, CoreMessages.pref_page_projects_settings_label_folder);
        resourceTable.setHeaderVisible(true);
        resourceTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        handlerTableEditor = new TableEditor(resourceTable);
        handlerTableEditor.verticalAlignment = SWT.TOP;
        handlerTableEditor.horizontalAlignment = SWT.RIGHT;
        handlerTableEditor.grabHorizontal = true;
        handlerTableEditor.grabVertical = true;
        resourceTable.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseUp(MouseEvent e) {
                disposeOldEditor();
                final TableItem item = resourceTable.getItem(new Point(0, e.y));
                if (item == null) {
                    return;
                }
                int columnIndex = UIUtils.getColumnAtPos(item, e.x, e.y);
                if (columnIndex <= 0) {
                    return;
                }
                if (columnIndex == 1) {
                    final String resourcePath = item.getText(1);
                    if (project != null) {
                        final IFolder folder = project.getFolder(resourcePath);
                        ContainerSelectionDialog dialog = new ContainerSelectionDialog(resourceTable.getShell(), folder, true, CoreMessages.pref_page_projects_settings_label_select + item.getText(0) + CoreMessages.pref_page_projects_settings_label_root_folder);
                        dialog.showClosedProjects(false);
                        dialog.setValidator(new ISelectionValidator() {

                            @Override
                            public String isValid(Object selection) {
                                if (selection instanceof IPath) {
                                    final File file = ((IPath) selection).toFile();
                                    if (file.isHidden() || file.getName().startsWith(".")) {
                                        return CoreMessages.pref_page_projects_settings_label_not_use_hidden_folders;
                                    }
                                    final String[] segments = ((IPath) selection).segments();
                                    if (!project.getName().equals(segments[0])) {
                                        return CoreMessages.pref_page_projects_settings_label_not_store_resources_in_another_project;
                                    }
                                }
                                return null;
                            }
                        });
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            final Object[] result = dialog.getResult();
                            if (result.length == 1 && result[0] instanceof IPath) {
                                final IPath plainPath = ((IPath) result[0]).removeFirstSegments(1).removeTrailingSeparator();
                                item.setText(1, plainPath.toString());
                            }
                        }
                    } else {
                        final Text editor = new Text(resourceTable, SWT.NONE);
                        editor.setText(resourcePath);
                        editor.selectAll();
                        handlerTableEditor.setEditor(editor, item, 1);
                        editor.setFocus();
                        editor.addFocusListener(new FocusAdapter() {

                            @Override
                            public void focusLost(FocusEvent e) {
                                item.setText(1, editor.getText());
                            }
                        });
                    }
                }
            }
        });
        UIUtils.createInfoLabel(composite, CoreMessages.pref_page_projects_settings_label_restart_require_refresh_global_settings);
    }
    performDefaults();
    return composite;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) IPath(org.eclipse.core.runtime.IPath) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ISelectionValidator(org.eclipse.ui.dialogs.ISelectionValidator) Point(org.eclipse.swt.graphics.Point) TableEditor(org.eclipse.swt.custom.TableEditor) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) GridData(org.eclipse.swt.layout.GridData) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with ContainerSelectionDialog

use of org.eclipse.ui.dialogs.ContainerSelectionDialog in project org.csstudio.display.builder by kasemir.

the class NewDisplayWizardPage method handleBrowse.

private void handleBrowse() {
    final ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, Messages.NewDisplay_BrowseTitle);
    if (dialog.open() != ContainerSelectionDialog.OK)
        return;
    final Object[] result = dialog.getResult();
    if (result.length == 1)
        containerText.setText(((Path) result[0]).toString());
}
Also used : Path(org.eclipse.core.runtime.Path) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog)

Aggregations

ContainerSelectionDialog (org.eclipse.ui.dialogs.ContainerSelectionDialog)10 IPath (org.eclipse.core.runtime.IPath)6 GridData (org.eclipse.swt.layout.GridData)6 File (java.io.File)4 ISelectionValidator (org.eclipse.ui.dialogs.ISelectionValidator)4 IFolder (org.eclipse.core.resources.IFolder)3 IProject (org.eclipse.core.resources.IProject)3 TableEditor (org.eclipse.swt.custom.TableEditor)3 FocusAdapter (org.eclipse.swt.events.FocusAdapter)3 FocusEvent (org.eclipse.swt.events.FocusEvent)3 MouseAdapter (org.eclipse.swt.events.MouseAdapter)3 MouseEvent (org.eclipse.swt.events.MouseEvent)3 Point (org.eclipse.swt.graphics.Point)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 IResource (org.eclipse.core.resources.IResource)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 Path (org.eclipse.core.runtime.Path)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2