Exemplo n.º 1
0
 @Override
 public Object getValueAt(int rowIndex, int columnIndex) {
   if (currentAction.getAction() instanceof AdaptableAction) {
     if (rowIndex < 2) {
       switch (columnIndex) {
         case 0:
           return rowIndex == 0 ? tr("Tooltip") : tr("Icon");
         case 1:
           return rowIndex == 0 ? currentAction.getName() : currentAction.getIcon();
         default:
           return null;
       }
     } else {
       rowIndex -= 2;
     }
   }
   ActionParameter<Object> param = getParam(rowIndex);
   switch (columnIndex) {
     case 0:
       return param.getName();
     case 1:
       return param.writeToString(currentAction.getParameters().get(param.getName()));
     default:
       return null;
   }
 }
Exemplo n.º 2
0
    public ActionDefinition loadAction(String actionName) {
      index = 0;
      this.s = actionName.toCharArray();

      String name = readTillChar('(', '{');
      Action action = actions.get(name);

      if (action == null) return null;

      ActionDefinition result = new ActionDefinition(action);

      if (action instanceof ParameterizedAction) {
        skip('(');

        ParameterizedAction parametrizedAction = (ParameterizedAction) action;
        Map<String, ActionParameter<?>> actionParams = new HashMap<String, ActionParameter<?>>();
        for (ActionParameter<?> param : parametrizedAction.getActionParameters()) {
          actionParams.put(param.getName(), param);
        }

        while (index < s.length && s[index] != ')') {
          String paramName = readTillChar('=', '=');
          skip('=');
          String paramValue = readTillChar(',', ')');
          if (paramName.length() > 0) {
            ActionParameter<?> actionParam = actionParams.get(paramName);
            if (actionParam != null) {
              result.getParameters().put(paramName, actionParam.readFromString(paramValue));
            }
          }
          skip(',');
        }
        skip(')');
      }
      if (action instanceof AdaptableAction) {
        skip('{');

        while (index < s.length && s[index] != '}') {
          String paramName = readTillChar('=', '=');
          skip('=');
          String paramValue = readTillChar(',', '}');
          if ("icon".equals(paramName) && paramValue.length() > 0) {
            result.setIcon(paramValue);
          } else if ("name".equals(paramName) && paramValue.length() > 0) {
            result.setName(paramValue);
          }
          skip(',');
        }
        skip('}');
      }

      return result;
    }
Exemplo n.º 3
0
    @SuppressWarnings("unchecked")
    public String saveAction(ActionDefinition action) {
      result.setLength(0);

      String val = (String) action.getAction().getValue("toolbar");
      if (val == null) return null;
      escape(val);
      if (action.getAction() instanceof ParameterizedAction) {
        result.append('(');
        List<ActionParameter<?>> params =
            ((ParameterizedAction) action.getAction()).getActionParameters();
        for (int i = 0; i < params.size(); i++) {
          ActionParameter<Object> param = (ActionParameter<Object>) params.get(i);
          escape(param.getName());
          result.append('=');
          Object value = action.getParameters().get(param.getName());
          if (value != null) {
            escape(param.writeToString(value));
          }
          if (i < params.size() - 1) {
            result.append(',');
          } else {
            result.append(')');
          }
        }
      }
      if (action.getAction() instanceof AdaptableAction) {
        boolean first = true;
        String tmp = action.getName();
        if (tmp.length() != 0) {
          result.append(first ? "{" : ",");
          result.append("name=");
          escape(tmp);
          first = false;
        }
        tmp = action.getIcon();
        if (tmp.length() != 0) {
          result.append(first ? "{" : ",");
          result.append("icon=");
          escape(tmp);
          first = false;
        }
        if (!first) {
          result.append('}');
        }
      }

      return result.toString();
    }
Exemplo n.º 4
0
 @Override
 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
   if (currentAction.getAction() instanceof AdaptableAction) {
     if (rowIndex == 0) {
       currentAction.setName((String) aValue);
       return;
     } else if (rowIndex == 1) {
       currentAction.setIcon((String) aValue);
       return;
     } else {
       rowIndex -= 2;
     }
   }
   ActionParameter<Object> param = getParam(rowIndex);
   currentAction.getParameters().put(param.getName(), param.readFromString((String) aValue));
 }