KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > actions > NewValueAction


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.common.actions;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
26 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils;
27 import org.eclipse.jface.resource.ImageDescriptor;
28
29
30 /**
31  * This Action adds a new Value to an Attribute.
32  *
33  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
34  * @version $Rev$, $Date$
35  */

36 public class NewValueAction extends BrowserAction
37 {
38     /**
39      * Creates a new instance of NewValueAction.
40      */

41     public NewValueAction()
42     {
43         super();
44     }
45
46
47     /**
48      * {@inheritDoc}
49      */

50     public void dispose()
51     {
52         super.dispose();
53     }
54
55
56     /**
57      * {@inheritDoc}
58      */

59     public void run()
60     {
61         if ( getSelectedValues().length == 1 )
62         {
63             getSelectedValues()[0].getAttribute().addEmptyValue();
64         }
65         else if ( getSelectedAttributes().length == 1 )
66         {
67             getSelectedAttributes()[0].addEmptyValue();
68         }
69         else if ( getSelectedAttributeHierarchies().length == 1 )
70         {
71             getSelectedAttributeHierarchies()[0].getAttribute().addEmptyValue();
72         }
73
74         if ( getSelectedSearchResults().length > 0 )
75         {
76
77         }
78     }
79
80
81     /**
82      * {@inheritDoc}
83      */

84     public String JavaDoc getText()
85     {
86         return "New Value";
87     }
88
89
90     /**
91      * {@inheritDoc}
92      */

93     public ImageDescriptor getImageDescriptor()
94     {
95         return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_VALUE_ADD );
96     }
97
98
99     /**
100      * {@inheritDoc}
101      */

102     public String JavaDoc getCommandId()
103     {
104         return "org.apache.directory.ldapstudio.browser.action.addValue";
105     }
106
107
108     /**
109      * {@inheritDoc}
110      */

111     public boolean isEnabled()
112     {
113         // System.out.println(getSelectedAttributeArrays());
114
// System.out.print("==> ");
115
// IAttribute[][] attArr = getSelectedAttributeArrays();
116
// for (int i = 0; i < attArr.length; i++) {
117
// for (int j = 0; j < attArr[i].length; j++) {
118
// IAttribute att = attArr[i][j];
119
// System.out.print(att + "|");
120
// }
121
// }
122
// System.out.println();
123

124         return ( getSelectedSearchResults().length == 0 && getSelectedAttributes().length == 0
125             && getSelectedValues().length == 1 && SchemaUtils.isModifyable( getSelectedValues()[0].getAttribute()
126             .getAttributeTypeDescription() ) )
127
128             || ( getSelectedSearchResults().length == 0 && getSelectedValues().length == 0
129                 && getSelectedAttributes().length == 1 && SchemaUtils.isModifyable( getSelectedAttributes()[0]
130                 .getAttributeTypeDescription() ) )
131
132             || ( getSelectedSearchResults().length == 1 && getSelectedValues().length == 0
133                 && getSelectedAttributes().length == 0 && getSelectedAttributeHierarchies().length == 1 && SchemaUtils
134                 .isModifyable( getSelectedAttributeHierarchies()[0].getAttribute().getAttributeTypeDescription() ) );
135     }
136 }
137
Popular Tags