KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > entryeditor > EntryEditorWidgetCellModifier


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.widgets.entryeditor;
22
23
24 import org.apache.directory.ldapstudio.browser.core.model.IValue;
25 import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
26 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils;
27 import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager;
28 import org.eclipse.jface.dialogs.MessageDialog;
29 import org.eclipse.jface.viewers.ICellModifier;
30 import org.eclipse.swt.widgets.Display;
31 import org.eclipse.swt.widgets.Item;
32
33
34 /**
35  * The EntryEditorWidgetCellModifier implements the {@link ICellModifier} interface
36  * for the entry editor widget.
37  *
38  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
39  * @version $Rev$, $Date$
40  */

41 public class EntryEditorWidgetCellModifier implements ICellModifier
42 {
43
44     /** The value editor manager. */
45     private ValueEditorManager valueEditorManager;
46
47
48     /**
49      * Creates a new instance of EntryEditorWidgetCellModifier.
50      *
51      * @param valueEditorManager
52      */

53     public EntryEditorWidgetCellModifier( ValueEditorManager valueEditorManager )
54     {
55         this.valueEditorManager = valueEditorManager;
56     }
57
58
59     /**
60      * Disposes this object.
61      */

62     public void dispose()
63     {
64         valueEditorManager = null;
65     }
66
67
68     /**
69      * {@inheritDoc}
70      */

71     public boolean canModify( Object JavaDoc element, String JavaDoc property )
72     {
73         if ( element != null && element instanceof IValue && valueEditorManager != null )
74         {
75             IValue attributeValue = ( IValue ) element;
76
77             if ( !SchemaUtils.isModifyable( attributeValue.getAttribute().getAttributeTypeDescription() ) )
78             {
79                 return false;
80             }
81             if ( attributeValue.isRdnPart() )
82             {
83                 return false;
84             }
85             if ( EntryEditorWidgetTableMetadata.KEY_COLUMN_NAME.equals( property ) )
86             {
87                 return false;
88             }
89             if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) )
90             {
91                 return this.valueEditorManager.getCurrentValueEditor( attributeValue ).getRawValue( attributeValue ) != null;
92             }
93         }
94
95         return false;
96     }
97
98
99     /**
100      * {@inheritDoc}
101      */

102     public Object JavaDoc getValue( Object JavaDoc element, String JavaDoc property )
103     {
104         if ( element != null && element instanceof IValue && valueEditorManager != null )
105         {
106             IValue attributeValue = ( IValue ) element;
107             Object JavaDoc returnValue;
108             if ( EntryEditorWidgetTableMetadata.KEY_COLUMN_NAME.equals( property ) )
109             {
110                 returnValue = attributeValue.getAttribute().getDescription();
111             }
112             else if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) )
113             {
114                 returnValue = this.valueEditorManager.getCurrentValueEditor( attributeValue ).getRawValue(
115                     attributeValue );
116             }
117             else
118             {
119                 returnValue = "";
120             }
121             return returnValue;
122         }
123         else
124         {
125             return null;
126         }
127     }
128
129
130     /**
131      * {@inheritDoc}
132      *
133      * TODO: Remove value modification from value editors
134      */

135     public void modify( Object JavaDoc element, String JavaDoc property, Object JavaDoc newRawValue )
136     {
137         if ( element != null && element instanceof Item )
138         {
139             element = ( ( Item ) element ).getData();
140         }
141
142         if ( element != null && element instanceof IValue && valueEditorManager != null )
143         {
144             IValue attributeValue = ( IValue ) element;
145
146             if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) )
147             {
148                 try
149                 {
150                     this.valueEditorManager.getCurrentValueEditor( attributeValue ).modifyValue( attributeValue,
151                         newRawValue );
152                 }
153                 catch ( ModelModificationException mme )
154                 {
155                     MessageDialog.openError( Display.getDefault().getActiveShell(), "Error While Modifying Value", mme
156                         .getMessage() );
157                 }
158             }
159         }
160     }
161
162 }
163
Popular Tags