Java Code Examples for com.intellij.ide.BrowserUtil

The following examples show how to use com.intellij.ide.BrowserUtil. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: markdown-image-kit   Source File: UploadNotification.java    License: MIT License 7 votes vote down vote up
/**
 * 上传时检查到配置错误时通知
 *
 * @param project    the project
 * @param actionName the action name
 */
public static void notifyConfigurableError(Project project, String actionName) {
    String content = "<p><a href=''>Configure " + actionName + " OSS</a></p><br />";
    content = "<p>You may need to set or reset your account. Please be sure to <b>test</b> it after the setup is complete.</p>" + content + "<br />";
    content = content + "<p>Or you may need <a href='" + HELP_URL + "'>Help</a></p>";
    Notifications.Bus.notify(new Notification(MIK_NOTIFICATION_GROUP,
                                              "Configurable Error",
                                              content,
                                              NotificationType.ERROR,
                                              new NotificationListener.Adapter() {
                                                  @Override
                                                  protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                                                      String url = e.getDescription();
                                                      log.trace("{}", e.getDescription());
                                                      if (StringUtils.isBlank(url)) {
                                                          ProjectSettingsPage configurable = new ProjectSettingsPage();
                                                          // 打开设置面板
                                                          ShowSettingsUtil.getInstance().editConfigurable(project, configurable);
                                                      } else {
                                                          BrowserUtil.browse(url);
                                                      }
                                                      hideBalloon(notification.getBalloon());
                                                  }
                                              }), project);
}
 
Example 2
private void checkForDisplayFirstReload() {
  final PropertiesComponent properties = PropertiesComponent.getInstance(myProject);

  final boolean alreadyRun = properties.getBoolean(RELOAD_ALREADY_RUN);
  if (!alreadyRun) {
    properties.setValue(RELOAD_ALREADY_RUN, true);

    final Notification notification = new Notification(
      FlutterMessages.FLUTTER_NOTIFICATION_GROUP_ID,
      FlutterBundle.message("flutter.reload.firstRun.title"),
      FlutterBundle.message("flutter.reload.firstRun.content"),
      NotificationType.INFORMATION);
    notification.setIcon(FlutterIcons.HotReload);
    notification.addAction(new AnAction("Learn more") {
      @Override
      public void actionPerformed(@NotNull AnActionEvent event) {
        BrowserUtil.browse(FlutterBundle.message("flutter.reload.firstRun.url"));
        notification.expire();
      }
    });
    Notifications.Bus.notify(notification);
  }
}
 
Example 3
private void checkForDisplayFirstReload() {
  final PropertiesComponent properties = PropertiesComponent.getInstance(myProject);

  final boolean alreadyRun = properties.getBoolean(RELOAD_ALREADY_RUN);
  if (!alreadyRun) {
    properties.setValue(RELOAD_ALREADY_RUN, true);

    final Notification notification = new Notification(
      FlutterMessages.FLUTTER_NOTIFICATION_GROUP_ID,
      FlutterBundle.message("flutter.reload.firstRun.title"),
      FlutterBundle.message("flutter.reload.firstRun.content"),
      NotificationType.INFORMATION);
    notification.setIcon(FlutterIcons.HotReload);
    notification.addAction(new AnAction("Learn more") {
      @Override
      public void actionPerformed(@NotNull AnActionEvent event) {
        BrowserUtil.browse(FlutterBundle.message("flutter.reload.firstRun.url"));
        notification.expire();
      }
    });
    Notifications.Bus.notify(notification);
  }
}
 
Example 4
Source Project: azure-devops-intellij   Source File: AnnotateAction.java    License: MIT License 6 votes vote down vote up
@Override
protected void execute(final @NotNull SingleItemActionContext actionContext) {
    final ServerContext context = actionContext.getServerContext();

    // check for null values (it's ok if the server item is null because the URL redirects to the general page in that case
    if (context != null && context.getTeamProjectReference() != null && actionContext.getItem() != null) {
        final URI urlToBrowseTo = UrlHelper.getTfvcAnnotateURI(context.getUri().toString(),
                context.getTeamProjectReference().getName(), actionContext.getItem().getServerItem());
        logger.info("Browsing to url " + urlToBrowseTo.getPath());
        BrowserUtil.browse(urlToBrowseTo);
    } else {
        final String issue = context == null ? "context is null" : context.getTeamProjectReference() == null ? "team project is null" : "getItem is null";
        logger.warn("Couldn't create annotate url: " + issue);
        Messages.showErrorDialog(actionContext.getProject(), TfPluginBundle.message(TfPluginBundle.KEY_ACTIONS_ANNOTATE_ERROR_MSG),
                TfPluginBundle.message(TfPluginBundle.KEY_ACTIONS_ANNOTATE_ERROR_TITLE));
    }
}
 
Example 5
Source Project: azure-devops-intellij   Source File: OpenCommitInBrowserAction.java    License: MIT License 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull final AnActionEvent anActionEvent) {
    final Project project = anActionEvent.getRequiredData(CommonDataKeys.PROJECT);
    final VcsFullCommitDetails commit = anActionEvent.getRequiredData(VcsLogDataKeys.VCS_LOG).getSelectedDetails().get(0);

    final GitRepository gitRepository = GitUtil.getRepositoryManager(project).getRepositoryForRootQuick(commit.getRoot());
    if (gitRepository == null)
        return;

    final GitRemote remote = TfGitHelper.getTfGitRemote(gitRepository);

    // guard for null so findbugs doesn't complain
    if (remote == null) {
        return;
    }

    final String remoteUrl = remote.getFirstUrl();
    if (remoteUrl == null) {
        return;
    }

    final URI urlToBrowseTo = UrlHelper.getCommitURI(remoteUrl, commit.getId().toString());
    logger.info("Browsing to url " + urlToBrowseTo.getPath());
    BrowserUtil.browse(urlToBrowseTo);
}
 
Example 6
Source Project: azure-devops-intellij   Source File: FeedbackAction.java    License: MIT License 6 votes vote down vote up
public void sendFeedback(final boolean smile) {
    final FeedbackDialog dialog = new FeedbackDialog(project, smile);

    dialog.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            if (FeedbackForm.CMD_GOTO_PRIVACY.equalsIgnoreCase(e.getActionCommand())) {
                BrowserUtil.browse(URL_PRIVACY_POLICY);
            }
        }
    });

    if (dialog.showAndGet()) {
        VcsNotifier.getInstance(project).notifySuccess(
                TfPluginBundle.message(TfPluginBundle.KEY_FEEDBACK_DIALOG_TITLE),
                TfPluginBundle.message(TfPluginBundle.KEY_FEEDBACK_NOTIFICATION));
    }
}
 
Example 7
Source Project: azure-devops-intellij   Source File: AnnotateActionTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testExecute_Success() {
    ArgumentCaptor<URI> argCapture = ArgumentCaptor.forClass(URI.class);
    when(mockTeamProjectReference.getName()).thenReturn("TeamName");
    when(mockItemInfo.getServerItem()).thenReturn("$/path/to/file.txt");
    when(mockServerContext.getTeamProjectReference()).thenReturn(mockTeamProjectReference);
    when(mockActionContext.getServerContext()).thenReturn(mockServerContext);
    when(mockActionContext.getItem()).thenReturn(mockItemInfo);
    annotateAction.execute(mockActionContext);

    verifyStatic(times(0));
    Messages.showErrorDialog(any(Project.class), anyString(), anyString());
    verifyStatic(times(1));
    BrowserUtil.browse(argCapture.capture());
    assertEquals(serverURI.toString() +
                    "TeamName/_versionControl/?path=%24%2Fpath%2Fto%2Ffile.txt&_a=contents&annotate=true&hideComments=true",
            argCapture.getValue().toString());
}
 
Example 8
Source Project: consulo-unity3d   Source File: UnityPluginFileValidator.java    License: Apache License 2.0 6 votes vote down vote up
private static void showNotify(final Project project, final String pluginFileName, final File unityPluginFile, @Nonnull String title, @Nonnull List<VirtualFile> oldPluginFiles)
{
	Notification notification = new Notification(ourGroup.getDisplayId(), "Unity3D Plugin", title, !oldPluginFiles.isEmpty() ? NotificationType.ERROR : NotificationType.INFORMATION);
	notification.setListener((thisNotification, hyperlinkEvent) ->
	{
		thisNotification.hideBalloon();

		switch(hyperlinkEvent.getDescription())
		{
			case "info":
				BrowserUtil.browse("https://github.com/consulo/consulo/issues/250");
				break;
			case "update":
				updatePlugin(project, pluginFileName, unityPluginFile, oldPluginFiles);
				break;
		}
	});
	notification.notify(project);
}
 
Example 9
Source Project: tutorials   Source File: SearchAction.java    License: MIT License 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Optional<PsiFile> psiFile = Optional.ofNullable(e.getData(LangDataKeys.PSI_FILE));
    String languageTag = psiFile
            .map(PsiFile::getLanguage)
            .map(Language::getDisplayName)
            .map(String::toLowerCase)
            .map(lang -> "[" + lang + "]")
            .orElse("");

    Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
    CaretModel caretModel = editor.getCaretModel();
    String selectedText = caretModel.getCurrentCaret().getSelectedText();

    BrowserUtil.browse("https://stackoverflow.com/search?q=" + languageTag + selectedText);
}
 
Example 10
Source Project: consulo   Source File: BrowserLauncherAppless.java    License: Apache License 2.0 6 votes vote down vote up
private static void addArgs(@Nonnull GeneralCommandLine command, @Nullable BrowserSpecificSettings settings, @Nonnull String[] additional) {
  List<String> specific = settings == null ? Collections.<String>emptyList() : settings.getAdditionalParameters();
  if (specific.size() + additional.length > 0) {
    if (isOpenCommandUsed(command)) {
      if (BrowserUtil.isOpenCommandSupportArgs()) {
        command.addParameter("--args");
      }
      else {
        LOG.warn("'open' command doesn't allow to pass command line arguments so they will be ignored: " + StringUtil.join(specific, ", ") + " " + Arrays.toString(additional));
        return;
      }
    }

    command.addParameters(specific);
    command.addParameters(additional);
  }
}
 
Example 11
Source Project: consulo   Source File: ChangeListStorageImpl.java    License: Apache License 2.0 6 votes vote down vote up
public static void notifyUser(String message) {
  final String logFile = ContainerPathManager.get().getLogPath();
  /*String createIssuePart = "<br>" +
                           "<br>" +
                           "Please attach log files from <a href=\"file\">" + logFile + "</a><br>" +
                           "to the <a href=\"url\">YouTrack issue</a>";*/
  Notifications.Bus.notify(new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID,
                                            "Local History is broken",
                                            message /*+ createIssuePart*/,
                                            NotificationType.ERROR,
                                            new NotificationListener() {
                                              @Override
                                              public void hyperlinkUpdate(@Nonnull Notification notification,
                                                                          @Nonnull HyperlinkEvent event) {
                                                if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                                                  if ("url".equals(event.getDescription())) {
                                                    BrowserUtil.launchBrowser("http://youtrack.jetbrains.net/issue/IDEA-71270");
                                                  }
                                                  else {
                                                    File file = new File(logFile);
                                                    ShowFilePathAction.openFile(file);
                                                  }
                                                }
                                              }
                                            }), null);
}
 
Example 12
Source Project: consulo   Source File: TipUIUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static JEditorPane createTipBrowser() {
  JEditorPane browser = new JEditorPane() {
    @Override
    public void setDocument(Document document) {
      super.setDocument(document);
      document.putProperty("imageCache", new URLDictionatyLoader());
    }
  };
  browser.setEditable(false);
  browser.setBackground(UIUtil.getTextFieldBackground());
  browser.addHyperlinkListener(e -> {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
      BrowserUtil.browse(e.getURL());
    }
  });
  URL resource = ResourceUtil.getResource(TipUIUtil.class, "/tips/css/", UIUtil.isUnderDarcula() ? "tips_darcula.css" : "tips.css");
  HTMLEditorKit kit = UIUtil.getHTMLEditorKit(false);
  kit.getStyleSheet().addStyleSheet(UIUtil.loadStyleSheet(resource));
  browser.setEditorKit(kit);
  return browser;
}
 
Example 13
Source Project: consulo   Source File: PluginManagerMain.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
  if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
    JEditorPane pane = (JEditorPane)e.getSource();
    if (e instanceof HTMLFrameHyperlinkEvent) {
      HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent)e;
      HTMLDocument doc = (HTMLDocument)pane.getDocument();
      doc.processHTMLFrameHyperlinkEvent(evt);
    }
    else {
      URL url = e.getURL();
      if (url != null) {
        BrowserUtil.browse(url);
      }
    }
  }
}
 
Example 14
Source Project: consulo   Source File: VcsCommitInfoBalloon.java    License: Apache License 2.0 6 votes vote down vote up
public VcsCommitInfoBalloon(@Nonnull JTree tree) {
  myTree = tree;
  myEditorPane = new JEditorPane(UIUtil.HTML_MIME, "");
  myEditorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
  myEditorPane.setEditable(false);
  myEditorPane.setBackground(HintUtil.INFORMATION_COLOR);
  myEditorPane.setFont(UIUtil.getToolTipFont());
  myEditorPane.setBorder(HintUtil.createHintBorder());
  Border margin = IdeBorderFactory.createEmptyBorder(3, 3, 3, 3);
  myEditorPane.setBorder(new CompoundBorder(myEditorPane.getBorder(), margin));
  myEditorPane.addHyperlinkListener(new HyperlinkAdapter() {
    @Override
    protected void hyperlinkActivated(HyperlinkEvent e) {
      BrowserUtil.browse(e.getURL());
    }
  });
  myWrapper = new Wrapper(myEditorPane);
  myPopupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(myWrapper, null);
  myPopupBuilder.setCancelOnClickOutside(true).setResizable(true).setMovable(true).setRequestFocus(false)
          .setMinSize(new Dimension(80, 30));
}
 
Example 15
Source Project: consulo   Source File: AbstractBaseTagMouseListener.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean onClick(MouseEvent e, int clickCount) {
  if (e.getButton() == 1 && !e.isPopupTrigger()) {
    Object tag = getTagAt(e);
    if (tag instanceof Runnable) {
      ((Runnable) tag).run();
      return true;
    }

    if ((tag != null) && (! Object.class.getName().equals(tag.getClass().getName()))) {
      BrowserUtil.launchBrowser(tag.toString());
      return true;
    }
  }
  return false;
}
 
Example 16
Source Project: consulo   Source File: WindowsDefenderFixAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e, @Nonnull Notification notification) {
  int rc = Messages.showDialog(e.getProject(), DiagnosticBundle
                                       .message("virus.scanning.fix.explanation", ApplicationNamesInfo.getInstance().getFullProductName(), WindowsDefenderChecker.getInstance().getConfigurationInstructionsUrl()),
                               DiagnosticBundle.message("virus.scanning.fix.title"),
                               new String[]{DiagnosticBundle.message("virus.scanning.fix.automatically"), DiagnosticBundle.message("virus.scanning.fix.manually"),
                                       CommonBundle.getCancelButtonText()}, 0, null);

  switch (rc) {
    case Messages.OK:
      notification.expire();
      ApplicationManager.getApplication().executeOnPooledThread(() -> {
        if (WindowsDefenderChecker.getInstance().runExcludePathsCommand(e.getProject(), myPaths)) {
          UIUtil.invokeLaterIfNeeded(() -> {
            Notifications.Bus.notifyAndHide(new Notification("System Health", "", DiagnosticBundle.message("virus.scanning.fix.success.notification"), NotificationType.INFORMATION), e.getProject());
          });
        }
      });

      break;
    case Messages.CANCEL:
      BrowserUtil.browse(WindowsDefenderChecker.getInstance().getConfigurationInstructionsUrl());
      break;
  }
}
 
Example 17
QuarkusCodeEndpointChooserStep(WizardContext wizardContext) {
    this.customUrlWithBrowseButton = new ComponentWithBrowseButton(this.endpointURL, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                QuarkusCodeEndpointChooserStep.this.validate();
                BrowserUtil.browse(QuarkusCodeEndpointChooserStep.this.endpointURL.getText());
            } catch (ConfigurationException var3) {
                Messages.showErrorDialog(var3.getMessage(), "Cannot Open URL");
            }

        }
    });
    this.wizardContext = wizardContext;
    String lastServiceUrl = PropertiesComponent.getInstance().getValue(LAST_ENDPOINT_URL, QUARKUS_CODE_URL);
    if (!lastServiceUrl.equals(QUARKUS_CODE_URL)) {
        this.endpointURL.setSelectedItem(lastServiceUrl);
        this.defaultRadioButton.setSelected(false);
        this.customRadioButton.setSelected(true);
    } else {
        this.defaultRadioButton.setSelected(true);
    }

    List<String> history = this.endpointURL.getHistory();
    history.remove(QUARKUS_CODE_URL);
    this.endpointURL.setHistory(history);
    this.updateCustomUrl();
}
 
Example 18
@Override
public boolean handleExternal(PsiElement element, PsiElement originalElement) {
    String val = fetchLiteralForCamelDocumentation(element);
    if (val == null || !ServiceManager.getService(element.getProject(), CamelService.class).isCamelPresent()) {
        return false;
    }

    String name = asComponentName(val);
    Project project = element.getProject();
    CamelCatalog camelCatalog = ServiceManager.getService(project, CamelCatalogService.class).get();
    if (name != null && camelCatalog.findComponentNames().contains(name)) {

        String json = camelCatalog.componentJSonSchema(name);
        ComponentModel component = ModelHelper.generateComponentModel(json, false);

        // to build external links which points to github
        String artifactId = component.getArtifactId();

        String url;
        if ("camel-core".equals(artifactId)) {
            url = GITHUB_EXTERNAL_DOC_URL + "/camel-core/src/main/docs/" + name + "-component.adoc";
        } else {
            url = GITHUB_EXTERNAL_DOC_URL + "/components/" + component.getArtifactId() + "/src/main/docs/" + name + "-component.adoc";
        }

        String hash = component.getTitle().toLowerCase().replace(' ', '-') + "-component";
        BrowserUtil.browse(url + "#" + hash);
        return true;
    }

    return false;
}
 
Example 19
Source Project: intellij   Source File: FileGitHubIssueAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) {
  URL url = getGitHubTemplateURL(project);
  if (url == null) {
    // If, for some reason, we can't construct the URL, open the issues page directly.
    BrowserUtil.browse(BASE_URL);
  } else {
    BrowserUtil.browse(url);
  }
}
 
Example 20
Source Project: azure-devops-intellij   Source File: CreatePullRequestModel.java    License: MIT License 5 votes vote down vote up
private void notifySuccess(final Project project, final String title, final String message) {
    VcsNotifier.getInstance(project).notifyImportantInfo(title, message, new NotificationListener() {
        @Override
        public void hyperlinkUpdate(@NotNull final Notification n, @NotNull final HyperlinkEvent e) {
            BrowserUtil.browse(e.getURL());
        }
    });

    // Update the PR tab and any other UI that is listening for PR Changed events
    EventContextHelper.triggerPullRequestChanged(EventContextHelper.SENDER_CREATE_PULL_REQUEST, project);
}
 
Example 21
Source Project: azure-devops-intellij   Source File: VcsPullRequestsModel.java    License: MIT License 5 votes vote down vote up
public void openGitRepoLink() {
    if (isTfGitRepository()) {
        final ServerContext context = TfGitHelper.getSavedServerContext(gitRepository);
        if (context != null && context.getGitRepository() != null) {
            if (StringUtils.isNotEmpty(context.getGitRepository().getRemoteUrl())) {
                BrowserUtil.browse(context.getGitRepository().getRemoteUrl()
                        .concat(UrlHelper.URL_SEPARATOR).concat("pullrequests"));
            }
        }
    }
}
 
Example 22
Source Project: azure-devops-intellij   Source File: VcsPullRequestsModel.java    License: MIT License 5 votes vote down vote up
public void openSelectedItemsLink() {
    if (isTfGitRepository()) {
        final ServerContext context = TfGitHelper.getSavedServerContext(gitRepository);
        final GitPullRequest pullRequest = getSelectedPullRequest();
        if (context != null && pullRequest != null) {
            BrowserUtil.browse(getPullRequestWebLink(context.getGitRepository().getRemoteUrl(),
                    pullRequest.getPullRequestId()));
        }
    }
}
 
Example 23
Source Project: azure-devops-intellij   Source File: OpenFileInBrowserAction.java    License: MIT License 5 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
    final Project project = anActionEvent.getRequiredData(CommonDataKeys.PROJECT);
    final VirtualFile virtualFile = anActionEvent.getRequiredData(CommonDataKeys.VIRTUAL_FILE);

    final GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
    final GitRepository gitRepository = manager.getRepositoryForFileQuick(virtualFile);
    if (gitRepository == null)
        return;

    final GitRemote gitRemote = TfGitHelper.getTfGitRemote(gitRepository);

    // guard for null so findbugs doesn't complain
    if (gitRemote == null || gitRepository.getRoot() == null) {
        return;
    }

    final String rootPath = gitRepository.getRoot().getPath();
    final String path = virtualFile.getPath();
    final String relativePath = path.substring(rootPath.length());

    String gitRemoteBranchName = StringUtils.EMPTY;
    final GitLocalBranch gitLocalBranch = gitRepository.getCurrentBranch();
    if (gitLocalBranch != null) {
        final GitRemoteBranch gitRemoteBranch = gitLocalBranch.findTrackedBranch(gitRepository);
        if (gitRemoteBranch != null) {
            gitRemoteBranchName = gitRemoteBranch.getNameForRemoteOperations();
        }
    }

    final URI urlToBrowseTo = UrlHelper.getFileURI(gitRemote.getFirstUrl(), encodeVirtualFilePath(relativePath), gitRemoteBranchName);
    logger.info("Browsing to url " + urlToBrowseTo.getPath());
    BrowserUtil.browse(urlToBrowseTo);
}
 
Example 24
private void ensureInitialized() {
    if (!this.initialized) {
        this.verificationUriLink.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (response != null) {
                    BrowserUtil.browse(response.getVerificationUri());
                }
            }
        });
        this.initialized = true;
    }
}
 
Example 25
Source Project: azure-devops-intellij   Source File: AnnotateActionTest.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    PowerMockito.mockStatic(VcsUtil.class, Messages.class, BrowserUtil.class);

    when(mockAnActionEvent.getPresentation()).thenReturn(mockPresentation);
    when(VcsUtil.getOneVirtualFile(mockAnActionEvent)).thenReturn(mockVirtualFile);
    when(mockActionContext.getProject()).thenReturn(mockProject);
    when(mockServerContext.getUri()).thenReturn(serverURI);
    annotateAction = new AnnotateAction();
}
 
Example 26
Source Project: azure-devops-intellij   Source File: AnnotateActionTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testExecute_NullContext() {
    when(mockActionContext.getServerContext()).thenReturn(null);
    annotateAction.execute(mockActionContext);

    verifyStatic(times(1));
    Messages.showErrorDialog(mockProject, TfPluginBundle.message(TfPluginBundle.KEY_ACTIONS_ANNOTATE_ERROR_MSG),
            TfPluginBundle.message(TfPluginBundle.KEY_ACTIONS_ANNOTATE_ERROR_TITLE));
    verifyStatic(times(0));
    BrowserUtil.browse(any(URI.class));
}
 
Example 27
Source Project: azure-devops-intellij   Source File: AnnotateActionTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testExecute_NullTeamProject() {
    when(mockServerContext.getTeamProjectReference()).thenReturn(null);
    when(mockActionContext.getServerContext()).thenReturn(mockServerContext);
    annotateAction.execute(mockActionContext);

    verifyStatic(times(1));
    Messages.showErrorDialog(mockProject, TfPluginBundle.message(TfPluginBundle.KEY_ACTIONS_ANNOTATE_ERROR_MSG),
            TfPluginBundle.message(TfPluginBundle.KEY_ACTIONS_ANNOTATE_ERROR_TITLE));
    verifyStatic(times(0));
    BrowserUtil.browse(any(URI.class));
}
 
Example 28
Source Project: azure-devops-intellij   Source File: AnnotateActionTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testExecute_NullItem() {
    when(mockServerContext.getTeamProjectReference()).thenReturn(mockTeamProjectReference);
    when(mockActionContext.getServerContext()).thenReturn(mockServerContext);
    when(mockActionContext.getItem()).thenReturn(null);
    annotateAction.execute(mockActionContext);

    verifyStatic(times(1));
    Messages.showErrorDialog(mockProject, TfPluginBundle.message(TfPluginBundle.KEY_ACTIONS_ANNOTATE_ERROR_MSG),
            TfPluginBundle.message(TfPluginBundle.KEY_ACTIONS_ANNOTATE_ERROR_TITLE));
    verifyStatic(times(0));
    BrowserUtil.browse(any(URI.class));
}
 
Example 29
Source Project: netbeans-mmd-plugin   Source File: IdeaUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean browseURI(final URI uri, final boolean useInternalBrowser) {
  try {
    BrowserUtil.browse(uri);
  } catch (Exception ex) {
    ex.printStackTrace();
    return false;
  }
  return true;
}
 
Example 30
Source Project: KodeBeagle   Source File: ProjectTree.java    License: Apache License 2.0 5 votes vote down vote up
public final MouseListener getMouseListener(final TreeNode root) {
    return new MouseAdapter() {
        @Override
        public void mouseClicked(final MouseEvent mouseEvent) {
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)
                    windowObjects.getjTree().getLastSelectedPathComponent();
            String url = "";
            if (mouseEvent.isMetaDown() && selectedNode != null
                    && selectedNode.getParent() != null) {
                final String gitUrl = getGitUrl(selectedNode, url, root);
                JPopupMenu menu = new JPopupMenu();

                if (selectedNode.isLeaf()) {
                    final CodeInfo codeInfo = (CodeInfo) selectedNode.getUserObject();

                    menu.add(new JMenuItem(addOpenInNewTabMenuItem(codeInfo))).
                            setText(OPEN_IN_NEW_TAB);
                }

                menu.add(new JMenuItem(new AbstractAction() {
                    @Override
                    public void actionPerformed(final ActionEvent actionEvent) {
                        if (!gitUrl.isEmpty()) {
                            BrowserUtil.browse(GITHUB_LINK + gitUrl);
                        }
                    }
                })).setText(RIGHT_CLICK_MENU_ITEM_TEXT);

                menu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
            }
            doubleClickListener(mouseEvent);
        }
    };
}