/** @return The body text of the expression. */ public String getBody() { Object expression = getExpression(); if (expression == null) { return EMPTYSTRING; } return Model.getDataTypesHelper().getBody(expression); }
/** @param lang the language of the expression */ public void setLanguage(String lang) { Object expression = getExpression(); boolean mustChange = true; if (expression != null) { String oldValue = Model.getDataTypesHelper().getLanguage(expression); if (oldValue != null && oldValue.equals(lang)) { mustChange = false; } } if (mustChange) { String body = EMPTYSTRING; if (expression != null && Model.getDataTypesHelper().getBody(expression) != null) { body = Model.getDataTypesHelper().getBody(expression); } setExpression(lang, body); } }
/** * Update an existing Action with a new Script. * * @author MVW * @param old the Action * @param s a string representing a new Script for the ActionExpression */ private void updateAction(Object old, String s) { Object ae = Model.getFacade().getScript(old); // the ActionExpression String language = LANGUAGE; if (ae != null) { language = Model.getDataTypesHelper().getLanguage(ae); String body = (String) Model.getFacade().getBody(ae); if (body.equals(s)) { return; } } ae = Model.getDataTypesFactory().createActionExpression(language, s); Model.getCommonBehaviorHelper().setScript(old, ae); }
/** * This is only called if we already know that the values differ. * * @param lang the language of the expression * @param body the body text of the expression */ private void setExpression(String lang, String body) { if (Model.getFacade().getUmlVersion().charAt(0) == '1') { // Expressions are DataTypes, not independent model elements // be careful not to reuse them final Object currentExpression = getExpression(); if (currentExpression != null) { LOG.log(Level.INFO, "Deleting the current expression {0}", currentExpression); Model.getUmlFactory().delete(currentExpression); } final Object newExpression; if (lang.length() == 0 && body.length() == 0) { newExpression = null; } else { newExpression = newExpression(lang, body); } setExpression(newExpression); } else { // reuse Opaque..., just set it's attributes Object expression = getExpression(); Model.getDataTypesHelper().setBody(expression, body); Model.getDataTypesHelper().setLanguage(expression, lang); } }
/** * Find the Icon for a given model element. * * @return The Icon or <code>null</code> if there is no Icon. * @param value The model element. * <p>TODO: This should not use string matching on classnames to do this since this means that * we have knowledge about how the model elements are implemented outside of the Model * component. */ public Icon lookupIcon(Object value) { if (value == null) { throw new IllegalArgumentException("Attempted to get an icon given a null key"); } if (value instanceof String) { return null; } Icon icon = iconCache.get(value.getClass()); try { if (Model.getFacade().isAPseudostate(value)) { Object kind = Model.getFacade().getKind(value); DataTypesHelper helper = Model.getDataTypesHelper(); if (helper.equalsINITIALKind(kind)) { icon = initialStateIcon; } if (helper.equalsDeepHistoryKind(kind)) { icon = deepIcon; } if (helper.equalsShallowHistoryKind(kind)) { icon = shallowIcon; } if (helper.equalsFORKKind(kind)) { icon = forkIcon; } if (helper.equalsJOINKind(kind)) { icon = joinIcon; } if (helper.equalsCHOICEKind(kind)) { icon = branchIcon; } if (helper.equalsJUNCTIONKind(kind)) { icon = junctionIcon; } // if (MPseudostateKind.FINAL.equals(kind)) // icon = _FinalStateIcon; } if (Model.getFacade().isAAbstraction(value)) { icon = realizeIcon; } if (Model.getFacade().isAException(value)) { icon = exceptionIcon; } else { // needs more work: sending and receiving icons if (Model.getFacade().isASignal(value)) { icon = signalIcon; } } if (Model.getFacade().isAComment(value)) { icon = commentIcon; } if (icon == null) { String cName = Model.getMetaTypes().getName(value); icon = lookupIconResource(cName); if (icon == null) { LOG.log(Level.FINE, "Can't find icon for {0}", cName); } else { synchronized (iconCache) { iconCache.put(value.getClass(), icon); } } } } catch (InvalidElementException e) { LOG.log(Level.FINE, "Attempted to get icon for deleted element"); return null; } return icon; }