/** * Handles the given action based on the command type. If the command is "addBug" then creates a * new bug. If the command is "commentBug" then creates a new comment for the given bug. Otherwise * changes the status of the given bug. * * @param action A <code>MapdustAction</code> object * @throws MapdustServiceHandlerException If there was some error during the upload to MapDust * service */ private void dispatchAction(MapdustAction action) throws MapdustServiceHandlerException { if (action.getCommand().equals(MapdustServiceCommand.ADD_BUG)) { /* create new bug */ handler.addBug(action.getMapdustBug()); } else { if (action.getCommand().equals(MapdustServiceCommand.COMMENT_BUG)) { /* comment bug */ handler.commentBug(action.getMapdustComment()); } else { /* change bug status */ handler.changeBugStatus(action.getNewStatus(), action.getMapdustComment()); } } }
/** * Closes the given MapDust bug. If the entered informations are invalid a corresponding warning * message will be displayed. * * @param event The action event which fires this action */ @Override public void actionPerformed(ActionEvent event) { if (event.getSource() instanceof JButton) { JButton btn = (JButton) event.getSource(); if (btn.getText().equals("OK")) { /* the OK button was pressed */ ChangeBugStatusDialog issueDialog = (ChangeBugStatusDialog) getDialog(); String nickname = issueDialog.getTxtNickname().getText(); String commentText = issueDialog.getTxtDescription().getText(); /* validate nickname & comment text */ String errorMessage = validate(nickname, commentText); if (errorMessage != null) { /* invalid input data */ JOptionPane.showMessageDialog( Main.parent, tr(errorMessage), tr("Missing input data"), JOptionPane.WARNING_MESSAGE); return; } /* valid input data */ Main.pref.put("mapdust.nickname", nickname); MapdustBug selectedBug = mapdustGUI.getSelectedBug(); MapdustComment comment = new MapdustComment(selectedBug.getId(), commentText, nickname); String pluginState = Main.pref.get("mapdust.pluginState"); if (pluginState.equals(MapdustPluginState.OFFLINE.getValue())) { /* offline state, put to the actions list */ selectedBug.setStatus(Status.FIXED); String iconPath = getIconPath(selectedBug); MapdustAction mapdustAction = new MapdustAction( MapdustServiceCommand.CHANGE_BUG_STATUS, iconPath, selectedBug, comment, 2); /* destroy dialog */ enableFiredButton(issueDialog.getFiredButton()); mapdustGUI.enableBtnPanel(true); issueDialog.dispose(); if (getMapdustGUI().getActionPanel() != null) { notifyObservers(mapdustAction); } } else { /* online state, execute Mapdust service method */ MapdustServiceHandler handler = new MapdustServiceHandler(); Long id = null; try { id = handler.changeBugStatus(2, comment); } catch (MapdustServiceHandlerException e) { errorMessage = "There was a Mapdust service error."; JOptionPane.showMessageDialog( Main.parent, tr(errorMessage), tr("Error"), JOptionPane.ERROR_MESSAGE); } if (id != null) { // success MapdustBug newMapdustBug = null; try { newMapdustBug = handler.getBug(selectedBug.getId(), null); } catch (MapdustServiceHandlerException e) { errorMessage = "There was a Mapdust service error."; JOptionPane.showMessageDialog( Main.parent, tr(errorMessage), tr("Error"), JOptionPane.ERROR_MESSAGE); } /* destroy dialog */ enableFiredButton(issueDialog.getFiredButton()); mapdustGUI.enableBtnPanel(false); issueDialog.dispose(); if (newMapdustBug != null) { notifyObservers(newMapdustBug); } } } } } }