Search in sources :

Example 1 with IImageDescriptor

use of org.python.pydev.shared_core.image.IImageDescriptor in project Pydev by fabioz.

the class ImageCache method getDescriptor.

/**
 * like get, but returns ImageDescription instead of image
 */
@Override
public IImageDescriptor getDescriptor(String key) {
    ImageDescriptor desc;
    synchronized (descriptorLock) {
        desc = descriptorHash.get(key);
        if (desc == null) {
            URL url;
            try {
                url = new URL(baseURL, key);
                desc = ImageDescriptor.createFromURL(url);
            } catch (MalformedURLException e) {
                Log.log("ERROR: Missing image: " + key);
                desc = ImageDescriptor.getMissingImageDescriptor();
            }
            descriptorHash.put(key, desc);
        }
    }
    final ImageDescriptor computed = desc;
    return new IImageDescriptor() {

        @Override
        public Object getImageDescriptor() {
            return computed;
        }
    };
}
Also used : MalformedURLException(java.net.MalformedURLException) IImageDescriptor(org.python.pydev.shared_core.image.IImageDescriptor) IImageDescriptor(org.python.pydev.shared_core.image.IImageDescriptor) CompositeImageDescriptor(org.eclipse.jface.resource.CompositeImageDescriptor) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) URL(java.net.URL)

Example 2 with IImageDescriptor

use of org.python.pydev.shared_core.image.IImageDescriptor in project Pydev by fabioz.

the class SyncSystemModulesManager method updateStructures.

/**
 * Here we'll update the tree structure to be shown to the user with the changes (root).
 * The managerToNameToInfo structure has the information on the interpreter manager and related
 * interpreter infos for which the changes should be checked.
 */
public void updateStructures(IProgressMonitor monitor, final DataAndImageTreeNode root, ManagerInfoToUpdate managerToNameToInfo, CreateInterpreterInfoCallback callback) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    IImageCache imageCache = SharedCorePlugin.getImageCache();
    if (imageCache == null) {
        imageCache = new IImageCache() {

            @Override
            public IImageHandle getStringDecorated(String key, String stringToAddToDecoration) {
                return null;
            }

            @Override
            public IImageHandle getImageDecorated(String key, String decoration, int decorationLocation, String secondDecoration, int secondDecorationLocation) {
                return null;
            }

            @Override
            public IImageHandle getImageDecorated(String key, String decoration, int decorationLocation) {
                return null;
            }

            @Override
            public IImageHandle getImageDecorated(String key, String decoration) {
                return null;
            }

            @Override
            public IImageDescriptor getDescriptor(String projectIcon) {
                return null;
            }

            @Override
            public IImageHandle get(String key) {
                return null;
            }
        };
    }
    for (Tuple<IInterpreterManager, IInterpreterInfo> infos : managerToNameToInfo.getManagerAndInfos()) {
        IInterpreterManager manager = infos.o1;
        IInterpreterInfo internalInfo = infos.o2;
        String executable = internalInfo.getExecutableOrJar();
        IInterpreterInfo newInterpreterInfo = callback.createInterpreterInfo(manager, executable, monitor);
        if (newInterpreterInfo == null) {
            continue;
        }
        DefaultPathsForInterpreterInfo defaultPaths = new DefaultPathsForInterpreterInfo();
        OrderedSet<String> newEntries = new OrderedSet<String>(newInterpreterInfo.getPythonPath());
        newEntries.removeAll(internalInfo.getPythonPath());
        // Iterate over the new entries to suggest what should be added (we already have only what's not there).
        for (Iterator<String> it = newEntries.iterator(); it.hasNext(); ) {
            String entryInPythonpath = it.next();
            if (!defaultPaths.selectByDefault(entryInPythonpath) || !defaultPaths.exists(entryInPythonpath)) {
                // Don't suggest the addition of entries in the workspace or entries which do not exist.
                it.remove();
            }
        }
        // Iterate over existing entries to suggest what should be removed.
        OrderedSet<String> removedEntries = new OrderedSet<String>();
        List<String> pythonPath = internalInfo.getPythonPath();
        for (String string : pythonPath) {
            if (!new File(string).exists()) {
                // Only suggest a removal if it was removed from the filesystem.
                removedEntries.add(string);
            }
        }
        if (newEntries.size() > 0 || removedEntries.size() > 0) {
            DataAndImageTreeNode<IInterpreterInfo> interpreterNode = new DataAndImageTreeNode<IInterpreterInfo>(root, internalInfo, imageCache.get(UIConstants.PY_INTERPRETER_ICON));
            for (String s : newEntries) {
                new DataAndImageTreeNode(interpreterNode, new PythonpathChange(s, true), imageCache.get(UIConstants.LIB_SYSTEM));
            }
            for (String s : removedEntries) {
                new DataAndImageTreeNode(interpreterNode, new PythonpathChange(s, false), imageCache.get(UIConstants.REMOVE_LIB_SYSTEM));
            }
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OrderedSet(org.python.pydev.shared_core.structure.OrderedSet) IImageCache(org.python.pydev.shared_core.image.IImageCache) IImageDescriptor(org.python.pydev.shared_core.image.IImageDescriptor) DefaultPathsForInterpreterInfo(org.python.pydev.ast.interpreter_managers.DefaultPathsForInterpreterInfo) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) IInterpreterManager(org.python.pydev.core.IInterpreterManager) IImageHandle(org.python.pydev.shared_core.image.IImageHandle) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) File(java.io.File)

Example 3 with IImageDescriptor

use of org.python.pydev.shared_core.image.IImageDescriptor in project Pydev by fabioz.

the class PyEdit method updateForceTabsMessage.

public void updateForceTabsMessage() {
    boolean forceTabs = getIndentPrefs().getForceTabs();
    IImageCache imageCache = SharedUiPlugin.getImageCache();
    IImageDescriptor desc;
    if (forceTabs) {
        desc = imageCache.getDescriptor(UIConstants.FORCE_TABS_ACTIVE);
    } else {
        desc = imageCache.getDescriptor(UIConstants.FORCE_TABS_INACTIVE);
    }
    IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
    if (statusLine != null) {
        statusLine.setMessage(false, forceTabs ? "Forcing tabs" : "Not forcing tabs.", ImageCache.asImageDescriptor(desc).createImage());
    }
}
Also used : IImageCache(org.python.pydev.shared_core.image.IImageCache) IImageDescriptor(org.python.pydev.shared_core.image.IImageDescriptor) IEditorStatusLine(org.eclipse.ui.texteditor.IEditorStatusLine)

Aggregations

IImageDescriptor (org.python.pydev.shared_core.image.IImageDescriptor)3 IImageCache (org.python.pydev.shared_core.image.IImageCache)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 CompositeImageDescriptor (org.eclipse.jface.resource.CompositeImageDescriptor)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 IEditorStatusLine (org.eclipse.ui.texteditor.IEditorStatusLine)1 DefaultPathsForInterpreterInfo (org.python.pydev.ast.interpreter_managers.DefaultPathsForInterpreterInfo)1 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)1 IInterpreterManager (org.python.pydev.core.IInterpreterManager)1 IImageHandle (org.python.pydev.shared_core.image.IImageHandle)1 DataAndImageTreeNode (org.python.pydev.shared_core.structure.DataAndImageTreeNode)1 OrderedSet (org.python.pydev.shared_core.structure.OrderedSet)1