Search in sources :

Example 26 with IAdaptable

use of org.eclipse.core.runtime.IAdaptable in project ow by vtst.

the class EasyResourcePropertyPage method getResource.

/**
   * @return  The project resource edited by this page.
   */
protected IResource getResource() {
    IAdaptable element = getElement();
    if (element instanceof IResource)
        return (IResource) element;
    Object resource = element.getAdapter(IResource.class);
    if (resource instanceof IResource)
        return (IResource) resource;
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IResource(org.eclipse.core.resources.IResource)

Example 27 with IAdaptable

use of org.eclipse.core.runtime.IAdaptable in project tdi-studio-se by Talend.

the class JobSettingsView method selectionChanged.

/*
     * (non-Javadoc)
     *
     * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.
     * SelectionChangedEvent )
     */
@Override
public void selectionChanged(SelectionChangedEvent event) {
    ISelection selection = event.getSelection();
    if (selection instanceof StructuredSelection) {
        Object input = ((IStructuredSelection) selection).getFirstElement();
        if (!(input instanceof RepositoryNode)) {
            if (input instanceof IAdaptable) {
                // see ProcessPart.getAdapter()
                IAdaptable adaptable = (IAdaptable) input;
                input = adaptable.getAdapter(RepositoryNode.class);
            }
        }
        if (input instanceof RepositoryNode) {
            RepositoryNode repositoryNode = (RepositoryNode) input;
            Object obj = repositoryNode.getProperties(EProperties.CONTENT_TYPE);
            String type = null;
            if (obj != null) {
                type = obj.toString();
                if (obj instanceof ERepositoryObjectType) {
                    ERepositoryObjectType objType = (ERepositoryObjectType) obj;
                    if (objType == ERepositoryObjectType.PROCESS) {
                        type = getViewNameLable();
                    } else if (objType == ERepositoryObjectType.JOBLET) {
                        type = VIEW_NAME_JOBLET;
                    }
                }
            } else {
                return;
            }
            IRepositoryViewObject repositoryObject = repositoryNode.getObject();
            if (repositoryObject == null) {
                repositoryObject = new EmptyRepositoryObject();
                return;
            }
            String title = repositoryObject.getLabel();
            if (allowVerchange) {
                if (repositoryObject.getVersion() != null) {
                    //$NON-NLS-1$
                    title = repositoryObject.getLabel() + " " + repositoryObject.getVersion();
                }
            }
            Image jobSettingImage = null;
            ERepositoryObjectType repositoryObjectType = repositoryNode.getObjectType();
            if (repositoryObjectType == ERepositoryObjectType.PROCESS_MR || repositoryObjectType == ERepositoryObjectType.PROCESS_STORM) {
                jobSettingImage = getImage(repositoryObject);
            }
            if (jobSettingImage == null) {
                jobSettingImage = getImageFromFramework(repositoryObjectType);
            }
            if (jobSettingImage == null) {
                jobSettingImage = ImageProvider.getImage(repositoryNode.getIcon());
            }
            setElement(repositoryObject, type + SEPARATOR + title, jobSettingImage);
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) EmptyRepositoryObject(org.talend.core.model.repository.EmptyRepositoryObject) EmptyRepositoryObject(org.talend.core.model.repository.EmptyRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IImage(org.talend.commons.ui.runtime.image.IImage) ECoreImage(org.talend.commons.ui.runtime.image.ECoreImage) Image(org.eclipse.swt.graphics.Image)

Example 28 with IAdaptable

use of org.eclipse.core.runtime.IAdaptable in project sling by apache.

the class ServersActionModeFiddlerActionDelegate method initToolbarContributedActions.

private void initToolbarContributedActions() {
    cleanAction = new Action("Clean Publish...", IAction.AS_PUSH_BUTTON) {

        public void run() {
            if (server == null) {
                MessageDialog.openInformation(view.getSite().getShell(), "No server selected", "A server must be selected");
                return;
            }
            int selection = 2;
            if (!doNotAskAgain) {
                MessageDialog dialog = new MessageDialog(view.getSite().getShell(), Messages.defaultDialogTitle, null, Messages.dialogPublishClean, MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Cancel", "OK (do not ask again)", "OK" }, 1) {

                    @Override
                    protected void configureShell(Shell shell) {
                        super.configureShell(shell);
                        setShellStyle(getShellStyle() | SWT.SHEET);
                    }
                };
                selection = dialog.open();
            }
            if (selection != 0) {
                if (selection == 1) {
                    doNotAskAgain = true;
                }
                IAdaptable info = new IAdaptable() {

                    public Object getAdapter(Class adapter) {
                        if (Shell.class.equals(adapter))
                            return view.getSite().getShell();
                        if (String.class.equals(adapter))
                            return "user";
                        return null;
                    }
                };
                server.publish(IServer.PUBLISH_CLEAN, modules, info, null);
            }
        }
    };
    cleanAction.setText("Clean Publish...");
    cleanAction.setToolTipText("Clean and Publish...");
    ImageDescriptor cleanAndPublishImageDesc = new DecorationOverlayIcon(ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_PUBLISH).createImage(), ImageDescriptor.createFromFile(SharedImages.class, "refresh.gif"), IDecoration.BOTTOM_RIGHT);
    cleanAction.setImageDescriptor(cleanAndPublishImageDesc);
    cleanAction.setId("org.apache.sling.ide.eclipse.ui.actions.CleanPublishAction");
    publishAction = new Action("Publish", IAction.AS_PUSH_BUTTON) {

        public void run() {
            if (server == null) {
                MessageDialog.openInformation(view.getSite().getShell(), "No server selected", "A server must be selected");
                return;
            }
            IAdaptable info = new IAdaptable() {

                public Object getAdapter(Class adapter) {
                    if (Shell.class.equals(adapter))
                        return view.getSite().getShell();
                    if (String.class.equals(adapter))
                        return "user";
                    return null;
                }
            };
            server.publish(IServer.PUBLISH_INCREMENTAL, modules, info, null);
        }
    };
    publishAction.setText("Publish");
    publishAction.setToolTipText("Publish");
    publishAction.setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_PUBLISH));
    publishAction.setId("org.apache.sling.ide.eclipse.ui.actions.PublishAction");
    cleanAction.setEnabled(false);
    publishAction.setEnabled(false);
    cleanActionContributionItem = new ActionContributionItem(cleanAction);
    publishActionContributionItem = new ActionContributionItem(publishAction);
    appendedToolbarActionContributionItems.add(publishActionContributionItem);
    appendedToolbarActionContributionItems.add(cleanActionContributionItem);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) DecorationOverlayIcon(org.eclipse.jface.viewers.DecorationOverlayIcon) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) Shell(org.eclipse.swt.widgets.Shell) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 29 with IAdaptable

use of org.eclipse.core.runtime.IAdaptable in project bndtools by bndtools.

the class RepositoriesView method convertSelectionToFiles.

private static File[] convertSelectionToFiles(ISelection selection) {
    if (!(selection instanceof IStructuredSelection))
        return new File[0];
    IStructuredSelection structSel = (IStructuredSelection) selection;
    List<File> files = new ArrayList<File>(structSel.size());
    for (Iterator<?> iter = structSel.iterator(); iter.hasNext(); ) {
        Object element = iter.next();
        if (element instanceof IFile)
            files.add(((IFile) element).getLocation().toFile());
        else if (element instanceof IAdaptable) {
            IAdaptable adaptable = (IAdaptable) element;
            IFile ifile = (IFile) adaptable.getAdapter(IFile.class);
            if (ifile != null) {
                files.add(ifile.getLocation().toFile());
            } else {
                File file = (File) adaptable.getAdapter(File.class);
                if (file != null) {
                    files.add(file);
                }
            }
        }
    }
    return files.toArray(new File[0]);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IFile(org.eclipse.core.resources.IFile) File(java.io.File) JarFile(java.util.jar.JarFile)

Example 30 with IAdaptable

use of org.eclipse.core.runtime.IAdaptable in project bndtools by bndtools.

the class SelectionUtils method getSelectionMembers.

public static <T> Collection<T> getSelectionMembers(ISelection selection, Class<T> clazz, Predicate<? super T> filter) throws Exception {
    if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
        return Collections.emptyList();
    }
    IStructuredSelection structSel = (IStructuredSelection) selection;
    List<T> result = new ArrayList<T>(structSel.size());
    Iterator<?> iter = structSel.iterator();
    while (iter.hasNext()) {
        Object element = iter.next();
        if (clazz.isInstance(element)) {
            @SuppressWarnings("unchecked") T casted = (T) element;
            if (filter == null || filter.test(casted)) {
                result.add(casted);
            }
        } else if (element instanceof IAdaptable) {
            @SuppressWarnings("unchecked") T adapted = (T) ((IAdaptable) element).getAdapter(clazz);
            if (adapted != null) {
                if (filter == null || filter.test(adapted)) {
                    result.add(adapted);
                }
            }
        }
    }
    return result;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

IAdaptable (org.eclipse.core.runtime.IAdaptable)33 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 IProject (org.eclipse.core.resources.IProject)11 ArrayList (java.util.ArrayList)9 IResource (org.eclipse.core.resources.IResource)8 IFile (org.eclipse.core.resources.IFile)7 CoreException (org.eclipse.core.runtime.CoreException)5 Iterator (java.util.Iterator)4 List (java.util.List)4 IOException (java.io.IOException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 File (java.io.File)2 LinkedList (java.util.LinkedList)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 EditPart (org.eclipse.gef.EditPart)2 AbstractTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand)2 Diagram (org.eclipse.gmf.runtime.notation.Diagram)2