Author: bobtarling Date: 2009-12-31 08:24:56-0800 New Revision: 17714 Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionBodyField.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionLanguageField.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionModel.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLMethodSpecificationComboBoxModel.java Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/meta/panels.xml trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManager.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManagerImpl.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SingleListFactory.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java
Log: Complete the method panel Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/meta/panels.xml Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/meta/panels.xml?view=diff&pathrev=17714&r1=17713&r2=17714 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/meta/panels.xml (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/meta/panels.xml 2009-12-31 08:24:56-0800 @@ -686,22 +686,23 @@ </panel> <panel name="Method"> <text name="name" type="Name" /> + <singlerow name="owner" type="Classifier" /> + <combo name="specification" type="Operation" /> + <list name="clientDependency" type="Dependency" /> + <list name="supplierDependency" type="ModelElement" /> + <separator /> <optionbox name="visibility" type="VisibilityKind" /> <checkgroup name="modifiers"> <checkbox name="isSpecification" type="Boolean" /> <checkbox name="isQuery" type="Boolean" /> <checkbox name="ownerScope" type="ScopeKind" /> </checkgroup> - <combo name="namespace" type="Namespace" /> - <list name="clientDependency" type="Dependency" /> - <list name="supplierDependency" type="ModelElement" /> <separator /> + <textarea name="body" type="ProcedureExpression" /> <list name="behavior" type="ModelElement" /> <list name="classifierRole" type="ModelElement" /> <list name="collaboration" type="ModelElement" /> <list name="collaborationInstanceSet" type="ModelElement" /> - <text name="body" type="ProcedureExpression" /> - <attribute name="specification" type="Operation" /> <!-- <list name="presentation" type="ModelElement" /> <list name="defaultedParameter" type="ModelElement" /> Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManager.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManager.java?view=diff&pathrev=17714&r1=17713&r2=17714 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManager.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManager.java 2009-12-31 08:24:56-0800 @@ -41,6 +41,8 @@ * @return the UML element or property */ public abstract Object get(Object umlElement, String propertyName, String type); + + public abstract Object create(String propertyName, String language, String body); public abstract Collection getOptions(Object umlElement, String propertyName, String type); @@ -62,6 +64,11 @@ abstract void set(Object modelElement, Object value); } + protected abstract class ExpressionGetterSetter extends BaseGetterSetter { + abstract Object create(String language, String body); + } + + protected abstract class OptionGetterSetter extends BaseGetterSetter { private Collection options; Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManagerImpl.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManagerImpl.java?view=diff&pathrev=17714&r1=17713&r2=17714 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManagerImpl.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManagerImpl.java 2009-12-31 08:24:56-0800 @@ -55,6 +55,8 @@ addGetterSetter("changeability", new ChangeabilityGetterSetter()); addGetterSetter("concurrency", new ConcurrencyGetterSetter()); addGetterSetter("feature", new FeatureGetterSetter()); + addGetterSetter("stimulus", new StimuliGetterSetter()); + addGetterSetter("body", new MethodExpressionGetterSetter()); } /** @@ -103,6 +105,16 @@ return null; } + + public Object create(String propertyName, String language, String body) { + BaseGetterSetter bgs = getterSetterByPropertyName.get(propertyName); + if (bgs instanceof ExpressionGetterSetter) { + return ((ExpressionGetterSetter) bgs).create(language, body); + } + + return null; + } + public boolean isValidElement(String propertyName, String type, Object element) { BaseGetterSetter bgs = getterSetterByPropertyName.get(propertyName); if (bgs instanceof ListGetterSetter) { @@ -542,7 +554,7 @@ } } - protected class FeatureGetterSetter extends ListGetterSetter { + private class FeatureGetterSetter extends ListGetterSetter { public Collection getOptions(Object modelElement, String type) { if ("Attribute".equals(type)) { @@ -554,7 +566,7 @@ } } - public Collection get(Object modelElement, String type) { + public Object get(Object modelElement, String type) { // not needed return null; } @@ -573,7 +585,51 @@ return false; } - return get(element, type).contains(element); + return getOptions(element, type).contains(element); + } + + public Object getMetaType() { + return Model.getMetaTypes().getAttribute(); + } + } + + + private class MethodExpressionGetterSetter extends ExpressionGetterSetter { + + @Override + public Object get(Object modelElement, String type) { + return Model.getFacade().getBody(modelElement); + } + + @Override + public void set(Object modelElement, Object value) { + Model.getCoreHelper().setBody(modelElement, value); + } + + @Override + Object create(final String language, final String body) { + return Model.getDataTypesFactory().createProcedureExpression(language, body); + } + } + + private class StimuliGetterSetter extends ListGetterSetter { + + public Collection getOptions(Object modelElement, String type) { + return Model.getFacade().getReceivedStimuli(modelElement); + } + + public Object get(Object modelElement, String type) { + // not needed + return null; + } + + public void set(Object element, Object x) { + // not needed + } + + protected boolean isValidElement(Object element, String type) { + + return getOptions(element, type).contains(element); } public Object getMetaType() { Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionBodyField.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionBodyField.java?view=markup&pathrev=17714 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionBodyField.java 2009-12-31 08:24:56-0800 @@ -0,0 +1,110 @@ +/* $Id$ + ******************************************************************************* + * Copyright (c) 2009 Contributors - see below + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bob Tarling + ******************************************************************************* + */ + +// $Id: UMLExpressionBodyField.java 17560 2009-11-30 06:56:31Z mvw $ +// Copyright (c) 1996-2009 The Regents of the University of California. All +// Rights Reserved. Permission to use, copy, modify, and distribute this +// software and its documentation without fee, and without a written +// agreement is hereby granted, provided that the above copyright notice +// and this paragraph appear in all copies. This software program and +// documentation are copyrighted by The Regents of the University of +// California. The software program and documentation are supplied "AS +// IS", without any accompanying services from The Regents. The Regents +// does not warrant that the operation of the program will be +// uninterrupted or error-free. The end-user understands that the program +// was developed for research purposes and is advised not to rely +// exclusively on the program for any reason. IN NO EVENT SHALL THE +// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, +// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, +// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF +// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE +// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF +// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, +// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +package org.argouml.core.propertypanels.ui; +import javax.swing.JTextArea; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import org.apache.log4j.Logger; +import org.argouml.i18n.Translator; +import org.argouml.ui.LookAndFeelMgr; + +/** + * This text field shows the body of a UML expression. + * + */ +class ExpressionBodyField extends JTextArea + implements DocumentListener { + + /** + * Logger. + */ + private static final Logger LOG = + Logger.getLogger(ExpressionBodyField.class); + + private ExpressionModel model; + + /** + * The constructor. + * + * @param expressionModel + * Expression model, should be shared between Language and Body + * fields + */ + public ExpressionBodyField(ExpressionModel expressionModel) { + model = expressionModel; + getDocument().addDocumentListener(this); + setToolTipText(Translator.localize("label.body.tooltip")); + setFont(LookAndFeelMgr.getInstance().getStandardFont()); + setRows(2); // make it stretch vertically + + update(); + } + + void update() { + String oldText = getText(); + String newText = model.getBody(); + + if (oldText == null || newText == null || !oldText.equals(newText)) { + if (oldText != newText) { + setText(newText); + } + } + } + + /* + * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent) + */ + public void changedUpdate(final DocumentEvent p1) { + model.setBody(getText()); + } + + /* + * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent) + */ + public void removeUpdate(final DocumentEvent p1) { + model.setBody(getText()); + } + + /* + * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent) + */ + public void insertUpdate(final DocumentEvent p1) { + model.setBody(getText()); + } +} Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionLanguageField.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionLanguageField.java?view=markup&pathrev=17714 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionLanguageField.java 2009-12-31 08:24:56-0800 @@ -0,0 +1,98 @@ +/* $Id: SwingUIFactory.java 17700 2009-12-23 10:40:18Z bobtarling $ + ******************************************************************************* + * Copyright (c) 2009 Contributors - see below + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bob Tarling + ******************************************************************************* + */ + +// $Id: UMLExpressionLanguageField.java 17560 2009-11-30 06:56:31Z mvw $ +// Copyright (c) 1996-2009 The Regents of the University of California. All +// Rights Reserved. Permission to use, copy, modify, and distribute this +// software and its documentation without fee, and without a written +// agreement is hereby granted, provided that the above copyright notice +// and this paragraph appear in all copies. This software program and +// documentation are copyrighted by The Regents of the University of +// California. The software program and documentation are supplied "AS +// IS", without any accompanying services from The Regents. The Regents +// does not warrant that the operation of the program will be +// uninterrupted or error-free. The end-user understands that the program +// was developed for research purposes and is advised not to rely +// exclusively on the program for any reason. IN NO EVENT SHALL THE +// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, +// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, +// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF +// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE +// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF +// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, +// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +package org.argouml.core.propertypanels.ui; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import org.argouml.i18n.Translator; +import org.argouml.ui.LookAndFeelMgr; + +/** + * This text field shows the language of a UML expression. + */ +class ExpressionLanguageField extends JTextField implements + DocumentListener { + + private ExpressionModel model; + + /** + * Creates a new field that selects the language for an expression. + * + * @param m Expression model, should be shared between + * Language and Body fields + */ + public ExpressionLanguageField(ExpressionModel m) { + model = m; + getDocument().addDocumentListener(this); + setToolTipText(Translator.localize("label.language.tooltip")); + setFont(LookAndFeelMgr.getInstance().getStandardFont()); + update(); + } + + void update() { + String oldText = getText(); + String newText = model.getLanguage(); + if (oldText == null || newText == null || !oldText.equals(newText)) { + if (oldText != newText) { + setText(newText); + } + } + } + + /* + * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent) + */ + public void changedUpdate(final DocumentEvent p1) { + model.setLanguage(getText()); + } + + /* + * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent) + */ + public void removeUpdate(final DocumentEvent p1) { + model.setLanguage(getText()); + } + + /* + * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent) + */ + public void insertUpdate(final DocumentEvent p1) { + model.setLanguage(getText()); + } +} Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionModel.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionModel.java?view=markup&pathrev=17714 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ExpressionModel.java 2009-12-31 08:24:56-0800 @@ -0,0 +1,291 @@ +/* $Id$ + ******************************************************************************* + * Copyright (c) 2009 Contributors - see below + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bob Tarling + ******************************************************************************* + */ + +// $Id: UMLExpressionModel.java 17560 2009-11-30 06:56:31Z mvw $ +// Copyright (c) 1996-2009 The Regents of the University of California. All +// Rights Reserved. Permission to use, copy, modify, and distribute this +// software and its documentation without fee, and without a written +// agreement is hereby granted, provided that the above copyright notice +// and this paragraph appear in all copies. This software program and +// documentation are copyrighted by The Regents of the University of +// California. The software program and documentation are supplied "AS +// IS", without any accompanying services from The Regents. The Regents +// does not warrant that the operation of the program will be +// uninterrupted or error-free. The end-user understands that the program +// was developed for research purposes and is advised not to rely +// exclusively on the program for any reason. IN NO EVENT SHALL THE +// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, +// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, +// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF +// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE +// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF +// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, +// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +package org.argouml.core.propertypanels.ui; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.EventListenerList; + +import org.apache.log4j.Logger; +import org.argouml.core.propertypanels.model.GetterSetterManager; +import org.argouml.model.Model; + +/** + * The model for Expressions. + * The target is the UML element to which this Expression is attached. + * + * The ChangeEvent/ChangeListener handling is inspired by + * javax.swing.DefaultBoundedRangeModel. + * It listens to UML model changes not caused by us, + * which need to trigger an update of the UI rendering. + * + * @author mkl, penyaskito, mvw + */ +class ExpressionModel implements PropertyChangeListener { + + private static final Logger LOG = + Logger.getLogger(ExpressionModel.class); + + private Object target; + private String propertyName; + + /** This member is only used when we set the expression ourselves. + * In this case, we do not wish to receive UML model change events + * for this self-inflicted change. + * So, this member is used to detect this situation. */ + private Object rememberExpression; + + private final GetterSetterManager getterSetterManager; + + private final String type; + + private static final String EMPTYSTRING = ""; + + /** The listeners waiting for model changes. */ + protected EventListenerList listenerList = new EventListenerList(); + + /** + * Only one <code>ChangeEvent</code> is needed per model instance + * since the event's only (read-only) state is the expression. The source + * of events generated here is always "this". + */ + protected transient ChangeEvent changeEvent = null; + + /** + * The constructor. + * + * @param target the UML element + * @param name the name of the property + */ + public ExpressionModel( + final String propertyName, + final String type, + final Object umlElement, + final GetterSetterManager getterSetterManager) { + this.target = umlElement; + this.propertyName = propertyName; + this.getterSetterManager = getterSetterManager; + this.type = type; + addModelEventListener(); + } + + public void addModelEventListener() { + Model.getPump().addModelEventListener(this, target, propertyName); + } + + public void removeModelEventListener() { + Model.getPump().removeModelEventListener(this, target, propertyName); + } + + public void propertyChange(PropertyChangeEvent e) { + if (propertyName.equals(e.getPropertyName())) { + if (rememberExpression != e.getNewValue()) { + fireStateChanged(); + } + } + } + + protected Object getTarget() { + return target; + } + + /** + * @return the expression + */ + public Object getExpression() { + return getterSetterManager.get(target, propertyName, type); + } + + /** + * @param expr the expression + */ + public void setExpression(Object expr) { + getterSetterManager.set(target, expr, propertyName); + } + + /** + * @return a new expression with given language and body + */ + public Object newExpression(String language, String body) { + return getterSetterManager.create(propertyName, language, body); + } + + /** + * @return the language of the expression + */ + public String getLanguage() { + Object expression = getExpression(); + if (expression == null) { + return EMPTYSTRING; + } + return Model.getDataTypesHelper().getLanguage(expression); + } + + /** + * @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); + } + } + + /** + * @param body the body text of the expression + */ + public void setBody(String body) { + + Object expression = getExpression(); + boolean mustChange = true; + if (expression != null) { + Object oldValue = Model.getDataTypesHelper().getBody(expression); + if (oldValue != null && oldValue.equals(body)) { + mustChange = false; + } + } + if (mustChange) { + String lang = null; + if (expression != null) { + lang = Model.getDataTypesHelper().getLanguage(expression); + } + if (lang == null) { + lang = EMPTYSTRING; + } + + setExpression(lang, body); + } + } + + /** + * 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) { + + // Expressions are DataTypes, not independent model elements + // be careful not to reuse them + final Object currentExpression = getExpression(); + removeModelEventListener(); + if (currentExpression != null) { + Model.getUmlFactory().delete(currentExpression); + } + final Object newExpression; + if (lang.length() == 0 && body.length()==0) { + newExpression = null; + } else { + newExpression = newExpression(lang, body); + } + setExpression(newExpression); + addModelEventListener(); + } + + /** + * Adds a <code>ChangeListener</code>. + * The change listeners are run each + * time the expression changes. + * + * @param l the ChangeListener to add + * @see #removeChangeListener + */ + public void addChangeListener(ChangeListener l) { + listenerList.add(ChangeListener.class, l); + LOG.debug(">>Add listener"); + } + + /** + * Removes a <code>ChangeListener</code>. + * + * @param l the <code>ChangeListener</code> to remove + * @see #addChangeListener + */ + public void removeChangeListener(ChangeListener l) { + listenerList.remove(ChangeListener.class, l); + } + + /** + * Runs each <code>ChangeListener</code>'s + * <code>stateChanged</code> method. + * + * @see #setRangeProperties + * @see EventListenerList + */ + protected void fireStateChanged() { + LOG.debug(">>Fire state changed to listeners."); + Object[] listeners = listenerList.getListenerList(); + for (int i = listeners.length - 2; i >= 0; i -=2 ) { + if (listeners[i] == ChangeListener.class) { + if (changeEvent == null) { + changeEvent = new ChangeEvent(this); + } + ((ChangeListener)listeners[i+1]).stateChanged(changeEvent); + } + } + } +} Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SingleListFactory.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SingleListFactory.java?view=diff&pathrev=17714&r1=17713&r2=17714 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SingleListFactory.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SingleListFactory.java 2009-12-31 08:24:56-0800 @@ -1,3 +1,16 @@ +/* $Id$ + ******************************************************************************* + * Copyright (c) 2009 Contributors - see below + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bob Tarling + ******************************************************************************* + */ + // $Id: ListFactory.java 17009 2009-03-31 22:53:20Z bobtarling $ // Copyright (c) 2008 The Regents of the University of California. All // Rights Reserved. Permission to use, copy, modify, and distribute this @@ -24,7 +37,10 @@ package org.argouml.core.propertypanels.ui; +import javax.swing.DefaultListModel; import javax.swing.JComponent; + +import org.argouml.core.propertypanels.model.GetterSetterManager; import org.argouml.model.Model; /** @@ -38,7 +54,7 @@ final String propName, final String type) { - UMLModelElementListModel model = null; + DefaultListModel model = null; if ("owner".equals(propName)) { model = new UMLFeatureOwnerListModel(modelElement, propName); @@ -114,6 +130,16 @@ model = new UMLTemplateParameterParameterListModel(modelElement, propName); } + if (model == null) { + final GetterSetterManager getterSetterManager = + GetterSetterManager.getGetterSetter(); + if (getterSetterManager.contains(propName)) { + model = new SimpleListModel(propName, type, modelElement, getterSetterManager); + } + } + + + if (model != null) { return new RowSelector(model, false, false); } Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java?view=diff&pathrev=17714&r1=17713&r2=17714 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java 2009-12-31 08:24:56-0800 @@ -110,12 +110,14 @@ JComponent control = null; + final String propertyName = prop.getName(); + if ("initialValue".equals(prop.getName())) { UMLExpressionModel model = new UMLInitialValueExpressionModel(target); p = new UMLExpressionPanel(model, prop.getName()); control = p; - } else if ("defaultValue".equals(prop.getName())) { + } else if ("defaultValue".equals(prop.getName())) { UMLExpressionModel model = new UMLDefaultValueExpressionModel(target); p = new UMLExpressionPanel(model, prop.getName()); @@ -126,7 +128,7 @@ UMLTextArea osta = new UMLTextArea(document); osta.setRows(3); control = new JScrollPane(osta); - } else if ("body".equals(prop.getName())) { + } else if ("body".equals(prop.getName()) && "String".equals(prop.getType())) { UMLPlainTextDocument document = new UMLCommentBodyDocument(prop.getName(), target); UMLTextArea text = new UMLTextArea(document); text.setLineWrap(true); @@ -171,6 +173,20 @@ // if not, it is a control and must be labeled... addControl(panel, prop.getName(), control); } + } else { + final GetterSetterManager getterSetter = GetterSetterManager.getGetterSetter(); + + if (getterSetter.contains(propertyName)) { + ExpressionModel model = new ExpressionModel(propertyName, prop.getType(), target, getterSetter); + final JTextField languageField = + new ExpressionLanguageField(model); + addControl( + panel, + Translator.localize("label.language"), + languageField); + control = new JScrollPane(new ExpressionBodyField(model)); + addControl(panel, null, control); + } } } @@ -416,6 +432,13 @@ comp = new UMLComboBoxNavigator( Translator.localize("label.type.navigate.tooltip"), combo); + } else if ("specification".equals(prop.getName())) { + final UMLComboBoxModel model = + new UMLMethodSpecificationComboBoxModel(propertyName, target); + final JComboBox combo = new UMLComboBox(model); + comp = new UMLComboBoxNavigator( + Translator.localize("label.type.navigate.tooltip"), + combo); } if (comp != null) { Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLMethodSpecificationComboBoxModel.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLMethodSpecificationComboBoxModel.java?view=markup&pathrev=17714 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLMethodSpecificationComboBoxModel.java 2009-12-31 08:24:56-0800 @@ -0,0 +1,128 @@ +/* $Id$ + ******************************************************************************* + * Copyright (c) 2009 Contributors - see below + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bob Tarling + ******************************************************************************* + */ + +package org.argouml.core.propertypanels.ui; + +import java.awt.event.ActionEvent; + +import javax.swing.Action; + +import org.argouml.i18n.Translator; +import org.argouml.model.AttributeChangeEvent; +import org.argouml.model.Model; +import org.argouml.model.UmlChangeEvent; +import org.argouml.ui.UndoableAction; +import org.argouml.uml.ui.UMLComboBox2; + +class UMLMethodSpecificationComboBoxModel +extends UMLComboBoxModel { + /** + * Constructor. + */ + public UMLMethodSpecificationComboBoxModel( + final String propertyName, + final Object target) { + super("specification", false); + setTarget(target); + Model.getPump().addClassModelEventListener(this, + Model.getMetaTypes().getOperation(), "method"); + } + + /* + * @see org.argouml.uml.ui.UMLComboBoxModel2#isValidElement( + * java.lang.Object) + */ + protected boolean isValidElement(Object element) { + Object specification = + Model.getCoreHelper().getSpecification(getTarget()); + return specification == element; + } + + /* + * @see org.argouml.uml.ui.UMLComboBoxModel2#buildModelList() + */ + protected void buildModelList() { + if (getTarget() != null) { + removeAllElements(); + Object classifier = Model.getFacade().getOwner(getTarget()); + addAll(Model.getFacade().getOperations(classifier)); + } + } + + /* + * @see org.argouml.uml.ui.UMLComboBoxModel2#getSelectedModelElement() + */ + protected Object getSelectedModelElement() { + return Model.getCoreHelper().getSpecification(getTarget()); + } + + /* + * @see java.beans.PropertyChangeListener#propertyChange( + * java.beans.PropertyChangeEvent) + */ + public void modelChanged(UmlChangeEvent evt) { + if (evt instanceof AttributeChangeEvent) { + if (evt.getPropertyName().equals("specification")) { + if (evt.getSource() == getTarget() + && (getChangedElement(evt) != null)) { + Object elem = getChangedElement(evt); + setSelectedItem(elem); + } + } + } + } + + public Action getAction() { + return new ActionSetMethodSpecification(); + } + + private static class ActionSetMethodSpecification extends UndoableAction { + + /** + * Constructor for ActionSetStructuralFeatureType. + */ + protected ActionSetMethodSpecification() { + super(Translator.localize("Set"), null); + // Set the tooltip string: + putValue(Action.SHORT_DESCRIPTION, + Translator.localize("Set")); + } + + /* + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) { + super.actionPerformed(e); + Object source = e.getSource(); + Object oldOperation = null; + Object newOperation = null; + Object method = null; + if (source instanceof UMLComboBox2) { + UMLComboBox2 box = (UMLComboBox2) source; + Object o = box.getTarget(); // the method + if (Model.getFacade().isAMethod(o)) { + method = o; + oldOperation = + Model.getCoreHelper().getSpecification(method); + } + o = box.getSelectedItem(); // the selected operation + if (Model.getFacade().isAOperation(o)) { + newOperation = o; + } + } + if (newOperation != oldOperation && method != null) { + Model.getCoreHelper().setSpecification(method, newOperation); + } + } + } +} ------------------------------------------------------ http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2433994 To unsubscribe from this discussion, e-mail: [[email protected]].
