Search in sources :

Example 6 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 7 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 8 with ContainerSelectionDialog

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

the class PrefPageProjectResourceSettings method createContents.

@Override
protected Control createContents(final Composite parent) {
    Composite composite = UIUtils.createComposite(parent, 1);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        UIUtils.createControlLabel(composite, UINavigatorMessages.pref_page_projects_settings_label_resource_location);
        resourceTable = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 400;
        gd.heightHint = 300;
        resourceTable.setLayoutData(gd);
        resourceTable.setHeaderVisible(true);
        resourceTable.setLinesVisible(true);
        UIUtils.createTableColumn(resourceTable, SWT.LEFT, UINavigatorMessages.pref_page_projects_settings_label_resource);
        UIUtils.createTableColumn(resourceTable, SWT.LEFT, UINavigatorMessages.pref_page_projects_settings_label_folder);
        resourceTable.setHeaderVisible(true);
        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, UINavigatorMessages.pref_page_projects_settings_label_select + item.getText(0) + UINavigatorMessages.pref_page_projects_settings_label_root_folder);
                        dialog.showClosedProjects(false);
                        dialog.setValidator(selection -> {
                            if (selection instanceof IPath) {
                                final File file = ((IPath) selection).toFile();
                                if (file.isHidden() || file.getName().startsWith(".")) {
                                    return UINavigatorMessages.pref_page_projects_settings_label_not_use_hidden_folders;
                                }
                                final String[] segments = ((IPath) selection).segments();
                                if (!project.getName().equals(segments[0])) {
                                    return UINavigatorMessages.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, UINavigatorMessages.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) 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 9 with ContainerSelectionDialog

use of org.eclipse.ui.dialogs.ContainerSelectionDialog in project mechanoid by robotoworks.

the class ContainerBrowserField method onBrowseButtonPressed.

@Override
protected void onBrowseButtonPressed() {
    ContainerSelectionDialog dialog = new ContainerSelectionDialog(PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(), (IContainer) mWorkspaceRoot.findMember(mSelectedPath), true, Messages.ContainerBrowserField_ContainerSelectionDialog_Message);
    dialog.setTitle(Messages.ContainerBrowserField_Title);
    dialog.setBlockOnOpen(true);
    if (dialog.open() == Window.OK) {
        mSelectedPath = (IPath) dialog.getResult()[0];
        getTextField().setText(mSelectedPath.toPortableString());
    }
}
Also used : ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog)

Example 10 with ContainerSelectionDialog

use of org.eclipse.ui.dialogs.ContainerSelectionDialog in project InformationSystem by ObeoNetwork.

the class ExportAsSQLScriptsAction method getContainingFolder.

private IResource getContainingFolder(Comparison comparison) {
    if (comparison.getMatches() != null && comparison.getMatches().isEmpty() == false) {
        Match match = comparison.getMatches().get(0);
        Resource resource = match.getLeft().eResource();
        if (resource instanceof CDOResource) {
            return getModelingProject(resource);
        } else if (resource.getURI().isPlatformResource()) {
            String uri = resource.getURI().toPlatformString(true);
            Path path = new Path(uri);
            return ResourcesPlugin.getWorkspace().getRoot().getFile(path).getParent();
        } else if (activeEditor.getEditorInput() instanceof ThreeWayResourceCompareInput) {
            // The resource is a SVN resource
            try {
                IEditorInput editorInput = activeEditor.getEditorInput();
                Field localField = editorInput.getClass().getDeclaredField("local");
                localField.setAccessible(true);
                ILocalResource local = (ILocalResource) localField.get(editorInput);
                return local.getResource().getParent();
            } catch (ReflectiveOperationException e) {
            // The fallback case below will apply
            } catch (SecurityException e) {
            // The fallback case below will apply
            } catch (IllegalArgumentException e) {
            // The fallback case below will apply
            }
        }
        // Fallback case
        ContainerSelectionDialog projectSelectionDialog = new ContainerSelectionDialog(activeEditor.getSite().getShell(), null, false, "Sélectionner le projet de destination :");
        projectSelectionDialog.setTitle("Sélection de projet");
        if (projectSelectionDialog.open() == ContainerSelectionDialog.OK && projectSelectionDialog.getResult().length == 1) {
            Path projectPath = (Path) projectSelectionDialog.getResult()[0];
            IResource selectedResource = ResourcesPlugin.getWorkspace().getRoot().findMember(projectPath);
            if (selectedResource instanceof IProject) {
                return selectedResource;
            }
        }
    }
    return null;
}
Also used : Path(org.eclipse.core.runtime.Path) ThreeWayResourceCompareInput(org.eclipse.team.svn.ui.compare.ThreeWayResourceCompareInput) ILocalResource(org.eclipse.team.svn.core.resource.ILocalResource) Resource(org.eclipse.emf.ecore.resource.Resource) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource) ILocalResource(org.eclipse.team.svn.core.resource.ILocalResource) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) Match(org.eclipse.emf.compare.Match) Field(java.lang.reflect.Field) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Aggregations

ContainerSelectionDialog (org.eclipse.ui.dialogs.ContainerSelectionDialog)30 IPath (org.eclipse.core.runtime.IPath)15 GridData (org.eclipse.swt.layout.GridData)11 IProject (org.eclipse.core.resources.IProject)8 File (java.io.File)7 Path (org.eclipse.core.runtime.Path)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 GridLayout (org.eclipse.swt.layout.GridLayout)7 Button (org.eclipse.swt.widgets.Button)7 IResource (org.eclipse.core.resources.IResource)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 Label (org.eclipse.swt.widgets.Label)6 Text (org.eclipse.swt.widgets.Text)6 IContainer (org.eclipse.core.resources.IContainer)5 Composite (org.eclipse.swt.widgets.Composite)5 IFolder (org.eclipse.core.resources.IFolder)4 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)4 ModifyListener (org.eclipse.swt.events.ModifyListener)4 Group (org.eclipse.swt.widgets.Group)4