@Override public void paint(Graphics g) { final Rectangle bounds = g.getClipBounds(); if (mySplitter instanceof OnePixelSplitter) { final Producer<Insets> blindZone = ((OnePixelSplitter)mySplitter).getBlindZone(); if (blindZone != null) { final Insets insets = blindZone.produce(); if (insets != null) { bounds.x += insets.left; bounds.y += insets.top; bounds.width -= insets.left + insets.right; bounds.height -= insets.top + insets.bottom; g.setColor(getBackground()); g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); return; } } } super.paint(g); }
@Nullable @Override public DataNode<ProjectData> resolveProjectInfo(@NotNull final ExternalSystemTaskId id, @NotNull final String projectPath, final boolean isPreviewMode, final S settings) throws ExternalSystemException, IllegalArgumentException, IllegalStateException { return execute(id, new Producer<DataNode<ProjectData>>() { @Nullable @Override public DataNode<ProjectData> produce() { return myDelegate.resolveProjectInfo(id, projectPath, isPreviewMode, settings, getNotificationListener()); } }); }
@Override public void executeTasks(@NotNull final ExternalSystemTaskId id, @NotNull final List<String> taskNames, @NotNull final String projectPath, @Nullable final S settings, @NotNull final List<String> vmOptions, @NotNull final List<String> scriptParameters, @Nullable final String debuggerSetup) throws RemoteException, ExternalSystemException { execute(id, new Producer<Object>() { @Nullable @Override public Object produce() { myDelegate.executeTasks( id, taskNames, projectPath, settings, vmOptions, scriptParameters, debuggerSetup, getNotificationListener()); return null; } }); }
protected JComponent createEditorContent() { final JPanel result = new JPanel(new BorderLayout()); searchCriteriaEdit = createEditor(searchContext, mySavedEditorText != null ? mySavedEditorText : ""); result.add(BorderLayout.CENTER, searchCriteriaEdit.getComponent()); result.setMinimumSize(new Dimension(150, 100)); final JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0)); labelPanel.add(new JLabel(SSRBundle.message("search.template"))); labelPanel.add(UIUtil.createCompleteMatchInfo(new Producer<Configuration>() { @Nullable @Override public Configuration produce() { return model.getConfig(); } })); result.add(BorderLayout.NORTH, labelPanel); return result; }
@Nullable private static String getCopiedFqn(final DataContext context) { Producer<Transferable> producer = PasteAction.TRANSFERABLE_PROVIDER.getData(context); if (producer != null) { Transferable transferable = producer.produce(); if (transferable != null) { try { return (String)transferable.getTransferData(CopyReferenceAction.ourFlavor); } catch (Exception ignored) { } } return null; } return CopyPasteManager.getInstance().getContents(CopyReferenceAction.ourFlavor); }
public void updateText(@NotNull final Producer<String> contentProducer) { myAlarm.cancelAllRequests(); myAlarm.addRequest(new Runnable() { @Override public void run() { if (!isDisposed) { final String newText = contentProducer.produce(); if (StringUtil.isEmpty(newText)) { hide(); } else if (!myEditor.getDocument().getText().equals(newText)) { DocumentUtil.writeInRunUndoTransparentAction(new Runnable() { @Override public void run() { myEditor.getDocument().setText(newText); } }); } } } }, 100); }
private static Producer<PsiElement> prevWalker(final PsiElement element, final PsiElement scope) { return new Producer<PsiElement>() { PsiElement e = element; @Nullable @Override public PsiElement produce() { if (e == null || e == scope) return null; PsiElement prev = e.getPrevSibling(); if (prev != null) { return e = PsiTreeUtil.getDeepestLast(prev); } else { PsiElement parent = e.getParent(); return e = parent == scope || parent instanceof PsiFile ? null : parent; } } }; }
private void runPasteAction(final String toPaste) { final Producer<Transferable> producer = new Producer<Transferable>() { @Nullable @Override public Transferable produce() { return new StringSelection(toPaste); } }; EditorActionManager actionManager = EditorActionManager.getInstance(); EditorActionHandler pasteActionHandler = actionManager.getActionHandler(ACTION_EDITOR_PASTE); final PasteHandler pasteHandler = new PasteHandler(pasteActionHandler); new WriteCommandAction.Simple(getProject(), new PsiFile[0]) { protected void run() throws Throwable { Component component = myFixture.getEditor().getComponent(); DataContext dataContext = DataManager.getInstance().getDataContext(component); pasteHandler.execute(myFixture.getEditor(), dataContext, producer); } }.execute(); }
@Nullable @Override public DataNode<ProjectData> resolveProjectInfo(@NotNull final ExternalSystemTaskId id, @NotNull final String projectPath, final boolean downloadLibraries, ExternalSystemExecutionSettings settings) throws ExternalSystemException, IllegalArgumentException, IllegalStateException { return execute(id, new Producer<DataNode<ProjectData>>() { @Nullable @Override public DataNode<ProjectData> produce() { return myDelegate.resolveProjectInfo(id, projectPath, downloadLibraries, getSettings(), getNotificationListener()); } }); }
@Override public void executeTasks(@NotNull final ExternalSystemTaskId id, @NotNull final List<String> taskNames, @NotNull final String projectPath, @Nullable final S settings, @Nullable final String vmOptions) throws RemoteException, ExternalSystemException { execute(id, new Producer<Object>() { @Nullable @Override public Object produce() { myDelegate.executeTasks(id, taskNames, projectPath, settings, vmOptions, getNotificationListener()); return null; } }); }
@javax.annotation.Nullable @Override public DataNode<ProjectData> resolveProjectInfo(@Nonnull final ExternalSystemTaskId id, @Nonnull final String projectPath, final boolean isPreviewMode, ExternalSystemExecutionSettings settings) throws ExternalSystemException, IllegalArgumentException, IllegalStateException { return execute(id, new Producer<DataNode<ProjectData>>() { @javax.annotation.Nullable @Override public DataNode<ProjectData> produce() { return myDelegate.resolveProjectInfo(id, projectPath, isPreviewMode, getSettings(), getNotificationListener()); } }); }
@Override public void executeTasks(@Nonnull final ExternalSystemTaskId id, @Nonnull final List<String> taskNames, @Nonnull final String projectPath, @javax.annotation.Nullable final S settings, @Nonnull final List<String> vmOptions, @Nonnull final List<String> scriptParameters, @javax.annotation.Nullable final String debuggerSetup) throws RemoteException, ExternalSystemException { execute(id, new Producer<Object>() { @javax.annotation.Nullable @Override public Object produce() { myDelegate.executeTasks( id, taskNames, projectPath, settings, vmOptions, scriptParameters, debuggerSetup, getNotificationListener()); return null; } }); }
@Nonnull public static <K, V> ConcurrentMap<K, V> createMap(@Nonnull final Function<K, V> computeValue, @Nonnull final Producer<ConcurrentMap<K,V>> mapCreator) { //noinspection deprecation return new ConcurrentFactoryMap<K, V>() { @Nullable @Override protected V create(K key) { return computeValue.fun(key); } @Nonnull @Override protected ConcurrentMap<K, V> createMap() { return mapCreator.produce(); } }; }
@Nonnull public static <K, V> Map<K, V> createMap(@Nonnull final Function<K, V> computeValue, @Nonnull final Producer<Map<K,V>> mapCreator) { //noinspection deprecation return new FactoryMap<K, V>() { @Nullable @Override protected V create(K key) { return computeValue.fun(key); } @Nonnull @Override protected Map<K, V> createMap() { return mapCreator.produce(); } }; }
@Nullable private static String getCopiedFqn(final DataContext context) { Producer<Transferable> producer = context.getData(PasteAction.TRANSFERABLE_PROVIDER); if (producer != null) { Transferable transferable = producer.produce(); if (transferable != null) { try { return (String)transferable.getTransferData(CopyReferenceAction.ourFlavor); } catch (Exception ignored) { } } return null; } return CopyPasteManager.getInstance().getContents(CopyReferenceAction.ourFlavor); }
@Nullable public static Transferable getTransferable(final @NotNull Editor editor, DataContext dataContext) { try { Producer<Transferable> producer = PasteAction.TRANSFERABLE_PROVIDER.getData(dataContext); //noinspection UnnecessaryLocalVariable Transferable transferable = EditorModificationUtil.getContentsToPasteToEditor(producer); return transferable; } catch (Throwable e) { logger.error("error", e); } return null; }
@Nullable public static Transferable getContentsToPasteToEditor(@Nullable Producer<Transferable> producer) { if (producer == null) { CopyPasteManager manager = CopyPasteManager.getInstance(); return manager.areDataFlavorsAvailable(DataFlavor.stringFlavor) ? manager.getContents() : null; } else { return producer.produce(); } }
private static Transferable getTransferable(Producer<Transferable> producer) { Transferable content = null; if (producer != null) { content = producer.produce(); } else { CopyPasteManager manager = CopyPasteManager.getInstance(); if (manager.areDataFlavorsAvailable(DataFlavor.stringFlavor)) { content = manager.getContents(); } } return content; }
@Nullable public String getLabel() { return accessChanges(new Producer<String>() { @Override public String produce() { for (Change each : myChanges) { if (each instanceof PutLabelChange) { return ((PutLabelChange)each).getName(); } } return null; } }); }
public int getLabelColor() { return accessChanges(new Producer<Integer>() { @Override public Integer produce() { for (Change each : myChanges) { if (each instanceof PutSystemLabelChange) { return ((PutSystemLabelChange)each).getColor(); } } return -1; } }); }
public List<Change> getChanges() { return accessChanges(new Producer<List<Change>>() { @Override public List<Change> produce() { if (isLocked) return myChanges; return Collections.unmodifiableList(new ArrayList<Change>(myChanges)); } }); }
public boolean isEmpty() { return accessChanges(new Producer<Boolean>() { @Override public Boolean produce() { return myChanges.isEmpty(); } }); }
public boolean affectsPath(final String paths) { return accessChanges(new Producer<Boolean>() { @Override public Boolean produce() { for (Change c : myChanges) { if (c.affectsPath(paths)) return true; } return false; } }); }
public boolean isCreationalFor(final String path) { return accessChanges(new Producer<Boolean>() { @Override public Boolean produce() { for (Change c : myChanges) { if (c.isCreationalFor(path)) return true; } return false; } }); }
public List<Content> getContentsToPurge() { return accessChanges(new Producer<List<Content>>() { @Override public List<Content> produce() { List<Content> result = new ArrayList<Content>(); for (Change c : myChanges) { result.addAll(c.getContentsToPurge()); } return result; } }); }
public boolean isContentChangeOnly() { return accessChanges(new Producer<Boolean>() { @Override public Boolean produce() { return myChanges.size() == 1 && getFirstChange() instanceof ContentChange; } }); }
public boolean isLabelOnly() { return accessChanges(new Producer<Boolean>() { @Override public Boolean produce() { return myChanges.size() == 1 && getFirstChange() instanceof PutLabelChange; } }); }
public Change getFirstChange() { return accessChanges(new Producer<Change>() { @Override public Change produce() { return myChanges.get(0); } }); }
public Change getLastChange() { return accessChanges(new Producer<Change>() { @Override public Change produce() { return myChanges.get(myChanges.size() - 1); } }); }
public List<String> getAffectedPaths() { return accessChanges(new Producer<List<String>>() { @Override public List<String> produce() { List<String> result = new SmartList<String>(); for (Change each : myChanges) { if (each instanceof StructuralChange) { result.add(((StructuralChange)each).getPath()); } } return result; } }); }
public String toString() { return accessChanges(new Producer<String>() { @Override public String produce() { return myChanges.toString(); } }); }
private <T> T accessChanges(@NotNull Producer<T> func) { if (isLocked) { //noinspection ConstantConditions return func.produce(); } synchronized (myChanges) { //noinspection ConstantConditions return func.produce(); } }
private void accessChanges(@NotNull final Runnable func) { accessChanges(new Producer<Object>() { @Override public Object produce() { func.run(); return null; } }); }
protected <T> T execute(@NotNull ExternalSystemTaskId id, @NotNull Producer<T> task) { Set<ExternalSystemTaskId> tasks = myTasksInProgress.get(id.getType()); if (tasks == null) { myTasksInProgress.putIfAbsent(id.getType(), new HashSet<ExternalSystemTaskId>()); tasks = myTasksInProgress.get(id.getType()); } tasks.add(id); try { return task.produce(); } finally { tasks.remove(id); } }
public static void updateQuickDocAsync(@NotNull final PsiElement element, @NotNull final Producer<String> docProducer) { final Project project = element.getProject(); ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { updateQuickDoc(project, element, docProducer.produce()); } }); }
public static void unzipWithProgressSynchronously( @Nullable Project project, @NotNull String progressTitle, @NotNull final File zipArchive, @NotNull final File extractToDir, @Nullable final NullableFunction<String, String> pathConvertor, final boolean unwrapSingleTopLevelFolder) throws GeneratorException { final Outcome<Boolean> outcome = DownloadUtil.provideDataWithProgressSynchronously( project, progressTitle, "Unpacking ...", new Callable<Boolean>() { @Override public Boolean call() throws IOException { ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); unzip(progress, extractToDir, zipArchive, pathConvertor, null, unwrapSingleTopLevelFolder); return true; } }, new Producer<Boolean>() { @Override public Boolean produce() { return false; } } ); Boolean result = outcome.get(); if (result == null) { @SuppressWarnings("ThrowableResultOfMethodCallIgnored") Exception e = outcome.getException(); if (e != null) { throw new GeneratorException("Unpacking failed, downloaded archive is broken"); } throw new GeneratorException("Unpacking was cancelled"); } }
@Nullable public Result<T> getResult(@NotNull final Project project, @NotNull final PsiDirectory dir) { final Ref<Result<T>> created = Ref.create(null); okAction = new Producer<Boolean>() { @Nullable @Override public Boolean produce() { final String name = className.getText().trim(); if(name.isEmpty()) { return Boolean.FALSE; } final Set<DefracPlatform> enabledPlatforms = platformChooser.getPlatforms(); final T genericElement = createElement(generic, project, dir, name, DefracPlatform.GENERIC, enabledPlatforms); if(genericElement == null) { return Boolean.FALSE; } final T androidElement = createElement(android, project, dir, name, DefracPlatform.ANDROID, enabledPlatforms); final T iosElement = createElement(ios , project, dir, name, DefracPlatform.IOS , enabledPlatforms); final T jvmElement = createElement(jvm , project, dir, name, DefracPlatform.JVM , enabledPlatforms); final T webElement = createElement(web , project, dir, name, DefracPlatform.WEB , enabledPlatforms); created.set(new Result<T>(genericElement, androidElement, iosElement, jvmElement, webElement)); return Boolean.TRUE; } }; show(); if(getExitCode() == OK_EXIT_CODE) { return created.get(); } return null; }