Search in sources :

Example 6 with Ref

use of com.intellij.openapi.util.Ref in project intellij-community by JetBrains.

the class IgnoreActionGroup method update.

public void update(final AnActionEvent e) {
    final FileGroupInfo fileGroupInfo = new FileGroupInfo();
    myHelperAction.setFileIterationListener(fileGroupInfo);
    myHelperAction.update(e);
    myGetterStub.setDelegate(fileGroupInfo);
    if ((e.getPresentation().isEnabled())) {
        removeAll();
        if (myHelperAction.allAreIgnored()) {
            final DataContext dataContext = e.getDataContext();
            final Project project = CommonDataKeys.PROJECT.getData(dataContext);
            SvnVcs vcs = SvnVcs.getInstance(project);
            final Ref<Boolean> filesOk = new Ref<>(Boolean.FALSE);
            final Ref<Boolean> extensionOk = new Ref<>(Boolean.FALSE);
            // virtual files parameter is not used -> can pass null
            SvnPropertyService.doCheckIgnoreProperty(vcs, null, fileGroupInfo, fileGroupInfo.getExtensionMask(), filesOk, extensionOk);
            if (Boolean.TRUE.equals(filesOk.get())) {
                myRemoveExactAction.setActionText(fileGroupInfo.oneFileSelected() ? fileGroupInfo.getFileName() : SvnBundle.message("action.Subversion.UndoIgnore.text"));
                add(myRemoveExactAction);
            }
            if (Boolean.TRUE.equals(extensionOk.get())) {
                myRemoveExtensionAction.setActionText(fileGroupInfo.getExtensionMask());
                add(myRemoveExtensionAction);
            }
            e.getPresentation().setText(SvnBundle.message("group.RevertIgnoreChoicesGroup.text"));
        } else if (myHelperAction.allCanBeIgnored()) {
            final String ignoreExactlyName = (fileGroupInfo.oneFileSelected()) ? fileGroupInfo.getFileName() : SvnBundle.message("action.Subversion.Ignore.ExactMatch.text");
            myAddExactAction.setActionText(ignoreExactlyName);
            add(myAddExactAction);
            if (fileGroupInfo.sameExtension()) {
                myAddExtensionAction.setActionText(fileGroupInfo.getExtensionMask());
                add(myAddExtensionAction);
            }
            e.getPresentation().setText(SvnBundle.message("group.IgnoreChoicesGroup.text"));
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) Ref(com.intellij.openapi.util.Ref) FileGroupInfo(org.jetbrains.idea.svn.ignore.FileGroupInfo) SvnVcs(org.jetbrains.idea.svn.SvnVcs)

Example 7 with Ref

use of com.intellij.openapi.util.Ref in project intellij-community by JetBrains.

the class ShareProjectAction method performImpl.

private static boolean performImpl(@NotNull SvnVcs vcs, @NotNull VirtualFile file) throws VcsException {
    ShareDialog shareDialog = new ShareDialog(vcs.getProject(), file.getName());
    shareDialog.show();
    String parent = shareDialog.getSelectedURL();
    if (shareDialog.isOK() && parent != null) {
        Ref<Boolean> actionStarted = new Ref<>(Boolean.TRUE);
        Exception[] error = new Exception[1];
        ShareDialog.ShareTarget shareTarget = shareDialog.getShareTarget();
        if (ShareDialog.ShareTarget.useSelected.equals(shareTarget) && !isFolderEmpty(vcs, parent) && YES != showYesNoDialog(vcs.getProject(), "Remote folder \"" + parent + "\" is not empty.\nDo you want to continue sharing?", "Share Directory", getWarningIcon())) {
            return false;
        }
        WorkingCopyFormat format = SvnCheckoutProvider.promptForWCopyFormat(virtualToIoFile(file), vcs.getProject());
        actionStarted.set(format != WorkingCopyFormat.UNKNOWN);
        // means operation cancelled
        if (format == WorkingCopyFormat.UNKNOWN) {
            return true;
        }
        ExclusiveBackgroundVcsAction.run(vcs.getProject(), () -> ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            try {
                SvnWorkingCopyFormatHolder.setPresetFormat(format);
                SvnTarget checkoutTarget = createFolderStructure(vcs, file, shareTarget, shareDialog.createStandardStructure(), createUrl(parent), shareDialog.getCommitText());
                progress(message("share.directory.checkout.back.progress.text", checkoutTarget.getPathOrUrlString()));
                ClientFactory factory = SvnCheckoutProvider.getFactory(vcs, format);
                factory.createCheckoutClient().checkout(SvnTarget.fromURL(checkoutTarget.getURL()), virtualToIoFile(file), checkoutTarget.getPegRevision(), Depth.INFINITY, false, false, format, null);
                addRecursively(vcs, factory, file);
            } catch (VcsException e) {
                error[0] = e;
            } finally {
                vcs.invokeRefreshSvnRoots();
                SvnWorkingCopyFormatHolder.setPresetFormat(null);
            }
        }, message("share.directory.title"), true, vcs.getProject()));
        if (Boolean.TRUE.equals(actionStarted.get())) {
            if (error[0] != null) {
                throw new VcsException(error[0].getMessage());
            }
            showInfoMessage(vcs.getProject(), message("share.directory.info.message", file.getName()), message("share.directory.title"));
        }
        return true;
    }
    return false;
}
Also used : Ref(com.intellij.openapi.util.Ref) ShareDialog(org.jetbrains.idea.svn.dialogs.ShareDialog) SvnTarget(org.tmatesoft.svn.core.wc2.SvnTarget) VcsException(com.intellij.openapi.vcs.VcsException) ClientFactory(org.jetbrains.idea.svn.api.ClientFactory) VcsException(com.intellij.openapi.vcs.VcsException)

Example 8 with Ref

use of com.intellij.openapi.util.Ref in project intellij-community by JetBrains.

the class TaskManagerTest method testNotifications.

public void testNotifications() throws Exception {
    final Ref<Notification> notificationRef = new Ref<>();
    getProject().getMessageBus().connect(myFixture.getTestRootDisposable()).subscribe(Notifications.TOPIC, new NotificationsAdapter() {

        @Override
        public void notify(@NotNull Notification notification) {
            notificationRef.set(notification);
        }
    });
    TestRepository repository = new TestRepository() {

        @Override
        public Task[] getIssues(@Nullable String query, int max, long since) throws Exception {
            throw new Exception();
        }
    };
    myTaskManager.setRepositories(Collections.singletonList(repository));
    myTaskManager.updateIssues(null);
    assertNull(notificationRef.get());
    myTaskManager.getIssues("");
    assertNotNull(notificationRef.get());
}
Also used : NotificationsAdapter(com.intellij.notification.NotificationsAdapter) Ref(com.intellij.openapi.util.Ref) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with Ref

use of com.intellij.openapi.util.Ref in project intellij-community by JetBrains.

the class TaskManagerTest method testIssuesCacheSurvival.

public void testIssuesCacheSurvival() throws Exception {
    final Ref<Boolean> stopper = new Ref<>(Boolean.FALSE);
    TestRepository repository = new TestRepository(new LocalTaskImpl("foo", "bar")) {

        @Override
        public Task[] getIssues(@Nullable String query, int max, long since) throws Exception {
            if (stopper.get())
                throw new Exception();
            return super.getIssues(query, max, since);
        }
    };
    myTaskManager.setRepositories(Collections.singletonList(repository));
    List<Task> issues = myTaskManager.getIssues("");
    assertEquals(1, issues.size());
    stopper.set(Boolean.TRUE);
    issues = myTaskManager.getIssues("");
    assertEquals(1, issues.size());
}
Also used : Ref(com.intellij.openapi.util.Ref) LocalTaskImpl(com.intellij.tasks.impl.LocalTaskImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with Ref

use of com.intellij.openapi.util.Ref in project intellij-community by JetBrains.

the class PsiDocumentNavigator method getElementById.

public Object getElementById(Object object, final String elementId) {
    final XmlTag rootTag = ((XmlFile) ((XmlElement) object).getContainingFile()).getRootTag();
    if (rootTag == null) {
        return null;
    }
    final Ref<XmlTag> ref = new Ref<>();
    rootTag.accept(new XmlRecursiveElementVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (ref.get() == null) {
                super.visitElement(element);
            }
        }

        @Override
        public void visitXmlAttribute(XmlAttribute attribute) {
            final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
            final String value = attribute.getValue();
            if ((value != null && (descriptor != null && descriptor.hasIdType()))) {
                if (elementId.equals(value)) {
                    ref.set(attribute.getParent());
                }
            }
        }
    });
    return ref.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlRecursiveElementVisitor(com.intellij.psi.XmlRecursiveElementVisitor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

Ref (com.intellij.openapi.util.Ref)253 Nullable (org.jetbrains.annotations.Nullable)82 NotNull (org.jetbrains.annotations.NotNull)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)48 Project (com.intellij.openapi.project.Project)38 List (java.util.List)30 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)26 PsiElement (com.intellij.psi.PsiElement)26 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)22 PsiFile (com.intellij.psi.PsiFile)20 Module (com.intellij.openapi.module.Module)18 Editor (com.intellij.openapi.editor.Editor)16 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)16 File (java.io.File)16 Task (com.intellij.openapi.progress.Task)15 Pair (com.intellij.openapi.util.Pair)14 VcsException (com.intellij.openapi.vcs.VcsException)14 IncorrectOperationException (com.intellij.util.IncorrectOperationException)14 Document (com.intellij.openapi.editor.Document)13