Search in sources :

Example 11 with IWorkbenchAdapter

use of org.eclipse.ui.model.IWorkbenchAdapter in project sling by apache.

the class ConvertToContentProjectHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IProject project = (IProject) ((IStructuredSelection) selection).getFirstElement();
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getDisplay().getActiveShell(), new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
        dialog.setMessage("Select content sync root location (containing the jcr root)");
        dialog.setTitle("Content Sync Root");
        IContainer initialContainer = ProjectHelper.getInferredContentProjectContentRoot(project);
        if (initialContainer != null) {
            dialog.setInitialElementSelections(Arrays.asList(initialContainer));
        }
        dialog.addFilter(new ViewerFilter() {

            @Override
            public boolean select(Viewer viewer, Object parentElement, Object element) {
                if (element instanceof IProject) {
                    return ((IProject) element).equals(project);
                }
                // display folders only
                return element instanceof IContainer;
            }
        });
        dialog.setInput(new IWorkbenchAdapter() {

            @Override
            public Object getParent(Object o) {
                return null;
            }

            @Override
            public String getLabel(Object o) {
                return null;
            }

            @Override
            public ImageDescriptor getImageDescriptor(Object object) {
                return null;
            }

            @Override
            public Object[] getChildren(Object o) {
                return new Object[] { project };
            }
        });
        // this is the root element
        dialog.setAllowMultiple(false);
        dialog.setValidator(new ISelectionStatusValidator() {

            @Override
            public IStatus validate(Object[] selection) {
                if (selection.length > 0) {
                    final Object item = selection[0];
                    if (item instanceof IContainer) {
                        IContainer selectedContainer = (IContainer) item;
                        String errorMsg = ProjectHelper.validateContentPackageStructure(selectedContainer);
                        if (errorMsg != null) {
                            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMsg);
                        } else {
                            return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
                        }
                    }
                }
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "");
            }
        });
        if (dialog.open() == ContainerSelectionDialog.OK) {
            Object[] result = dialog.getResult();
            if (result != null && result.length > 0) {
                final IContainer container = (IContainer) result[0];
                IRunnableWithProgress r = new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            IResource jcrRoot = container.findMember("jcr_root");
                            if (jcrRoot == null || !(jcrRoot instanceof IFolder)) {
                                MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", "jcr_root not found under " + container + " (or not a Folder)");
                                return;
                            }
                            ConfigurationHelper.convertToContentPackageProject(project, monitor, jcrRoot.getProjectRelativePath());
                        } catch (CoreException e) {
                            Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
                            MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
                        }
                    }
                };
                try {
                    PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
                } catch (Exception e) {
                    Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
                    MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
                }
            }
        }
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IStatus(org.eclipse.core.runtime.IStatus) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) BaseWorkbenchContentProvider(org.eclipse.ui.model.BaseWorkbenchContentProvider) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) ISelection(org.eclipse.jface.viewers.ISelection) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with IWorkbenchAdapter

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

the class UITestHelper method getPropertyDialog.

public static PropertyDialog getPropertyDialog(String id, IAdaptable element) {
    PropertyDialogWrapper dialog = null;
    PropertyPageManager manager = new PropertyPageManager();
    String title = "";
    String name = "";
    // load pages for the selection
    // fill the manager with contributions from the matching contributors
    PropertyPageContributorManager.getManager().contribute(manager, element);
    IWorkbenchAdapter adapter = element.getAdapter(IWorkbenchAdapter.class);
    if (adapter != null) {
        name = adapter.getLabel(element);
    }
    // testing if there are pages in the manager
    Iterator pages = manager.getElements(PreferenceManager.PRE_ORDER).iterator();
    if (!pages.hasNext())
        return null;
    title = "Title: " + name;
    dialog = new PropertyDialogWrapper(getShell(), manager, new StructuredSelection(element));
    dialog.create();
    dialog.getShell().setText(title);
    for (Iterator iterator = manager.getElements(PreferenceManager.PRE_ORDER).iterator(); iterator.hasNext(); ) {
        IPreferenceNode node = (IPreferenceNode) iterator.next();
        if (node.getId().equals(id)) {
            dialog.showPage(node);
            break;
        }
    }
    return dialog;
}
Also used : IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) Iterator(java.util.Iterator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) PropertyPageManager(org.eclipse.ui.internal.dialogs.PropertyPageManager) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode)

Example 13 with IWorkbenchAdapter

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

the class ServerLabelProvider method getText.

/*
	 * @see ILabelProvider#getText(Object)
	 */
public String getText(Object element) {
    if (element == null)
        return "";
    if (element instanceof IRuntime) {
        IRuntime runtime = (IRuntime) element;
        return decorate(getString((runtime).getName()), runtime);
    } else if (element instanceof IServer) {
        IServer server = (IServer) element;
        return decorate(getString((server).getName()), server);
    } else if (element instanceof IRuntimeType) {
        IRuntimeType rt = (IRuntimeType) element;
        return decorate(rt.getName(), rt);
    } else if (element instanceof IServerType) {
        IServerType st = (IServerType) element;
        return decorate(st.getName(), st);
    } else if (element instanceof IClient) {
        IClient client = (IClient) element;
        return decorate(client.getName(), client);
    } else if (element instanceof IModule) {
        IModule module = (IModule) element;
        return decorate(module.getName(), module);
    } else if (element instanceof IModule[]) {
        IModule[] modules = (IModule[]) element;
        IModule module = modules[modules.length - 1];
        return decorate(module.getName(), modules);
    } else if (element instanceof ModuleServer) {
        ModuleServer ms = (ModuleServer) element;
        return decorate(ms.getModuleDisplayName(), ms);
    } else if (element instanceof IWorkbenchAdapter) {
        return ((IWorkbenchAdapter) element).getLabel(null);
    }
    return "";
}
Also used : ModuleServer(org.eclipse.wst.server.ui.internal.view.servers.ModuleServer) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) IClient(org.eclipse.wst.server.core.internal.IClient)

Example 14 with IWorkbenchAdapter

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

the class UITestHelper method getPropertyDialog.

public static PropertyDialog getPropertyDialog(String id, IAdaptable element) {
    PropertyDialogWrapper dialog = null;
    PropertyPageManager manager = new PropertyPageManager();
    String title = "";
    String name = "";
    // load pages for the selection
    // fill the manager with contributions from the matching contributors
    PropertyPageContributorManager.getManager().contribute(manager, element);
    IWorkbenchAdapter adapter = (IWorkbenchAdapter) element.getAdapter(IWorkbenchAdapter.class);
    if (adapter != null) {
        name = adapter.getLabel(element);
    }
    // testing if there are pages in the manager
    Iterator pages = manager.getElements(PreferenceManager.PRE_ORDER).iterator();
    if (!pages.hasNext())
        return null;
    title = "Title: " + name;
    dialog = new PropertyDialogWrapper(getShell(), manager, new StructuredSelection(element));
    dialog.create();
    dialog.getShell().setText(title);
    for (Iterator iterator = manager.getElements(PreferenceManager.PRE_ORDER).iterator(); iterator.hasNext(); ) {
        IPreferenceNode node = (IPreferenceNode) iterator.next();
        if (node.getId().equals(id)) {
            dialog.showPage(node);
            break;
        }
    }
    return dialog;
}
Also used : IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) Iterator(java.util.Iterator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) PropertyPageManager(org.eclipse.ui.internal.dialogs.PropertyPageManager) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode)

Example 15 with IWorkbenchAdapter

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

the class UITestHelper method getPropertyDialog.

public static PropertyDialog getPropertyDialog(String id, IAdaptable element) {
    PropertyDialogWrapper dialog = null;
    PropertyPageManager manager = new PropertyPageManager();
    String title = "";
    String name = "";
    // load pages for the selection
    // fill the manager with contributions from the matching contributors
    PropertyPageContributorManager.getManager().contribute(manager, element);
    IWorkbenchAdapter adapter = (IWorkbenchAdapter) element.getAdapter(IWorkbenchAdapter.class);
    if (adapter != null) {
        name = adapter.getLabel(element);
    }
    // testing if there are pages in the manager
    Iterator pages = manager.getElements(PreferenceManager.PRE_ORDER).iterator();
    if (!pages.hasNext())
        return null;
    title = "Title: " + name;
    dialog = new PropertyDialogWrapper(getShell(), manager, new StructuredSelection(element));
    dialog.create();
    dialog.getShell().setText(title);
    for (Iterator iterator = manager.getElements(PreferenceManager.PRE_ORDER).iterator(); iterator.hasNext(); ) {
        IPreferenceNode node = (IPreferenceNode) iterator.next();
        if (node.getId().equals(id)) {
            dialog.showPage(node);
            break;
        }
    }
    return dialog;
}
Also used : IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) Iterator(java.util.Iterator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) PropertyPageManager(org.eclipse.ui.internal.dialogs.PropertyPageManager) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode)

Aggregations

IWorkbenchAdapter (org.eclipse.ui.model.IWorkbenchAdapter)21 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)6 Image (org.eclipse.swt.graphics.Image)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 Iterator (java.util.Iterator)3 IResource (org.eclipse.core.resources.IResource)3 IPreferenceNode (org.eclipse.jface.preference.IPreferenceNode)3 PropertyPageManager (org.eclipse.ui.internal.dialogs.PropertyPageManager)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IContainer (org.eclipse.core.resources.IContainer)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1