Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package org.litesoft.aokeyhole.swing;

import javax.swing.*;

import org.litesoft.aokeyhole.objects.*;
import org.litesoft.aokeyhole.swing.namevaluecomponents.*;
import org.litesoft.aokeyhole.swing.simplecomponents.*;
import org.litesoft.aokeyhole.toolkit.*;
import org.litesoft.aokeyhole.toolkit.editorviewer.*;

public class SwingEditViewCardedJPanel extends CardedJPanel implements EditViewPanelController
{
    private static final String OPTION_BLANK = "Blank";

    private final ActionsListener mActionsListener;
    private final NameValueChangedByUserListener mNameValueChangedByUserListener;

    private static final String OPTION_SELECT_NEW_Object = "NEW_Object";
    private boolean mObjectSelector = false;
    private ObjectSet mDefaultObjectSet = null;
    private NewObjectTypeSelectionListener mNewObjectTypeSelectionListener = null;

    private static final String OPTION_SELECT_NEW_Attribute = "OPTION_SEL_Attribute";

    private static final String OPTION_SELECT_EXISTING_Object = "EXISTING_Object";

    private static final String OPTION_SELECT_EXISTING_Attribute = "EXISTING_Attribute";

    public SwingEditViewCardedJPanel( ActionsListener pActionsListener, NameValueChangedByUserListener pNameValueChangedByUserListener )
    {
        mActionsListener = pActionsListener;
        mNameValueChangedByUserListener = pNameValueChangedByUserListener;
        addOption( new JLabel( "- - - - - - - - - - - - - Properties - - - - - - - - - - - - -" ), OPTION_BLANK );
    }

    public void showBlank()
    {
        showOption( OPTION_BLANK );
    }

    public void addNewObjectTypeSelector( JPanel pPanel )
    {
        mObjectSelector = true;
        addOption( pPanel, OPTION_SELECT_NEW_Object );
    }

    public void addNewObjectTypeSelector( ObjectSet pDefaultObjectSet, NewObjectTypeSelectionListener pNewObjectTypeSelectionListener )
    {
        mDefaultObjectSet = pDefaultObjectSet;
        mNewObjectTypeSelectionListener = pNewObjectTypeSelectionListener;
    }

    public void showNewObjectTypeSelector( SubSystemMetaData pSubSystemMetaData )
    {
        if ( mObjectSelector )
        {
            showOption( OPTION_SELECT_NEW_Object );
            return;
        }
        if ( (mDefaultObjectSet != null) && (mNewObjectTypeSelectionListener != null) )
        {
            mNewObjectTypeSelectionListener.newObjectTypeSelected( mDefaultObjectSet );
            return;
        }
        throw new IllegalStateException( "No DefaultObjectSet or NewObjectTypeSelectionListener" );
    }

    private AddNewAttributeTypeSelectorJPanel mAddNewAttributeTypeSelectorJPanel = null;

    public void addNewAttributeTypeSelector( AttributeSet[] pAttributeSets, ActionsListener pActionsListener,
                                             NewAttributeTypeSelectionListener pNewAttributeTypeSelectionListener )
    {
        mAddNewAttributeTypeSelectorJPanel = new AddNewAttributeTypeSelectorJPanel( pAttributeSets, pActionsListener, pNewAttributeTypeSelectionListener );
        addOption( mAddNewAttributeTypeSelectorJPanel, OPTION_SELECT_NEW_Attribute );
    }

    public void showNewAttributeTypeSelector( ObjectMetaData pObjectMetaData )
    {
        mAddNewAttributeTypeSelectorJPanel.buildAttributePanel( pObjectMetaData.getObjectSet() );
        showOption( OPTION_SELECT_NEW_Attribute );
    }

    private SwingObjectPropertyComponentFactory mSwingObjectPropertyComponentFactory = null;
    private CommonPropertyActionJPanel mObjectPropertyActionJPanel = null;

    public void addObjects( SwingObjectPropertyComponentFactory pSwingObjectPropertyComponentFactory )
    {
        mSwingObjectPropertyComponentFactory = pSwingObjectPropertyComponentFactory;
        mObjectPropertyActionJPanel = new CommonPropertyActionJPanel();
        addOption( mObjectPropertyActionJPanel, OPTION_SELECT_EXISTING_Object );
    }

    public ActionsControllableNameValuesComponent showObjectNew( SubSystemMetaData pSubSystemMetaData, ObjectSet pObjectSet )
    {
        return populateAndShowObjectPanel( pSubSystemMetaData, pObjectSet, true, CommonPropertyActionJPanel.ACTION_NEW );
    }

    public ActionsControllableNameValuesComponent showObjectExisting( ObjectMetaData pObjectMetaData )
    {
        return populateAndShowObjectPanel( pObjectMetaData.getSubSystemMetaData(), pObjectMetaData.getObjectSet(), pObjectMetaData.isEditable(),
                                           CommonPropertyActionJPanel.ACTION_EDIT );
    }

    private ActionsControllableNameValuesComponent populateAndShowObjectPanel( SubSystemMetaData pSubSystemMetaData, ObjectSet pObjectSet, boolean pEditable,
                                                                               String pEditableActionsID )
    {
        showBlank(); // Switch away temporarily so can tear down potentially old Object View

        String zLabel = pObjectSet.getType();

        mObjectPropertyActionJPanel.clear();

        VerticalGrowableIndicatingComponent[] zComponents =
                mSwingObjectPropertyComponentFactory.createComponentsForObject( mNameValueChangedByUserListener, pObjectSet, pSubSystemMetaData );

        mObjectPropertyActionJPanel.build( zLabel, mActionsListener, pEditable, true, zComponents );

        return prepAndShowPanel( OPTION_SELECT_EXISTING_Object, mObjectPropertyActionJPanel, pObjectSet, false, null, pEditable, pEditableActionsID );
    }

    private SwingAttributePropertyComponentFactory mSwingAttributePropertyComponentFactory = null;
    private CommonPropertyActionJPanel mAttributePropertyActionJPanel = null;

    public void addAttributes( SwingAttributePropertyComponentFactory pSwingAttributePropertyComponentFactory )
    {
        mSwingAttributePropertyComponentFactory = pSwingAttributePropertyComponentFactory;
        mAttributePropertyActionJPanel = new CommonPropertyActionJPanel();
        addOption( mAttributePropertyActionJPanel, OPTION_SELECT_EXISTING_Attribute );
    }

    public ActionsControllableNameValuesComponent showAttributeNew( ObjectMetaData pObjectMetaData, boolean pVirtual, AttributeSet pAttributeSet )
    {
        return populateAndShowAttributePanel( pObjectMetaData, pVirtual, pAttributeSet, true, CommonPropertyActionJPanel.ACTION_NEW );
    }

    public ActionsControllableNameValuesComponent showAttribExisting( AttributeMetaData pAttributeMetaData )
    {
        return populateAndShowAttributePanel( pAttributeMetaData.getObjectMetaData(), pAttributeMetaData.isVirtual(), pAttributeMetaData.getAttributeSet(),
                                              pAttributeMetaData.isEditable(), CommonPropertyActionJPanel.ACTION_EDIT );
    }

    private ActionsControllableNameValuesComponent populateAndShowAttributePanel( ObjectMetaData pObjectMetaData, boolean pVirtual, AttributeSet pAttributeSet,
                                                                                  boolean pEditable, String pEditableActionsID )
    {
        showBlank(); // Switch away temporarily so can tear down potentially old Attribute View 

        String zLabel = (pVirtual ? "Virtual-" : "") + pAttributeSet.getType();

        mAttributePropertyActionJPanel.clear();

        VerticalGrowableIndicatingComponent[] zComponents =
                mSwingAttributePropertyComponentFactory.createComponentsForAttribute( mNameValueChangedByUserListener, pVirtual, pAttributeSet,
                                                                                      pObjectMetaData );

        mAttributePropertyActionJPanel.build( zLabel, mActionsListener, pEditable, pAttributeSet.isUiDeleteable(), zComponents );

        return prepAndShowPanel( OPTION_SELECT_EXISTING_Attribute, mAttributePropertyActionJPanel, pObjectMetaData.getObjectSet(), pVirtual, pAttributeSet,
                                 pEditable, pEditableActionsID );
    }

    private ActionsControllableNameValuesComponent prepAndShowPanel( String pOptionKey, CommonPropertyActionJPanel pPanel, ObjectSet pObjectSet,
                                                                     boolean pVirtual, AttributeSet pAttributeSet, boolean pEditable,
                                                                     String pEditableActionsID )
    {
        pPanel.set( pObjectSet, pVirtual, pAttributeSet );

        pPanel.setEnabled( pEditable );

        pPanel.showActions( pEditable ? pEditableActionsID : CommonPropertyActionJPanel.ACTION_BLANK );

        showOption( pOptionKey );

        return pPanel;
    }
}

Commits for litesoft/trunk/Java/KeyHole/src/org/litesoft/aokeyhole/swing/SwingEditViewCardedJPanel.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000