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