Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/KeyHole/src/org/litesoft/aokeyhole/swing/SwingEditViewCardedJPanel.java

Diff revisions: vs.
  @@ -1,164 +1,164 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.aokeyhole.swing;
3 -
4 - import org.litesoft.aokeyhole.objects.*;
5 - import org.litesoft.aokeyhole.swing.namevaluecomponents.*;
6 - import org.litesoft.aokeyhole.swing.simplecomponents.*;
7 - import org.litesoft.aokeyhole.toolkit.*;
8 - import org.litesoft.aokeyhole.toolkit.editorviewer.*;
9 -
10 - import javax.swing.*;
11 -
12 - public class SwingEditViewCardedJPanel extends CardedJPanel implements EditViewPanelController {
13 - private static final String OPTION_BLANK = "Blank";
14 -
15 - private final ActionsListener mActionsListener;
16 - private final NameValueChangedByUserListener mNameValueChangedByUserListener;
17 -
18 - private static final String OPTION_SELECT_NEW_Object = "NEW_Object";
19 - private boolean mObjectSelector = false;
20 - private ObjectSet mDefaultObjectSet = null;
21 - private NewObjectTypeSelectionListener mNewObjectTypeSelectionListener = null;
22 -
23 - private static final String OPTION_SELECT_NEW_Attribute = "OPTION_SEL_Attribute";
24 -
25 - private static final String OPTION_SELECT_EXISTING_Object = "EXISTING_Object";
26 -
27 - private static final String OPTION_SELECT_EXISTING_Attribute = "EXISTING_Attribute";
28 -
29 - public SwingEditViewCardedJPanel( ActionsListener pActionsListener, NameValueChangedByUserListener pNameValueChangedByUserListener ) {
30 - mActionsListener = pActionsListener;
31 - mNameValueChangedByUserListener = pNameValueChangedByUserListener;
32 - addOption( new JLabel( "- - - - - - - - - - - - - Properties - - - - - - - - - - - - -" ), OPTION_BLANK );
33 - }
34 -
35 - @Override
36 - public void showBlank() {
37 - showOption( OPTION_BLANK );
38 - }
39 -
40 - public void addNewObjectTypeSelector( JPanel pPanel ) {
41 - mObjectSelector = true;
42 - addOption( pPanel, OPTION_SELECT_NEW_Object );
43 - }
44 -
45 - public void addNewObjectTypeSelector( ObjectSet pDefaultObjectSet, NewObjectTypeSelectionListener pNewObjectTypeSelectionListener ) {
46 - mDefaultObjectSet = pDefaultObjectSet;
47 - mNewObjectTypeSelectionListener = pNewObjectTypeSelectionListener;
48 - }
49 -
50 - @Override
51 - public void showNewObjectTypeSelector( SubSystemMetaData pSubSystemMetaData ) {
52 - if ( mObjectSelector ) {
53 - showOption( OPTION_SELECT_NEW_Object );
54 - return;
55 - }
56 - if ( (mDefaultObjectSet != null) && (mNewObjectTypeSelectionListener != null) ) {
57 - mNewObjectTypeSelectionListener.newObjectTypeSelected( mDefaultObjectSet );
58 - return;
59 - }
60 - throw new IllegalStateException( "No DefaultObjectSet or NewObjectTypeSelectionListener" );
61 - }
62 -
63 - private AddNewAttributeTypeSelectorJPanel mAddNewAttributeTypeSelectorJPanel = null;
64 -
65 - public void addNewAttributeTypeSelector( AttributeSet[] pAttributeSets, ActionsListener pActionsListener,
66 - NewAttributeTypeSelectionListener pNewAttributeTypeSelectionListener ) {
67 - mAddNewAttributeTypeSelectorJPanel = new AddNewAttributeTypeSelectorJPanel( pAttributeSets, pActionsListener, pNewAttributeTypeSelectionListener );
68 - addOption( mAddNewAttributeTypeSelectorJPanel, OPTION_SELECT_NEW_Attribute );
69 - }
70 -
71 - @Override
72 - public void showNewAttributeTypeSelector( ObjectMetaData pObjectMetaData ) {
73 - mAddNewAttributeTypeSelectorJPanel.buildAttributePanel( pObjectMetaData.getObjectSet() );
74 - showOption( OPTION_SELECT_NEW_Attribute );
75 - }
76 -
77 - private SwingObjectPropertyComponentFactory mSwingObjectPropertyComponentFactory = null;
78 - private CommonPropertyActionJPanel mObjectPropertyActionJPanel = null;
79 -
80 - public void addObjects( SwingObjectPropertyComponentFactory pSwingObjectPropertyComponentFactory ) {
81 - mSwingObjectPropertyComponentFactory = pSwingObjectPropertyComponentFactory;
82 - mObjectPropertyActionJPanel = new CommonPropertyActionJPanel();
83 - addOption( mObjectPropertyActionJPanel, OPTION_SELECT_EXISTING_Object );
84 - }
85 -
86 - @Override
87 - public ActionsControllableNameValuesComponent showObjectNew( SubSystemMetaData pSubSystemMetaData, ObjectSet pObjectSet ) {
88 - return populateAndShowObjectPanel( pSubSystemMetaData, pObjectSet, true, CommonPropertyActionJPanel.ACTION_NEW );
89 - }
90 -
91 - @Override
92 - public ActionsControllableNameValuesComponent showObjectExisting( ObjectMetaData pObjectMetaData ) {
93 - return populateAndShowObjectPanel( pObjectMetaData.getSubSystemMetaData(), pObjectMetaData.getObjectSet(), pObjectMetaData.isEditable(),
94 - CommonPropertyActionJPanel.ACTION_EDIT );
95 - }
96 -
97 - private ActionsControllableNameValuesComponent populateAndShowObjectPanel( SubSystemMetaData pSubSystemMetaData, ObjectSet pObjectSet, boolean pEditable,
98 - String pEditableActionsID ) {
99 - showBlank(); // Switch away temporarily so can tear down potentially old Object View
100 -
101 - String zLabel = pObjectSet.getType();
102 -
103 - mObjectPropertyActionJPanel.clear();
104 -
105 - VerticalGrowableIndicatingComponent[] zComponents =
106 - mSwingObjectPropertyComponentFactory.createComponentsForObject( mNameValueChangedByUserListener, pObjectSet, pSubSystemMetaData );
107 -
108 - mObjectPropertyActionJPanel.build( zLabel, mActionsListener, pEditable, true, zComponents );
109 -
110 - return prepAndShowPanel( OPTION_SELECT_EXISTING_Object, mObjectPropertyActionJPanel, pObjectSet, false, null, pEditable, pEditableActionsID );
111 - }
112 -
113 - private SwingAttributePropertyComponentFactory mSwingAttributePropertyComponentFactory = null;
114 - private CommonPropertyActionJPanel mAttributePropertyActionJPanel = null;
115 -
116 - public void addAttributes( SwingAttributePropertyComponentFactory pSwingAttributePropertyComponentFactory ) {
117 - mSwingAttributePropertyComponentFactory = pSwingAttributePropertyComponentFactory;
118 - mAttributePropertyActionJPanel = new CommonPropertyActionJPanel();
119 - addOption( mAttributePropertyActionJPanel, OPTION_SELECT_EXISTING_Attribute );
120 - }
121 -
122 - @Override
123 - public ActionsControllableNameValuesComponent showAttributeNew( ObjectMetaData pObjectMetaData, boolean pVirtual, AttributeSet pAttributeSet ) {
124 - return populateAndShowAttributePanel( pObjectMetaData, pVirtual, pAttributeSet, true, CommonPropertyActionJPanel.ACTION_NEW );
125 - }
126 -
127 - @Override
128 - public ActionsControllableNameValuesComponent showAttribExisting( AttributeMetaData pAttributeMetaData ) {
129 - return populateAndShowAttributePanel( pAttributeMetaData.getObjectMetaData(), pAttributeMetaData.isVirtual(), pAttributeMetaData.getAttributeSet(),
130 - pAttributeMetaData.isEditable(), CommonPropertyActionJPanel.ACTION_EDIT );
131 - }
132 -
133 - private ActionsControllableNameValuesComponent populateAndShowAttributePanel( ObjectMetaData pObjectMetaData, boolean pVirtual, AttributeSet pAttributeSet,
134 - boolean pEditable, String pEditableActionsID ) {
135 - showBlank(); // Switch away temporarily so can tear down potentially old Attribute View
136 -
137 - String zLabel = (pVirtual ? "Virtual-" : "") + pAttributeSet.getType();
138 -
139 - mAttributePropertyActionJPanel.clear();
140 -
141 - VerticalGrowableIndicatingComponent[] zComponents =
142 - mSwingAttributePropertyComponentFactory.createComponentsForAttribute( mNameValueChangedByUserListener, pVirtual, pAttributeSet,
143 - pObjectMetaData );
144 -
145 - mAttributePropertyActionJPanel.build( zLabel, mActionsListener, pEditable, pAttributeSet.isUiDeleteable(), zComponents );
146 -
147 - return prepAndShowPanel( OPTION_SELECT_EXISTING_Attribute, mAttributePropertyActionJPanel, pObjectMetaData.getObjectSet(), pVirtual, pAttributeSet,
148 - pEditable, pEditableActionsID );
149 - }
150 -
151 - private ActionsControllableNameValuesComponent prepAndShowPanel( String pOptionKey, CommonPropertyActionJPanel pPanel, ObjectSet pObjectSet,
152 - boolean pVirtual, AttributeSet pAttributeSet, boolean pEditable,
153 - String pEditableActionsID ) {
154 - pPanel.set( pObjectSet, pVirtual, pAttributeSet );
155 -
156 - pPanel.setEnabled( pEditable );
157 -
158 - pPanel.showActions( pEditable ? pEditableActionsID : CommonPropertyActionJPanel.ACTION_BLANK );
159 -
160 - showOption( pOptionKey );
161 -
162 - return pPanel;
163 - }
164 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.aokeyhole.swing;
3 +
4 + import org.litesoft.aokeyhole.objects.*;
5 + import org.litesoft.aokeyhole.swing.namevaluecomponents.*;
6 + import org.litesoft.aokeyhole.swing.simplecomponents.*;
7 + import org.litesoft.aokeyhole.toolkit.*;
8 + import org.litesoft.aokeyhole.toolkit.editorviewer.*;
9 +
10 + import javax.swing.*;
11 +
12 + public class SwingEditViewCardedJPanel extends CardedJPanel implements EditViewPanelController {
13 + private static final String OPTION_BLANK = "Blank";
14 +
15 + private final ActionsListener mActionsListener;
16 + private final NameValueChangedByUserListener mNameValueChangedByUserListener;
17 +
18 + private static final String OPTION_SELECT_NEW_Object = "NEW_Object";
19 + private boolean mObjectSelector = false;
20 + private ObjectSet mDefaultObjectSet = null;
21 + private NewObjectTypeSelectionListener mNewObjectTypeSelectionListener = null;
22 +
23 + private static final String OPTION_SELECT_NEW_Attribute = "OPTION_SEL_Attribute";
24 +
25 + private static final String OPTION_SELECT_EXISTING_Object = "EXISTING_Object";
26 +
27 + private static final String OPTION_SELECT_EXISTING_Attribute = "EXISTING_Attribute";
28 +
29 + public SwingEditViewCardedJPanel( ActionsListener pActionsListener, NameValueChangedByUserListener pNameValueChangedByUserListener ) {
30 + mActionsListener = pActionsListener;
31 + mNameValueChangedByUserListener = pNameValueChangedByUserListener;
32 + addOption( new JLabel( "- - - - - - - - - - - - - Properties - - - - - - - - - - - - -" ), OPTION_BLANK );
33 + }
34 +
35 + @Override
36 + public void showBlank() {
37 + showOption( OPTION_BLANK );
38 + }
39 +
40 + public void addNewObjectTypeSelector( JPanel pPanel ) {
41 + mObjectSelector = true;
42 + addOption( pPanel, OPTION_SELECT_NEW_Object );
43 + }
44 +
45 + public void addNewObjectTypeSelector( ObjectSet pDefaultObjectSet, NewObjectTypeSelectionListener pNewObjectTypeSelectionListener ) {
46 + mDefaultObjectSet = pDefaultObjectSet;
47 + mNewObjectTypeSelectionListener = pNewObjectTypeSelectionListener;
48 + }
49 +
50 + @Override
51 + public void showNewObjectTypeSelector( SubSystemMetaData pSubSystemMetaData ) {
52 + if ( mObjectSelector ) {
53 + showOption( OPTION_SELECT_NEW_Object );
54 + return;
55 + }
56 + if ( (mDefaultObjectSet != null) && (mNewObjectTypeSelectionListener != null) ) {
57 + mNewObjectTypeSelectionListener.newObjectTypeSelected( mDefaultObjectSet );
58 + return;
59 + }
60 + throw new IllegalStateException( "No DefaultObjectSet or NewObjectTypeSelectionListener" );
61 + }
62 +
63 + private AddNewAttributeTypeSelectorJPanel mAddNewAttributeTypeSelectorJPanel = null;
64 +
65 + public void addNewAttributeTypeSelector( AttributeSet[] pAttributeSets, ActionsListener pActionsListener,
66 + NewAttributeTypeSelectionListener pNewAttributeTypeSelectionListener ) {
67 + mAddNewAttributeTypeSelectorJPanel = new AddNewAttributeTypeSelectorJPanel( pAttributeSets, pActionsListener, pNewAttributeTypeSelectionListener );
68 + addOption( mAddNewAttributeTypeSelectorJPanel, OPTION_SELECT_NEW_Attribute );
69 + }
70 +
71 + @Override
72 + public void showNewAttributeTypeSelector( ObjectMetaData pObjectMetaData ) {
73 + mAddNewAttributeTypeSelectorJPanel.buildAttributePanel( pObjectMetaData.getObjectSet() );
74 + showOption( OPTION_SELECT_NEW_Attribute );
75 + }
76 +
77 + private SwingObjectPropertyComponentFactory mSwingObjectPropertyComponentFactory = null;
78 + private CommonPropertyActionJPanel mObjectPropertyActionJPanel = null;
79 +
80 + public void addObjects( SwingObjectPropertyComponentFactory pSwingObjectPropertyComponentFactory ) {
81 + mSwingObjectPropertyComponentFactory = pSwingObjectPropertyComponentFactory;
82 + mObjectPropertyActionJPanel = new CommonPropertyActionJPanel();
83 + addOption( mObjectPropertyActionJPanel, OPTION_SELECT_EXISTING_Object );
84 + }
85 +
86 + @Override
87 + public ActionsControllableNameValuesComponent showObjectNew( SubSystemMetaData pSubSystemMetaData, ObjectSet pObjectSet ) {
88 + return populateAndShowObjectPanel( pSubSystemMetaData, pObjectSet, true, CommonPropertyActionJPanel.ACTION_NEW );
89 + }
90 +
91 + @Override
92 + public ActionsControllableNameValuesComponent showObjectExisting( ObjectMetaData pObjectMetaData ) {
93 + return populateAndShowObjectPanel( pObjectMetaData.getSubSystemMetaData(), pObjectMetaData.getObjectSet(), pObjectMetaData.isEditable(),
94 + CommonPropertyActionJPanel.ACTION_EDIT );
95 + }
96 +
97 + private ActionsControllableNameValuesComponent populateAndShowObjectPanel( SubSystemMetaData pSubSystemMetaData, ObjectSet pObjectSet, boolean pEditable,
98 + String pEditableActionsID ) {
99 + showBlank(); // Switch away temporarily so can tear down potentially old Object View
100 +
101 + String zLabel = pObjectSet.getType();
102 +
103 + mObjectPropertyActionJPanel.clear();
104 +
105 + VerticalGrowableIndicatingComponent[] zComponents =
106 + mSwingObjectPropertyComponentFactory.createComponentsForObject( mNameValueChangedByUserListener, pObjectSet, pSubSystemMetaData );
107 +
108 + mObjectPropertyActionJPanel.build( zLabel, mActionsListener, pEditable, true, zComponents );
109 +
110 + return prepAndShowPanel( OPTION_SELECT_EXISTING_Object, mObjectPropertyActionJPanel, pObjectSet, false, null, pEditable, pEditableActionsID );
111 + }
112 +
113 + private SwingAttributePropertyComponentFactory mSwingAttributePropertyComponentFactory = null;
114 + private CommonPropertyActionJPanel mAttributePropertyActionJPanel = null;
115 +
116 + public void addAttributes( SwingAttributePropertyComponentFactory pSwingAttributePropertyComponentFactory ) {
117 + mSwingAttributePropertyComponentFactory = pSwingAttributePropertyComponentFactory;
118 + mAttributePropertyActionJPanel = new CommonPropertyActionJPanel();
119 + addOption( mAttributePropertyActionJPanel, OPTION_SELECT_EXISTING_Attribute );
120 + }
121 +
122 + @Override
123 + public ActionsControllableNameValuesComponent showAttributeNew( ObjectMetaData pObjectMetaData, boolean pVirtual, AttributeSet pAttributeSet ) {
124 + return populateAndShowAttributePanel( pObjectMetaData, pVirtual, pAttributeSet, true, CommonPropertyActionJPanel.ACTION_NEW );
125 + }
126 +
127 + @Override
128 + public ActionsControllableNameValuesComponent showAttribExisting( AttributeMetaData pAttributeMetaData ) {
129 + return populateAndShowAttributePanel( pAttributeMetaData.getObjectMetaData(), pAttributeMetaData.isVirtual(), pAttributeMetaData.getAttributeSet(),
130 + pAttributeMetaData.isEditable(), CommonPropertyActionJPanel.ACTION_EDIT );
131 + }
132 +
133 + private ActionsControllableNameValuesComponent populateAndShowAttributePanel( ObjectMetaData pObjectMetaData, boolean pVirtual, AttributeSet pAttributeSet,
134 + boolean pEditable, String pEditableActionsID ) {
135 + showBlank(); // Switch away temporarily so can tear down potentially old Attribute View
136 +
137 + String zLabel = (pVirtual ? "Virtual-" : "") + pAttributeSet.getType();
138 +
139 + mAttributePropertyActionJPanel.clear();
140 +
141 + VerticalGrowableIndicatingComponent[] zComponents =
142 + mSwingAttributePropertyComponentFactory.createComponentsForAttribute( mNameValueChangedByUserListener, pVirtual, pAttributeSet,
143 + pObjectMetaData );
144 +
145 + mAttributePropertyActionJPanel.build( zLabel, mActionsListener, pEditable, pAttributeSet.isUiDeleteable(), zComponents );
146 +
147 + return prepAndShowPanel( OPTION_SELECT_EXISTING_Attribute, mAttributePropertyActionJPanel, pObjectMetaData.getObjectSet(), pVirtual, pAttributeSet,
148 + pEditable, pEditableActionsID );
149 + }
150 +
151 + private ActionsControllableNameValuesComponent prepAndShowPanel( String pOptionKey, CommonPropertyActionJPanel pPanel, ObjectSet pObjectSet,
152 + boolean pVirtual, AttributeSet pAttributeSet, boolean pEditable,
153 + String pEditableActionsID ) {
154 + pPanel.set( pObjectSet, pVirtual, pAttributeSet );
155 +
156 + pPanel.setEnabled( pEditable );
157 +
158 + pPanel.showActions( pEditable ? pEditableActionsID : CommonPropertyActionJPanel.ACTION_BLANK );
159 +
160 + showOption( pOptionKey );
161 +
162 + return pPanel;
163 + }
164 + }