Search in sources :

Example 26 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.

the class ExternalSystemTestCase method getModule.

protected Module getModule(final String name) {
    AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        Module m = ModuleManager.getInstance(myProject).findModuleByName(name);
        assertNotNull("Module " + name + " not found", m);
        return m;
    } finally {
        accessToken.finish();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Module(com.intellij.openapi.module.Module)

Example 27 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.

the class LookupCellRenderer method getListCellRendererComponent.

@Override
public Component getListCellRendererComponent(final JList list, Object value, int index, boolean isSelected, boolean hasFocus) {
    boolean nonFocusedSelection = isSelected && myLookup.getFocusDegree() == LookupImpl.FocusDegree.SEMI_FOCUSED;
    if (!myLookup.isFocused()) {
        isSelected = false;
    }
    myIsSelected = isSelected;
    final LookupElement item = (LookupElement) value;
    final Color foreground = getForegroundColor(isSelected);
    final Color background = nonFocusedSelection ? SELECTED_NON_FOCUSED_BACKGROUND_COLOR : isSelected ? SELECTED_BACKGROUND_COLOR : BACKGROUND_COLOR;
    int allowedWidth = list.getWidth() - calcSpacing(myNameComponent, myEmptyIcon) - calcSpacing(myTailComponent, null) - calcSpacing(myTypeLabel, null);
    FontMetrics normalMetrics = getRealFontMetrics(item, false);
    FontMetrics boldMetrics = getRealFontMetrics(item, true);
    final LookupElementPresentation presentation = new RealLookupElementPresentation(isSelected ? getMaxWidth() : allowedWidth, normalMetrics, boldMetrics, myLookup);
    AccessToken token = ReadAction.start();
    try {
        if (item.isValid()) {
            try {
                item.renderElement(presentation);
            } catch (ProcessCanceledException e) {
                LOG.info(e);
                presentation.setItemTextForeground(JBColor.RED);
                presentation.setItemText("Error occurred, see the log in Help | Show Log");
            } catch (Exception | Error e) {
                LOG.error(e);
            }
        } else {
            presentation.setItemTextForeground(JBColor.RED);
            presentation.setItemText("Invalid");
        }
    } finally {
        token.finish();
    }
    myNameComponent.clear();
    myNameComponent.setBackground(background);
    allowedWidth -= setItemTextLabel(item, new JBColor(isSelected ? SELECTED_FOREGROUND_COLOR : presentation.getItemTextForeground(), presentation.getItemTextForeground()), isSelected, presentation, allowedWidth);
    Font font = myLookup.getCustomFont(item, false);
    if (font == null) {
        font = myNormalFont;
    }
    myTailComponent.setFont(font);
    myTypeLabel.setFont(font);
    myNameComponent.setIcon(augmentIcon(myLookup.getEditor(), presentation.getIcon(), myEmptyIcon));
    myTypeLabel.clear();
    if (allowedWidth > 0) {
        allowedWidth -= setTypeTextLabel(item, background, foreground, presentation, isSelected ? getMaxWidth() : allowedWidth, isSelected, nonFocusedSelection, normalMetrics);
    }
    myTailComponent.clear();
    myTailComponent.setBackground(background);
    if (isSelected || allowedWidth >= 0) {
        setTailTextLabel(isSelected, presentation, foreground, isSelected ? getMaxWidth() : allowedWidth, nonFocusedSelection, normalMetrics);
    }
    if (mySelected.containsKey(index)) {
        if (!isSelected && mySelected.get(index)) {
            myPanel.setUpdateExtender(true);
        }
    }
    mySelected.put(index, isSelected);
    final double w = myNameComponent.getPreferredSize().getWidth() + myTailComponent.getPreferredSize().getWidth() + myTypeLabel.getPreferredSize().getWidth();
    boolean useBoxLayout = isSelected && w > list.getWidth() && ((JBList) list).getExpandableItemsHandler().isEnabled();
    if (useBoxLayout != myPanel.getLayout() instanceof BoxLayout) {
        myPanel.removeAll();
        if (useBoxLayout) {
            myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.X_AXIS));
            myPanel.add(myNameComponent);
            myPanel.add(myTailComponent);
            myPanel.add(myTypeLabel);
        } else {
            myPanel.setLayout(new BorderLayout());
            myPanel.add(myNameComponent, BorderLayout.WEST);
            myPanel.add(myTailComponent, BorderLayout.CENTER);
            myPanel.add(myTypeLabel, BorderLayout.EAST);
        }
    }
    AccessibleContextUtil.setCombinedName(myPanel, myNameComponent, "", myTailComponent, " - ", myTypeLabel);
    AccessibleContextUtil.setCombinedDescription(myPanel, myNameComponent, "", myTailComponent, " - ", myTypeLabel);
    return myPanel;
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) LookupValueWithUIHint(com.intellij.codeInsight.lookup.LookupValueWithUIHint) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) RealLookupElementPresentation(com.intellij.codeInsight.lookup.RealLookupElementPresentation) LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) AccessToken(com.intellij.openapi.application.AccessToken) JBList(com.intellij.ui.components.JBList) RealLookupElementPresentation(com.intellij.codeInsight.lookup.RealLookupElementPresentation) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 28 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.

the class ClasspathStorage method getSerializedState.

@Nullable
@Override
public Element getSerializedState(@NotNull Boolean storageData, Object component, @NotNull String componentName, boolean archive) {
    if (storageData) {
        return null;
    }
    Element element = new Element("component");
    ModifiableRootModel model = null;
    AccessToken token = ReadAction.start();
    try {
        model = ((ModuleRootManagerImpl) component).getModifiableModel();
        // IDEA-137969 Eclipse integration: external remove of classpathentry is not synchronized
        model.clear();
        try {
            myConverter.readClasspath(model);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        ((RootModelImpl) model).writeExternal(element);
    } catch (WriteExternalException e) {
        LOG.error(e);
    } finally {
        try {
            token.finish();
        } finally {
            if (model != null) {
                model.dispose();
            }
        }
    }
    if (myPathMacroSubstitutor != null) {
        myPathMacroSubstitutor.expandPaths(element);
        myPathMacroSubstitutor.addUnknownMacros("NewModuleRootManager", PathMacrosCollector.getMacroNames(element));
    }
    getStorageDataRef().set(true);
    return element;
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) RootModelImpl(com.intellij.openapi.roots.impl.RootModelImpl) AccessToken(com.intellij.openapi.application.AccessToken) Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with AccessToken

use of com.intellij.openapi.application.AccessToken in project kotlin by JetBrains.

the class ExternalSystemTestCase method getModule.

protected Module getModule(String name) {
    AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        Module m = ModuleManager.getInstance(myProject).findModuleByName(name);
        assertNotNull("Module " + name + " not found", m);
        return m;
    } finally {
        accessToken.finish();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Module(com.intellij.openapi.module.Module)

Example 30 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.

the class OsgiRunState method getSelectedBundles.

/**
   * Here we got the magic. All libs are turned into bundles sorted and returned.
   */
private List<SelectedBundle> getSelectedBundles() throws ExecutionException {
    final Ref<List<SelectedBundle>> result = Ref.create();
    final Ref<ExecutionException> error = Ref.create();
    ProgressManager.getInstance().run(new Task.Modal(myRunConfiguration.getProject(), "Preparing bundles...", false) {

        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            progressIndicator.setIndeterminate(false);
            AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
            try {
                Set<SelectedBundle> selectedBundles = new HashSet<>();
                // the bundles are module names, by now we try to find jar files in the output directory which we can then install
                ModuleManager moduleManager = ModuleManager.getInstance(myRunConfiguration.getProject());
                BundleCompiler bundleCompiler = new BundleCompiler(progressIndicator);
                int bundleCount = myRunConfiguration.getBundlesToDeploy().size();
                for (int i = 0; i < bundleCount; i++) {
                    progressIndicator.setFraction((double) i / bundleCount);
                    SelectedBundle selectedBundle = myRunConfiguration.getBundlesToDeploy().get(i);
                    if (selectedBundle.isModule()) {
                        // use the output jar name if it is a module
                        String name = selectedBundle.getName();
                        Module module = moduleManager.findModuleByName(name);
                        if (module == null) {
                            throw new CantRunException("Module '" + name + "' no longer exists. Please check your run configuration.");
                        }
                        OsmorcFacet facet = OsmorcFacet.getInstance(module);
                        if (facet == null) {
                            throw new CantRunException("Module '" + name + "' has no OSGi facet. Please check your run configuration.");
                        }
                        selectedBundle.setBundlePath(facet.getConfiguration().getJarFileLocation());
                        selectedBundles.add(selectedBundle);
                        // add all the library dependencies of the bundle
                        List<String> paths = bundleCompiler.bundlifyLibraries(module);
                        for (String path : paths) {
                            selectedBundles.add(new SelectedBundle(SelectedBundle.BundleType.PlainLibrary, "Dependency", path));
                        }
                    } else {
                        if (selectedBundles.contains(selectedBundle)) {
                            // if the user selected a dependency as runnable library, we need to replace the dependency with
                            // the runnable library part
                            selectedBundles.remove(selectedBundle);
                        }
                        selectedBundles.add(selectedBundle);
                    }
                }
                // filter out bundles which have the same symbolic name
                Map<String, SelectedBundle> filteredBundles = new HashMap<>();
                for (SelectedBundle selectedBundle : selectedBundles) {
                    String path = selectedBundle.getBundlePath();
                    if (path != null) {
                        String name = CachingBundleInfoProvider.getBundleSymbolicName(path);
                        String version = CachingBundleInfoProvider.getBundleVersion(path);
                        String key = name + version;
                        if (!filteredBundles.containsKey(key)) {
                            filteredBundles.put(key, selectedBundle);
                        }
                    }
                }
                List<SelectedBundle> sortedBundles = ContainerUtil.newArrayList(filteredBundles.values());
                Collections.sort(sortedBundles, START_LEVEL_COMPARATOR);
                result.set(sortedBundles);
            } catch (CantRunException e) {
                error.set(e);
            } catch (OsgiBuildException e) {
                LOG.warn(e);
                error.set(new CantRunException(e.getMessage()));
            } catch (Throwable t) {
                LOG.error(t);
                error.set(new CantRunException("Internal error: " + t.getMessage()));
            } finally {
                token.finish();
            }
        }
    });
    if (!result.isNull()) {
        return result.get();
    } else {
        throw error.get();
    }
}
Also used : Task(com.intellij.openapi.progress.Task) SelectedBundle(org.osmorc.run.ui.SelectedBundle) ModuleManager(com.intellij.openapi.module.ModuleManager) CantRunException(com.intellij.execution.CantRunException) OsmorcFacet(org.osmorc.facet.OsmorcFacet) BundleCompiler(org.osmorc.make.BundleCompiler) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AccessToken(com.intellij.openapi.application.AccessToken) OsgiBuildException(org.jetbrains.osgi.jps.build.OsgiBuildException) ExecutionException(com.intellij.execution.ExecutionException) Module(com.intellij.openapi.module.Module)

Aggregations

AccessToken (com.intellij.openapi.application.AccessToken)97 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 Nullable (org.jetbrains.annotations.Nullable)15 Module (com.intellij.openapi.module.Module)13 Project (com.intellij.openapi.project.Project)12 Document (com.intellij.openapi.editor.Document)10 GitRepository (git4idea.repo.GitRepository)9 ArrayList (java.util.ArrayList)9 PsiElement (com.intellij.psi.PsiElement)7 NotNull (org.jetbrains.annotations.NotNull)6 File (java.io.File)5 IOException (java.io.IOException)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)4 PsiFile (com.intellij.psi.PsiFile)4 List (java.util.List)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 ReadAction (com.intellij.openapi.application.ReadAction)3 CompileContext (com.intellij.openapi.compiler.CompileContext)3 CompileTask (com.intellij.openapi.compiler.CompileTask)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3