@SuppressWarnings({"unchecked"}) private static <T extends BaseInjection> List<T> readExternal( Element element, Factory<T> factory) { final List<T> injections = new ArrayList<T>(); if (element != null) { final List<Element> list = element.getChildren(ENTRY_NAME); for (Element entry : list) { final T o = factory.create(); o.loadState(entry); injections.add(o); } } return injections; }
public final <T> T createStableValue(final Factory<T> provider, final Condition<T> validator) { final T initial = provider.create(); assert initial != null; final StableInvocationHandler handler = new StableInvocationHandler<T>(initial, provider, validator); final Set<Class> intf = new HashSet<Class>(); ContainerUtil.addAll(intf, initial.getClass().getInterfaces()); intf.add(StableElement.class); //noinspection unchecked return (T) AdvancedProxy.createProxy( initial.getClass().getSuperclass(), intf.toArray(new Class[intf.size()]), handler); }
private void searchUsages() { UsageSearcher usageSearcher = mySearcherFactory.create(); usageSearcher.generate( new Processor<Usage>() { public boolean process(final Usage usage) { checkSearchCanceled(); boolean incrementCounter = true; final int i = myUsageCountWithoutDefinition.get(); // Handle self reference (under definition we are invoked on) just to skip it if (mySearchFor.length == 1 && usage instanceof PsiElementUsage && mySearchFor[0] instanceof PsiElementUsageTarget) { final PsiElement element = ((PsiElementUsage) usage).getElement(); // TODO: self usage might be configurable if (element != null && element.getParent() == ((PsiElementUsageTarget) mySearchFor[0]).getElement()) { incrementCounter = false; } } int usageCount = incrementCounter ? myUsageCountWithoutDefinition.incrementAndGet() : i; if (usageCount == 1 && !myProcessPresentation.isShowPanelIfOnlyOneUsage()) { myFirstUsage.compareAndSet(null, usage); } UsageViewImpl usageView = getUsageView(); if (usageView != null) { usageView.appendUsageLater(usage); } final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); return indicator == null || !indicator.isCanceled(); } }); if (getUsageView() != null) { ApplicationManager.getApplication() .invokeLater( new Runnable() { public void run() { showToolWindow(true); } }, myProject.getDisposed()); } }
@Override @NotNull protected JComponent createCustomComponent() { new MnemonicHelper().register(getComponent()); myComponent = myComponentFactory.create(); DomUIFactory.getDomUIFactory().setupErrorOutdatingUserActivityWatcher(this, getDomElement()); DomManager.getDomManager(getProject()) .addDomEventListener( new DomEventListener() { @Override public void eventOccured(DomEvent event) { checkIsValid(); } }, this); Disposer.register(this, myComponent); return myComponent.getComponent(); }
public void searchAndShowUsages( @NotNull UsageTarget[] searchFor, @NotNull Factory<UsageSearcher> searcherFactory, @NotNull FindUsagesProcessPresentation processPresentation, @NotNull UsageViewPresentation presentation, UsageViewStateListener listener) { final AtomicReference<UsageViewImpl> usageView = new AtomicReference<UsageViewImpl>(); final SearchForUsagesRunnable runnable = new SearchForUsagesRunnable( usageView, presentation, searchFor, searcherFactory, processPresentation, listener); final Factory<ProgressIndicator> progressIndicatorFactory = processPresentation.getProgressIndicatorFactory(); final ProgressIndicator progressIndicator = progressIndicatorFactory != null ? progressIndicatorFactory.create() : null; ApplicationManager.getApplication() .executeOnPooledThread( new Runnable() { public void run() { try { ProgressManager.getInstance() .runProcess( new Runnable() { public void run() { runnable.searchUsages(); } }, progressIndicator); } catch (ProcessCanceledException e) { // ignore } ApplicationManager.getApplication() .invokeLater( new Runnable() { public void run() { runnable.endSearchForUsages(); } }, ModalityState.NON_MODAL); } }); }