List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction()
From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java
/** * shows/hides the buttons for switching to states default path * @param bVisible/*w w w . ja v a2 s . c om*/ * @param bEnableButtons */ private void setStatesDefaultPathVisible(boolean bVisible, boolean bEnableButtons) { // remove all previous listeners: cmpStateStandardView.removeActionListeners(); // initialize: cmpStateStandardView.removeAllItems(); cmpStateStandardView.setSelectedItem(null); if (!bVisible) cmpStateStandardView.setVisible(false); else { cmpStateStandardView.setVisible(true); cmpStateStandardView.setEnabled(bEnableButtons); // Create a temporary list for sorting the entries before entering into combo box final List<StateWrapper> lstDefaultPathEntries = new ArrayList<StateWrapper>(); final StateWrapper stateCurrent = getStateWrapperFromSelectedGenericObject(); UsageCriteria uc = null; List<StateVO> lstDefaultPathStates = new ArrayList<StateVO>(); try { uc = getSelectedCollectable() == null ? getUsageCriteriaFromView(false) : getUsageCriteria(getSelectedCollectable()); lstDefaultPathStates.addAll(StateDelegate.getInstance().getStatemodel(uc).getDefaultStatePath()); } catch (Exception e) { // ignore } // Copy all subsequent states to the sorting list: for (StateVO statevo : lstDefaultPathStates) if (statevo == null) // we don't want to throw an exception here, so we just log the error: LOG.error("Die Liste der Folgestati enth\u00e4lt ein null-Objekt."); else if (!lstDefaultPathEntries.contains(new StateWrapper(statevo.getId(), statevo.getNumeral(), statevo.getStatename(), statevo.getIcon(), statevo.getDescription(), null, null))) lstDefaultPathEntries.add(new StateWrapper(statevo.getId(), statevo.getNumeral(), getSpringLocaleDelegate() .getResource(/*StateDelegate.getInstance().getResourceSIdForName(statevo.getId()*/ StateDelegate.getInstance().getStatemodelClosure(getModuleId()) .getResourceSIdForLabel(statevo.getId()), statevo.getStatename()), statevo.getIcon(), statevo.getDescription(), statevo.getColor(), statevo.getButtonIcon(), statevo.isFromAutomatic(), getSelectedCollectable() != null ? StateDelegate.getInstance().getStatemodel(uc) .isStateReachableInDefaultPath(stateCurrent.getId(), statevo) : StateDelegate.getInstance().getStatemodel(uc) .isStateReachableInDefaultPathByNumeral(stateCurrent.getNumeral(), statevo))); cmpStateStandardView.setSelectedItem( getSelectedCollectable() == null || getSelectedCollectable().getId() == null ? null : stateCurrent); cmpStateStandardView.addItems(lstDefaultPathEntries); for (Iterator<StateWrapper> iterator = lstDefaultPathEntries.iterator(); iterator.hasNext();) { final StateWrapper item = iterator.next(); final ActionListener al = new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { UIUtils.runShortCommand(getTab(), new CommonRunnable() { @Override public void run() { if (item != stateCurrent && item != null && item.getId() != null) { cmdChangeStates(stateCurrent, item, item.getStatesBefore()); } } }); } }; cmpStateStandardView.addActionListener(al, item); if (LangUtils.equals(stateCurrent.getNumeral(), item.getNumeral())) { final List<StateWrapper> lstSubsequentEntries = new ArrayList<StateWrapper>(); List<StateVO> lstSubsequentStates = StateDelegate.getInstance().getStatemodel(uc) .getSubsequentStates(item.getId(), false); // Copy all subsequent states to the sorting list: for (StateVO statevo : lstSubsequentStates) if (statevo == null) // we don't want to throw an exception here, so we just log the error: LOG.error("Die Liste der Folgestati enth\u00e4lt ein null-Objekt."); else if (!lstSubsequentEntries.contains( new StateWrapper(statevo.getId(), statevo.getNumeral(), statevo.getStatename(), statevo.getIcon(), statevo.getDescription(), null, null))) lstSubsequentEntries.add(new StateWrapper(statevo.getId(), statevo.getNumeral(), getSpringLocaleDelegate() .getResource(/*StateDelegate.getInstance().getResourceSIdForName(statevo.getId()*/ StateDelegate.getInstance().getStatemodelClosure(getModuleId()) .getResourceSIdForLabel(statevo.getId()), statevo.getStatename()), statevo.getIcon(), statevo.getDescription(), statevo.getColor(), statevo.getButtonIcon())); Map<StateWrapper, Action> mpSubsequentStatesAction = new HashMap<StateWrapper, Action>(); for (Iterator<StateWrapper> iterator2 = lstSubsequentEntries.iterator(); iterator2.hasNext();) { final StateWrapper subsequentState = iterator2.next(); if (!subsequentState.getNumeral().equals(item.getNumeral())) { Action act = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cmdChangeState(subsequentState); } }; mpSubsequentStatesAction.put(subsequentState, act); } } cmpStateStandardView.addSubsequentStatesActionListener(item, mpSubsequentStatesAction); } } } cmpStateStandardView.setEnabled(getSelectedCollectable() == null ? false : (bEnableButtons && cmpStateStandardView.getItemCount() != 0)); }