Search in sources :

Example 16 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project whole by wholeplatform.

the class ReplaceWithResourceAction method performWorkspaceResourceSelection.

protected boolean performWorkspaceResourceSelection(Shell shell, IEntity entity) {
    IPath filePath = Path.fromPortableString(path);
    IResource resource = filePath.isAbsolute() ? ResourcesPlugin.getWorkspace().getRoot().findMember(filePath) : null;
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setInput(ResourcesPlugin.getWorkspace());
    dialog.setTitle(SELECT_RESOURCE_MSG);
    dialog.setMessage("Choose a resource");
    dialog.setInitialSelection(resource);
    if (dialog.open() != IDialogConstants.OK_ID)
        return false;
    Object[] selection = dialog.getResult();
    path = selection.length == 0 ? "/" : ((IResource) selection[0]).getFullPath().toPortableString();
    return true;
}
Also used : ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IPath(org.eclipse.core.runtime.IPath) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IResource(org.eclipse.core.resources.IResource)

Example 17 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project whole by wholeplatform.

the class WizardArtifactsModelImportPage1 method createSourceGroup.

@Override
protected void createSourceGroup(Composite parent) {
    resourceChooser = new TreeViewer(parent);
    GridLayout listAreaLayout = new GridLayout();
    listAreaLayout.marginWidth = 0;
    parent.setLayout(listAreaLayout);
    resourceChooser.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    resourceChooser.setContentProvider(new WorkbenchContentProvider());
    resourceChooser.setLabelProvider(new WorkbenchLabelProvider());
    resourceChooser.setComparator(new WorkbenchViewerComparator());
    resourceChooser.setInput(ResourcesPlugin.getWorkspace());
    resourceChooser.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            updatePageCompletion();
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) GridData(org.eclipse.swt.layout.GridData) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) WorkbenchViewerComparator(org.eclipse.ui.model.WorkbenchViewerComparator)

Example 18 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project ecf by eclipse.

the class RemotePeerSynchronizeWizardPage method createResourcesViewer.

private void createResourcesViewer(Composite composite) {
    resourcesViewer = new ContainerCheckedTreeViewer(composite);
    resourcesViewer.setContentProvider(new WorkbenchContentProvider() {

        public Object[] getChildren(Object element) {
            if (element instanceof org.eclipse.core.resources.IContainer) {
                try {
                    IResource[] members = ((org.eclipse.core.resources.IContainer) element).members();
                    List nonDerivedMembers = new ArrayList();
                    for (int i = 0; i < members.length; i++) {
                        if (!members[i].isDerived()) {
                            nonDerivedMembers.add(members[i]);
                        }
                    }
                    return nonDerivedMembers.toArray();
                } catch (CoreException e) {
                    return new IResource[0];
                }
            }
            return new IResource[0];
        }

        public boolean hasChildren(Object element) {
            if (element instanceof org.eclipse.core.resources.IContainer) {
                try {
                    IResource[] members = ((org.eclipse.core.resources.IContainer) element).members();
                    for (int i = 0; i < members.length; i++) {
                        if (!members[i].isDerived()) {
                            return true;
                        }
                    }
                    return false;
                } catch (CoreException e) {
                    return false;
                }
            }
            return false;
        }
    });
    resourcesViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
    resourcesViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IResource(org.eclipse.core.resources.IResource)

Example 19 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project InformationSystem by ObeoNetwork.

the class SpecificWorkspaceResourceDialog method openFileSelection.

public static IFile openFileSelection(Shell parent, String title, String message, IPath suggestedPath, Collection<ViewerFilter> viewerFilters, String newFileExtension) {
    final SpecificWorkspaceResourceDialog dialog = new SpecificWorkspaceResourceDialog(parent, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setNewFileExtension(newFileExtension);
    dialog.setAllowMultiple(false);
    dialog.setTitle(title != null ? title : CommonUIPlugin.INSTANCE.getString("_UI_NewFile_title"));
    dialog.setMessage(message);
    dialog.setShowNewFolderControl(true);
    dialog.setShowFileControl(true);
    dialog.addFilter(dialog.createDefaultViewerFilter(true));
    if (viewerFilters != null) {
        for (ViewerFilter viewerFilter : viewerFilters) {
            dialog.addFilter(viewerFilter);
        }
    }
    if (suggestedPath != null) {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IResource resource = root.findMember(suggestedPath);
        if (resource != null && resource.isAccessible()) {
            if (resource instanceof IContainer) {
                dialog.setInitialSelection(resource);
            } else {
                dialog.setInitialSelection(resource.getParent());
                dialog.setFileText(resource.getName());
            }
        } else {
            if (suggestedPath.segmentCount() > 1) {
                if (resource == null) {
                    resource = root.getFile(suggestedPath);
                }
                if (resource.getProject().isAccessible()) {
                    IContainer container = resource.getParent();
                    for (; !container.isAccessible() && container != resource.getProject(); container = container.getParent()) {
                    // Do nothing
                    }
                    dialog.setInitialSelection(container);
                    suggestedPath = suggestedPath.removeFirstSegments(container.getFullPath().segmentCount());
                    dialog.setFileText(suggestedPath.toString());
                    suggestedPath = null;
                }
            }
            if (suggestedPath != null) {
                String fileText = suggestedPath.isAbsolute() ? suggestedPath.removeFirstSegments(1).toString() : suggestedPath.toString();
                dialog.setFileText(fileText);
            }
        }
    }
    dialog.loadContents();
    return dialog.open() == Window.OK ? dialog.getFile() : null;
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 20 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project webtools.servertools by eclipse.

the class AntBuildFileSelectionEditorSection method createSection.

public void createSection(final Composite parent) {
    super.createSection(parent);
    FormToolkit formToolkit = getFormToolkit(parent.getDisplay());
    Section section = formToolkit.createSection(parent, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR | Section.DESCRIPTION);
    section.setText(GenericServerUIMessages.AntPublisherSectionHeading);
    section.setDescription(GenericServerUIMessages.AntPublisherSectionDescription);
    section.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    Composite composite = formToolkit.createComposite(section);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginHeight = 5;
    layout.marginWidth = 10;
    layout.verticalSpacing = 5;
    layout.horizontalSpacing = 15;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    Label buildFileLabel = formToolkit.createLabel(composite, GenericServerUIMessages.LabelBuildFile);
    buildFileLabel.setForeground(formToolkit.getColors().getColor(IFormColors.TITLE));
    // $NON-NLS-1$
    buildFileText = formToolkit.createText(composite, "");
    String oldValue = // $NON-NLS-1$
    fServer.getServerInstanceProperties().get(GenericServer.PROP_CUSTOM_BUILD_SCRIPT) == null ? // $NON-NLS-1$
    "" : (String) fServer.getServerInstanceProperties().get(GenericServer.PROP_CUSTOM_BUILD_SCRIPT);
    buildFileText.setText(oldValue);
    buildFileText.addListener(SWT.Modify, new Listener() {

        public void handleEvent(Event event) {
            executeUpdateOperation(GenericServer.PROP_CUSTOM_BUILD_SCRIPT, buildFileText.getText());
        }
    });
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    buildFileText.setLayoutData(gridData);
    Button buildFileBtn = formToolkit.createButton(composite, GenericServerUIMessages.ButtonBrowseForBuildFile, SWT.PUSH);
    buildFileBtn.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(parent.getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
            // dialog.setValidator(new FileValidator());
            dialog.setAllowMultiple(false);
            dialog.setTitle(GenericServerUIMessages.AntBuildDialogTitle);
            dialog.setMessage(GenericServerUIMessages.AntBuildDialogDescription);
            dialog.addFilter(new BuildFileFilter());
            dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
            if (dialog.open() == Window.OK) {
                IFile file = (IFile) dialog.getFirstResult();
                // $NON-NLS-1$
                buildFileText.setText(VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression("workspace_loc", file.getFullPath().toString()));
            }
        }
    });
    formToolkit.paintBordersFor(composite);
    section.setClient(composite);
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Listener(org.eclipse.swt.widgets.Listener) PropertyChangeListener(java.beans.PropertyChangeListener) IFile(org.eclipse.core.resources.IFile) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) Label(org.eclipse.swt.widgets.Label) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ServerEditorSection(org.eclipse.wst.server.ui.editor.ServerEditorSection) Section(org.eclipse.ui.forms.widgets.Section) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) PropertyChangeEvent(java.beans.PropertyChangeEvent)

Aggregations

WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)53 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)42 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)32 IResource (org.eclipse.core.resources.IResource)27 IFile (org.eclipse.core.resources.IFile)18 ResourceComparator (org.eclipse.ui.views.navigator.ResourceComparator)18 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)16 IContainer (org.eclipse.core.resources.IContainer)15 IPath (org.eclipse.core.runtime.IPath)14 ArrayList (java.util.ArrayList)12 IStatus (org.eclipse.core.runtime.IStatus)12 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)12 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)11 ISelectionStatusValidator (org.eclipse.ui.dialogs.ISelectionStatusValidator)11 CoreException (org.eclipse.core.runtime.CoreException)10 Status (org.eclipse.core.runtime.Status)10 Composite (org.eclipse.swt.widgets.Composite)10 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)9 GridData (org.eclipse.swt.layout.GridData)9 Button (org.eclipse.swt.widgets.Button)9