static void save(final FileObject fo, final String content) { if (fo == null) throw new NullPointerException(); if (content == null) throw new NullPointerException(); requestProcessor.post( new Runnable() { public void run() { try { FileLock lock = fo.lock(); try { OutputStream os = fo.getOutputStream(lock); Writer writer = new OutputStreamWriter(os, "UTF-8"); // NOI18N try { writer.write(content); } finally { writer.close(); } } finally { lock.releaseLock(); } } catch (IOException ex) { ErrorManager.getDefault().notify(ex); } } }); }
@Override public void actionPerformed(ActionEvent e) { final GitHubIssuePanel p = getPanel(); p.setNewCommentEnabled(false); GitHubIssues gitHubIssues = GitHubIssues.getInstance(); RequestProcessor rp = gitHubIssues.getRequestProcessor(); rp.post( new Runnable() { @Override public void run() { try { String comment = p.getNewComment(); if (StringUtils.isEmpty(comment)) { closeReopen(); } else { Comment newComment = comment(comment); if (newComment != null) { closeReopen(); } } SwingUtilities.invokeLater( new Runnable() { @Override public void run() { p.update(); } }); } finally { p.setNewCommentEnabled(true); } } }); }
@NbBundle.Messages({"GitHubIssueController.delete.comment.fail=Can't delete this issue."}) private void deleteComment() { final Comment deletedComment = getPanel().getDeletedComment(); if (deletedComment == null) { return; } RequestProcessor rp = GitHubIssues.getInstance().getRequestProcessor(); rp.post( new Runnable() { @Override public void run() { GitHubRepository repository = getPanel().getIssue().getRepository(); final boolean success = GitHubIssueSupport.deleteComment(repository, deletedComment); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { if (success) { // remove comment panel getPanel().removeDeletedComment(); } else { // show error message UiUtils.showErrorDialog(Bundle.GitHubIssueController_delete_comment_fail()); } } }); } }); }
public static ClassLoader getReferenceClassLoader() { if (referenceClassLoader != null) { return referenceClassLoader; } REFERENCE_RP .post( new Runnable() { @Override public void run() { if (referenceClassLoader != null) { return; } try { referenceLibrary = copyCompleteJarToTempDir(); referenceClassLoader = new URLClassLoader( new URL[] {Utilities.toURI(referenceLibrary).toURL()}, ClassLoader.getSystemClassLoader()); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } }) .waitFinished(); return referenceClassLoader; }
public void propertyChange(PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if (propertyName == null) return; if ((!JPDABreakpoint.PROP_ENABLED.equals(propertyName)) && (!JPDABreakpoint.PROP_VALIDITY.equals(propertyName)) && (!LineBreakpoint.PROP_CONDITION.equals(propertyName)) && (!LineBreakpoint.PROP_URL.equals(propertyName)) && (!LineBreakpoint.PROP_LINE_NUMBER.equals(propertyName)) // && // (!FieldBreakpoint.PROP_CLASS_NAME.equals( propertyName )) && // (!FieldBreakpoint.PROP_FIELD_NAME.equals( propertyName )) && // (!MethodBreakpoint.PROP_CLASS_FILTERS.equals( propertyName )) && // (!MethodBreakpoint.PROP_CLASS_EXCLUSION_FILTERS.equals( propertyName )) && // (!MethodBreakpoint.PROP_METHOD_NAME.equals( propertyName )) && // (!MethodBreakpoint.PROP_METHOD_SIGNATURE.equals( propertyName ) ) return; // JPDABreakpoint b = (JPDABreakpoint) evt.getSource(); VisageLineBreakpoint b = (VisageLineBreakpoint) evt.getSource(); DebuggerManager manager = DebuggerManager.getDebuggerManager(); Breakpoint[] bkpts = manager.getBreakpoints(); boolean found = false; for (int x = 0; x < bkpts.length; x++) { if (b == bkpts[x]) { found = true; break; } } if (!found) { // breakpoint has been removed return; } rp.post(new AnnotationRefresh(b, true, true)); }
@Override public void actionPerformed(ActionEvent ev) { // Start JSLintRunnable if (processor == null) { processor = new RequestProcessor("JSLintErrorCheck", 1, true); } processor.post(new JSLintRunnable(context, "-e")); }
public @Override void actionPerformed(ActionEvent e) { RP.post( new Runnable() { @Override public void run() { DDHelper.addJsfListener(serverProject, webProject); } }); } // class
@Override public void run() { if (!SwingUtilities.isEventDispatchThread()) { EventQueue.invokeLater(this); return; } currentToken = new Object(); TopComponent.Registry registry = TopComponent.getRegistry(); final TopComponent activeTc = registry.getActivated(); final Set<TopComponent> opened = new HashSet<>(registry.getOpened()); final LayoutScene existingLayers = currentLayers; final boolean isMaximized = isLayersMaximized(); final Object token = currentToken; RP.post( () -> { findNewLayers(existingLayers, activeTc, opened, isMaximized, token); }); }
@NbBundle.Messages({ "GitHubIssueController.edit.comment.title=Edit Comment", "GitHubIssueController.edit.comment.fail=Can't edit this comment." }) private void editComment() { final Comment comment = getPanel().getEditedComment(); final String editedBody = CommentTabbedPanel.showDialog( Bundle.GitHubIssueController_edit_comment_title(), comment.getBody()); if (editedBody != null) { final GitHubIssue issue = getPanel().getIssue(); if (issue != null) { RequestProcessor rp = GitHubIssues.getInstance().getRequestProcessor(); rp.post( new Runnable() { @Override public void run() { Comment editedComment = issue.editComment(comment, editedBody); if (editedComment == null) { UiUtils.showErrorDialog(Bundle.GitHubIssueController_edit_comment_fail()); return; } SwingUtilities.invokeLater( new Runnable() { @Override public void run() { getPanel().loadComments(); } }); } }); } } }
@Override public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); final boolean isNewPullRequest = actionCommand.equals("New PR"); // NOI18N GitHubIssuePanel p = getPanel(); p.setCreatePullRequestButtonEnabled(false); final GitHubIssue issue = p.getIssue(); if (isNewPullRequest && !p.isNewPullRequestSelected()) { // remove the new pull request from the panle SwingUtilities.invokeLater( new Runnable() { @Override public void run() { getPanel().setNewPullRequest(null); } }); return; } RequestProcessor rp = GitHubIssues.getInstance().getRequestProcessor(); rp.post( new Runnable() { @Override public void run() { final GitHubRepository repository = issue.getRepository(); GitHubCache cache = GitHubCache.create(repository); final User mySelf = cache.getMySelf(); List<RepositoryBranch> baseBranches = cache.getBranches(true); final HashMap<Repository, List<RepositoryBranch>> baseRepositories = new HashMap<>(); baseRepositories.put(repository.getRepository(), baseBranches); final Map<Repository, List<RepositoryBranch>> headRepositories = getHeadRepositories(repository, baseBranches); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { try { if (baseRepositories.isEmpty() || headRepositories.isEmpty()) { UiUtils.showErrorDialog( Bundle .CreatePullRequestAction_error_message_cannot_find_base_head_repositories()); return; } // create descriptor final CreatePullRequestPanel createPullRequestPanel = new CreatePullRequestPanel(baseRepositories, headRepositories); createPullRequestPanel.setMessage( Bundle.CreatePullRequestAction_confirmation_message()); final NotifyDescriptor.Confirmation descriptor = new NotifyDescriptor.Confirmation( createPullRequestPanel, Bundle.CreatePullRequestAction_descriptor_title(), NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE); // add listeners ChangeListener changeListener = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { descriptor.setValid(false); createPullRequestPanel.setErrorMessage(""); // NOI18N } }; createPullRequestPanel.addChangeListener(changeListener); ComparePullRequestPropertyChangeListener propertyChangeListener = new ComparePullRequestPropertyChangeListener( repository, createPullRequestPanel, descriptor); createPullRequestPanel.addPropertyChangeListener(propertyChangeListener); changeListener.stateChanged(null); // show dialog if (DialogDisplayer.getDefault().notify(descriptor) == NotifyDescriptor.OK_OPTION) { RepositoryBranch selectedBaseBranch = createPullRequestPanel.getSelectedBaseBranch(); RepositoryBranch selectedHeadBranch = createPullRequestPanel.getSelectedHeadBranch(); String baseBranch = selectedBaseBranch.getName(); String headBranch = mySelf.getLogin() + ":" + selectedHeadBranch.getName(); // NOI18N PullRequest pullRequest; try { if (isNewPullRequest) { // set new pull request to panel PullRequestMarker baseMarker = new PullRequestMarker(); baseMarker.setLabel(baseBranch); PullRequestMarker headMarker = new PullRequestMarker(); headMarker.setLabel(headBranch); PullRequest newPullRequest = new PullRequest().setBase(baseMarker).setHead(headMarker); getPanel().setNewPullRequest(newPullRequest); } else { pullRequest = issue.createPullRequest(headBranch, baseBranch); if (pullRequest != null) { getPanel().refresh(); } } } catch (IOException ex) { UiUtils.showErrorDialog( "Can't create a pull request:" + ex.getMessage()); // NOI18N } } else if (isNewPullRequest) { getPanel().setNewPullRequestSelected(false); } // remove listeners createPullRequestPanel.removeChangeListener(changeListener); createPullRequestPanel.removePropertyChangeListener(propertyChangeListener); } finally { getPanel().setCreatePullRequestButtonEnabled(true); } } }); } }); }
@NbBundle.Messages({ "SubmitIssueAction.message.pull.request.added.fail=The pull request has not been added.", "SubmitIssueAction.message.issue.added.fail=The issue has not been added.", "SubmitIssueAction.message.issue.updated.fail=The issue has not been updated." }) @Override public void actionPerformed(ActionEvent e) { final GitHubIssuePanel p = getPanel(); p.setSubmitButtonEnabled(false); RequestProcessor rp = GitHubIssues.getInstance().getRequestProcessor(); rp.post( new Runnable() { @Override public void run() { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { GitHubIssue issue = p.getIssue(); CreateIssueParams issueParams = getCreateIssueParams(issue.isNew(), p); if (issue.isNew()) { if (p.isNewPullRequestSelected()) { // add pull request // can be added only title and body to a pull request // add other than those after the pull request was created PullRequest newPullRequest = p.getNewPullRequest(); if (newPullRequest != null) { newPullRequest .setTitle(issueParams.getTitle()) .setBody(issueParams.getBody()); try { PullRequest createdPullRequest = issue.createPullRequest(newPullRequest); if (createdPullRequest != null) { issue.editIssue(issueParams); p.update(); } else { // show dialog UiUtils.showErrorDialog( Bundle.SubmitIssueAction_message_pull_request_added_fail()); } } catch (IOException ex) { UiUtils.showErrorDialog(ex.getMessage()); } } } else { // add issue Issue newIssue = issue.submitNewIssue(issueParams); if (newIssue != null) { p.update(); } else { // show dialog UiUtils.showErrorDialog( Bundle.SubmitIssueAction_message_issue_added_fail()); } } } else { // edit issue Issue editIssue = issue.editIssue(issueParams); if (editIssue != null) { p.update(); } else { // show dialog UiUtils.showErrorDialog( Bundle.SubmitIssueAction_message_issue_updated_fail()); } } p.setSubmitButtonEnabled(true); } }); } }); }
public Task run() { ClassLoader targetLoader; if (target.contains("sharwell/optimized")) { targetLoader = Thread.currentThread().getContextClassLoader(); } else { targetLoader = getReferenceClassLoader(); } if (targetLoader == null) { return RequestProcessor.Task.EMPTY; } final ClassLoader loader = targetLoader; return REFERENCE_RP.post( new Runnable() { @Override public void run() { try { Class<?> toolClass = loader.loadClass(Tool.class.getName()); Constructor<?> ctor = toolClass.getConstructor(String[].class); Method processGrammarsOnCommandLine = toolClass.getMethod("processGrammarsOnCommandLine"); List<String> args = getCommandArguments(); for (FileObject grammarFile : grammarFiles) { args.add(FileUtil.toFile(grammarFile).getAbsolutePath()); } ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(loader); try { InputOutput inputOutput = IOProvider.getDefault() .getIO(String.format("ANTLR Codegen (%s)", target), false); inputOutput.select(); PrintStream originalOut = System.out; try (OutputWriter outputWriter = inputOutput.getOut()) { System.setOut(new PrintStream(new OutputWriterStream(outputWriter))); try { PrintStream originalErr = System.err; try (OutputWriter errorWriter = inputOutput.getErr()) { System.setErr(new PrintStream(new OutputWriterStream(errorWriter))); try { outputWriter.format("Arguments: %s%n", args); Object tool = ctor.newInstance((Object) args.toArray(new String[args.size()])); processGrammarsOnCommandLine.invoke(tool); } finally { System.setErr(originalErr); } } } finally { System.setOut(originalOut); } } } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); } } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { Exceptions.printStackTrace(ex); } } }); }