~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to java/src/IceGridGUI/Application/CommunicatorSubEditor.java

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// **********************************************************************
2
2
//
3
 
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
4
4
//
5
5
// This copy of Ice is licensed to you under the terms described in the
6
6
// ICE_LICENSE file included in this distribution.
7
7
//
8
8
// **********************************************************************
 
9
 
9
10
package IceGridGUI.Application;
10
11
 
11
12
import java.awt.event.ActionEvent;
28
29
    CommunicatorSubEditor(Editor mainEditor)
29
30
    {
30
31
        _mainEditor = mainEditor;
31
 
        
32
 
        _description.getDocument().addDocumentListener(
33
 
            _mainEditor.getUpdateListener());
 
32
 
 
33
        _description.getDocument().addDocumentListener(_mainEditor.getUpdateListener());
34
34
        _description.setToolTipText("An optional description");
35
35
 
36
 
        _propertySets.getDocument().addDocumentListener(
37
 
            _mainEditor.getUpdateListener());
 
36
        _propertySets.getDocument().addDocumentListener(_mainEditor.getUpdateListener());
38
37
        _propertySets.setToolTipText("Property Set References");
39
38
 
40
39
        _properties = new PropertiesField(mainEditor);
41
 
        _logFiles = new MapField(mainEditor, "Path", "Property",
42
 
                                 true);
 
40
        _logFiles = new SimpleMapField(mainEditor, true, "Path", "Property");
43
41
        _logFiles.setToolTipText("Log files used by this server or service");
44
42
    }
45
43
 
46
 
  
47
44
    void appendProperties(DefaultFormBuilder builder)
48
45
    {
49
46
        builder.append("Description");
52
49
        builder.nextRow(-2);
53
50
        CellConstraints cc = new CellConstraints();
54
51
        JScrollPane scrollPane = new JScrollPane(_description);
55
 
        builder.add(scrollPane, 
56
 
                    cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
 
52
        builder.add(scrollPane, cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
57
53
        builder.nextRow(2);
58
54
        builder.nextLine();
59
 
        
 
55
 
60
56
        builder.append("Property Sets");
61
57
        builder.append(_propertySets, 3);
62
58
        builder.nextLine();
71
67
 
72
68
        builder.nextRow(-6);
73
69
        scrollPane = new JScrollPane(_properties);
74
 
        builder.add(scrollPane, 
75
 
                    cc.xywh(builder.getColumn(), builder.getRow(), 3, 7));
 
70
        builder.add(scrollPane, cc.xywh(builder.getColumn(), builder.getRow(), 3, 7));
76
71
        builder.nextRow(6);
77
72
        builder.nextLine();
78
73
 
83
78
        builder.append("");
84
79
        builder.nextRow(-4);
85
80
        scrollPane = new JScrollPane(_logFiles);
86
 
        builder.add(scrollPane, 
87
 
                    cc.xywh(builder.getColumn(), builder.getRow(), 3, 5));
 
81
        builder.add(scrollPane, cc.xywh(builder.getColumn(), builder.getRow(), 3, 5));
88
82
        builder.nextRow(4);
89
83
        builder.nextLine();
90
84
    }
91
85
 
92
86
    void writeDescriptor(CommunicatorDescriptor descriptor)
93
87
    {
94
 
        descriptor.propertySet.references = 
95
 
            (String[])_propertySets.getList().toArray(new String[0]);
 
88
        descriptor.propertySet.references = _propertySets.getList().toArray(new String[0]);
96
89
        descriptor.propertySet.properties = _properties.getProperties();
97
90
        descriptor.description = _description.getText();
98
91
 
99
 
        java.util.TreeMap tm = _logFiles.get();
100
 
        java.util.Iterator p = tm.entrySet().iterator();
 
92
        java.util.TreeMap<String, String> tm = _logFiles.get();
101
93
        descriptor.logs = new String[tm.size()];
102
94
        int i = 0;
103
95
 
104
 
        while(p.hasNext())
 
96
        for(java.util.Map.Entry<String, String> p : tm.entrySet())
105
97
        {
106
 
            java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
107
 
            String path = (String)entry.getKey();
108
 
            String prop = ((String)entry.getValue()).trim();
 
98
            String path = p.getKey();
 
99
            String prop = p.getValue().trim();
109
100
 
110
101
            descriptor.logs[i++] = path;
111
102
            if(!prop.equals(""))
112
103
            {
113
 
                setProperty((java.util.LinkedList)descriptor.propertySet.properties, prop, path);
 
104
                setProperty((java.util.LinkedList<PropertyDescriptor>)descriptor.propertySet.properties, prop, path);
114
105
            }
115
106
        }
116
107
    }
123
114
        //
124
115
        // Note that we don't substitute in the lookup
125
116
        //
126
 
        java.util.Map map = new java.util.TreeMap();
127
 
        for(int i = 0; i < descriptor.logs.length; ++i)
 
117
        java.util.Map<String, String> map = new java.util.TreeMap<String, String>();
 
118
        for(String log : descriptor.logs)
128
119
        {
129
 
            String prop = lookupKey(descriptor.propertySet.properties,
130
 
                                    descriptor.logs[i]);
131
 
            map.put(descriptor.logs[i], prop);
 
120
            String prop = lookupKey(descriptor.propertySet.properties, log);
 
121
            map.put(log, prop);
132
122
        }
133
123
        _logFiles.set(map, detailResolver, isEditable);
134
124
 
135
 
        _propertySets.setList(java.util.Arrays.asList(descriptor.propertySet.references),
136
 
                              detailResolver);
 
125
        _propertySets.setList(java.util.Arrays.asList(descriptor.propertySet.references), detailResolver);
137
126
        _propertySets.setEditable(isEditable);
138
127
        _properties.setProperties(descriptor.propertySet.properties,
139
128
                                  descriptor.adapters,
140
129
                                  descriptor.logs,
141
130
                                  detailResolver, isEditable);
142
131
 
143
 
        _description.setText(
144
 
            Utils.substitute(descriptor.description, detailResolver));
 
132
        _description.setText(Utils.substitute(descriptor.description, detailResolver));
145
133
        _description.setEditable(isEditable);
146
134
        _description.setOpaque(isEditable);
147
135
    }
148
136
 
149
 
 
150
137
    //
151
138
    // Returns first key matching this value, if there is one
152
139
    //
153
 
    private String lookupKey(java.util.List props, String value)
 
140
    private String lookupKey(java.util.List<PropertyDescriptor> props, String value)
154
141
    {
155
 
        java.util.Iterator p = props.iterator();
156
 
        while(p.hasNext())
 
142
        for(PropertyDescriptor p : props)
157
143
        {
158
 
            PropertyDescriptor pd = (PropertyDescriptor)p.next();
159
 
            if(pd.value.equals(value))
 
144
            if(p.value.equals(value))
160
145
            {
161
 
                return pd.name;
 
146
                return p.name;
162
147
            }
163
148
        }
164
149
        return "";
165
150
    }
166
151
 
167
 
    private void setProperty(java.util.LinkedList props, String key, String newValue)
 
152
    private void setProperty(java.util.LinkedList<PropertyDescriptor> props, String key, String newValue)
168
153
    {
169
154
        removeProperty(props, key);
170
155
        props.addFirst(new PropertyDescriptor(key, newValue));
171
156
    }
172
157
 
173
 
    private void removeProperty(java.util.List props, String key)
 
158
    private void removeProperty(java.util.List<PropertyDescriptor> props, String key)
174
159
    {
175
 
        java.util.Iterator p = props.iterator();
 
160
        java.util.Iterator<PropertyDescriptor> p = props.iterator();
176
161
        while(p.hasNext())
177
162
        {
178
 
            PropertyDescriptor pd = (PropertyDescriptor)p.next();
 
163
            PropertyDescriptor pd = p.next();
179
164
            if(pd.name.equals(key))
180
165
            {
181
166
                p.remove();
182
167
            }
183
168
        }
184
169
    }
185
 
    
186
170
 
187
171
    protected Editor _mainEditor;
188
 
 
 
172
 
189
173
    private JTextArea _description = new JTextArea(3, 20);
190
 
    private ListTextField _propertySets = new ListTextField(20); 
 
174
    private ListTextField _propertySets = new ListTextField(20);
191
175
    private PropertiesField _properties;
192
 
    private MapField _logFiles;
 
176
    private SimpleMapField _logFiles;
193
177
}