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();
}
}
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;
}
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;
}
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();
}
}
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();
}
}
Aggregations