svn commit: r18042 - trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2010-02-26 01:19:31-0800
New Revision: 18042

Modified:
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLLinkedList.java

Log:
Make controls disabled in a panel for a readonly element - also hides any buttons and popup menus that may attempt to mutate the element

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java?view=diff&pathrev=18042&r1=18041&r2=18042
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java	2010-02-26 01:19:31-0800
@@ -277,39 +277,53 @@
             moveTopAction = null;
             moveBottomAction = null;
         } else {
-            // Create actions and expander if we have multiple rows
-            final ArrayList<Action> actions = new ArrayList<Action>(2);
+        	if (!Model.getModelManagementHelper().isReadOnly(target)) {
+        		// TODO: Lets build this into a separate buildToolbar method
+        		
+                // Create actions and expander if we have multiple rows
+                final ArrayList<Action> actions = new ArrayList<Action>(6);
+
+                if (Model.getUmlFactory().isContainmentValid(metaType, target)) {
+                    final Action createAction = new ActionCreateContainedModelElement(
+                            metaType,
+                            target,
+                            "button.new-" + Model.getMetaTypes().getName(metaType).toLowerCase());
+                    actions.add(createAction);
+                }
+                deleteAction = new DeleteAction();
+                actions.add(deleteAction);
 
-            if (Model.getUmlFactory().isContainmentValid(metaType, target)) {
-                final Action createAction = new ActionCreateContainedModelElement(
-                        metaType,
-                        target,
-                        "button.new-" + Model.getMetaTypes().getName(metaType).toLowerCase());
-                actions.add(createAction);
-            }
-            deleteAction = new DeleteAction();
-            actions.add(deleteAction);
+                if (Model.getUmlHelper().isMovable(metaType)) {
+                    moveUpAction = new MoveUpAction();
+                    moveDownAction = new MoveDownAction();
+                    moveTopAction = new MoveTopAction();
+                    moveBottomAction = new MoveBottomAction();
+                    actions.add(moveUpAction);
+                    actions.add(moveDownAction);
+                    actions.add(moveTopAction);
+                    actions.add(moveBottomAction);
+                } else {
+                    moveUpAction = null;
+                    moveDownAction = null;
+                    moveTopAction = null;
+                    moveBottomAction = null;
+                }
 
-            if (Model.getUmlHelper().isMovable(metaType)) {
-                moveUpAction = new MoveUpAction();
-                moveDownAction = new MoveDownAction();
-                moveTopAction = new MoveTopAction();
-                moveBottomAction = new MoveBottomAction();
-                actions.add(moveUpAction);
-                actions.add(moveDownAction);
-                actions.add(moveTopAction);
-                actions.add(moveBottomAction);
-            } else {
+                final ToolBarFactory tbf = new ToolBarFactory(actions);
+                toolbar = tbf.createToolBar();
+                toolbar.setRollover(true);
+                toolbar.setOrientation(ToolBar.VERTICAL);
+        	} else {
+                final ToolBarFactory tbf = new ToolBarFactory(new Object[] {});
+                toolbar = tbf.createToolBar();
+                toolbar.setRollover(true);
+                toolbar.setOrientation(ToolBar.VERTICAL);
                 moveUpAction = null;
                 moveDownAction = null;
                 moveTopAction = null;
                 moveBottomAction = null;
-            }
-
-            final ToolBarFactory tbf = new ToolBarFactory(actions);
-            toolbar = tbf.createToolBar();
-            toolbar.setRollover(true);
-            toolbar.setOrientation(ToolBar.VERTICAL);
+                deleteAction = null;
+        	}
 
             JPanel buttonPanel =
                 new JPanel(new FlexiGridLayout(2, 1, FlexiGridLayout.ROWCOLPREFERRED));
@@ -323,17 +337,19 @@
             }
             add(buttonPanel, BorderLayout.WEST);
 
-            getList().addListSelectionListener(deleteAction);
-            // TODO: We should really test the model instead for this
-            // but we have no API yet.
-            // Can we just check if the collection to build the JList
-            // control implements the List interface?
-            if (Model.getUmlHelper().isMovable(metaType)) {
-                getList().addListSelectionListener(moveUpAction);
-                getList().addListSelectionListener(moveDownAction);
-                getList().addListSelectionListener(moveTopAction);
-                getList().addListSelectionListener(moveBottomAction);
-            }
+        	if (!Model.getModelManagementHelper().isReadOnly(target)) {
+	            getList().addListSelectionListener(deleteAction);
+	            // TODO: We should really test the model instead for this
+	            // but we have no API yet.
+	            // Can we just check if the collection to build the JList
+	            // control implements the List interface?
+	            if (Model.getUmlHelper().isMovable(metaType)) {
+	                getList().addListSelectionListener(moveUpAction);
+	                getList().addListSelectionListener(moveDownAction);
+	                getList().addListSelectionListener(moveTopAction);
+	                getList().addListSelectionListener(moveBottomAction);
+	            }
+        	}
             
             getModel().addListDataListener(this);
         }
@@ -408,7 +424,7 @@
             toolbar.setVisible(expanded);
         }
 
-        // Froce the parent to redraw
+        // Force the parent to redraw
         getParent().invalidate();
         getParent().validate();
     }
@@ -429,13 +445,15 @@
      */
     public void removeNotify() {
         LOG.info("The RowSelector is being removed from a panel");
-        getList().removeListSelectionListener(deleteAction);
-        if (moveUpAction != null) {
-            getList().removeListSelectionListener(moveUpAction);
-            getList().removeListSelectionListener(moveDownAction);
-            getList().removeListSelectionListener(moveTopAction);
-            getList().removeListSelectionListener(moveBottomAction);
-        }
+    	if (!Model.getModelManagementHelper().isReadOnly(target)) {
+	        getList().removeListSelectionListener(deleteAction);
+	        if (moveUpAction != null) {
+	            getList().removeListSelectionListener(moveUpAction);
+	            getList().removeListSelectionListener(moveDownAction);
+	            getList().removeListSelectionListener(moveTopAction);
+	            getList().removeListSelectionListener(moveBottomAction);
+	        }
+    	}
         this.removeMouseListener(this);
         getModel().removeListDataListener(this);
         if (getModel() instanceof UMLModelElementListModel) {

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=18042&r1=18041&r2=18042
==============================================================================
--- 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	2010-02-26 01:19:31-0800
@@ -117,9 +117,11 @@
         tbf.setRollover(true);
         JToolBar tb = tbf.createToolBar();
         tb.add(new JLabel(metaTypeName, ResourceLoaderWrapper.lookupIconResource(metaTypeName), JLabel.LEFT));
-        // We only have this here until we have stereotypes
-        // list on property panel
-        tb.add(new ActionNewStereotype());
+        if (!Model.getModelManagementHelper().isReadOnly(target)) {
+            // We only have this here until we have stereotypes
+            // list on property panel
+            tb.add(new ActionNewStereotype());
+        }
         panel.add(tb);
     }
     
@@ -195,24 +197,27 @@
         if (control != null) {
             if (control == p) {
                 // if the control is a panel, add it
-                addControl(panel, null, control);
+                addControl(panel, null, control, target);
             } else {
                 // if not, it is a control and must be labeled...
-                addControl(panel, Translator.localize(prop.getLabel()), control);
+                addControl(panel, Translator.localize(prop.getLabel()),
+                		control, target);
             }
         } else {
-            final GetterSetterManager getterSetter = GetterSetterManager.getGetterSetter(prop.getType());
+            final GetterSetterManager getterSetter = 
+            	GetterSetterManager.getGetterSetter(prop.getType());
 
             if (getterSetter.contains(propertyName)) {
-                ExpressionModel model = new ExpressionModel(propertyName, prop.getType(), target, getterSetter);
+                ExpressionModel model =
+                	new ExpressionModel(propertyName, prop.getType(), target, getterSetter);
                 final JTextField languageField = 
                     new ExpressionLanguageField(model);
                 addControl(
                         panel,
                         Translator.localize("label.language"),
-                        languageField);
+                        languageField, target);
                 control = new JScrollPane(new ExpressionBodyField(model));
-                addControl(panel, null, control);
+                addControl(panel, null, control, target);
             }
         }
     }
@@ -224,8 +229,8 @@
         final JComponent pane =
             factory.createComponent(target, prop.getName(), prop.getType());
         
-        if (pane != null) {           
-            addControl(panel, Translator.localize(prop.getLabel()), pane);
+        if (pane != null) {
+            addControl(panel, Translator.localize(prop.getLabel()), pane, target);
         }
     }
 
@@ -238,7 +243,7 @@
             factory.createComponent(target, prop.getName(), prop.getType());
 
         if (list != null) {
-            addControl(panel, Translator.localize(prop.getLabel()), list);
+            addControl(panel, Translator.localize(prop.getLabel()), list, target);
         }
     }
 
@@ -261,7 +266,7 @@
                     propertyName, 
                     true, 
                     getterSetter);
-            addControl(panel, null, control);
+            addControl(panel, null, control, target);
         }
     }
 
@@ -282,7 +287,7 @@
                 buildCheckBox(p, target, data);
             }                            
         }
-        addControl(panel, null, p);
+        addControl(panel, null, p, target);
     }
 
     private void buildCheckBox(
@@ -298,7 +303,13 @@
         final String label = Translator.localize(prop.getLabel());
         
         if (getterSetter.contains(propertyName)) {
-            panel.add(new CheckBox(label, target, propertyName, getterSetter));
+        	final CheckBox cb =
+        		new CheckBox(label, target, propertyName, getterSetter);
+        	if (Model.getModelManagementHelper().isReadOnly(target)) {
+        		cb.setEnabled(false);
+        	}
+        	
+            panel.add(cb);
         }
     }
 
@@ -464,7 +475,8 @@
         }
         
         if (comp != null) {
-            addControl(panel, Translator.localize(prop.getLabel()), comp);
+            addControl(panel, Translator.localize(prop.getLabel()),
+            		comp, target);
         }
     }
 
@@ -493,11 +505,20 @@
         
         if (document != null) {
             JTextField tfield = new UMLTextField(document);
-            addControl(panel, Translator.localize(prop.getLabel()), tfield);
+            addControl(panel, Translator.localize(prop.getLabel()),
+            		tfield, target);
         }
     }
     
-    private void addControl(JPanel panel, String text, JComponent component) {
+    private void addControl(
+    		final JPanel panel,
+    		final String text,
+    		final JComponent component,
+    		final Object target) {
+    	if (Model.getModelManagementHelper().isReadOnly(target)) {
+    		component.setEnabled(false);
+    	}
+
         LabelledComponent lc = new LabelledComponent(text, component);
         panel.add(lc);
     }

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLLinkedList.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLLinkedList.java?view=diff&pathrev=18042&r1=18041&r2=18042
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLLinkedList.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLLinkedList.java	2010-02-26 01:19:31-0800
@@ -136,6 +136,9 @@
      * @return Object
      */
     public Object getTarget() {
+    	if (getModel() instanceof SimpleListModel) {
+            return ((SimpleListModel) getModel()).getUmlElement();
+    	}
         return ((UMLModelElementListModel) getModel()).getTarget();
     }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2452444

To unsubscribe from this discussion, e-mail: [[email protected]].
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.