KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > dialogs > properties > ValuePropertyPage


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.ui.dialogs.properties;
22
23
24 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
25 import org.apache.directory.ldapstudio.browser.core.model.IValue;
26 import org.apache.directory.ldapstudio.browser.core.utils.Utils;
27
28 import org.eclipse.core.runtime.IAdaptable;
29 import org.eclipse.jface.dialogs.IDialogConstants;
30 import org.eclipse.jface.resource.JFaceResources;
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.layout.GridData;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Control;
35 import org.eclipse.swt.widgets.Text;
36 import org.eclipse.ui.IWorkbenchPropertyPage;
37 import org.eclipse.ui.dialogs.PropertyPage;
38
39
40 public class ValuePropertyPage extends PropertyPage implements IWorkbenchPropertyPage
41 {
42
43     private Text descriptionText;
44
45     private Text valueText;
46
47     private Text typeText;
48
49     private Text sizeText;
50
51
52     public ValuePropertyPage()
53     {
54         super();
55         super.noDefaultAndApplyButton();
56     }
57
58
59     protected Control createContents( Composite parent )
60     {
61
62         IValue value = getValue( getElement() );
63
64         Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
65         Composite mainGroup = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
66
67         BaseWidgetUtils.createLabel( mainGroup, "Attribute Description:", 1 );
68         descriptionText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 );
69
70         BaseWidgetUtils.createLabel( mainGroup, "Value Type:", 1 );
71         typeText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 );
72
73         BaseWidgetUtils.createLabel( mainGroup, "Value Size:", 1 );
74         sizeText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 );
75
76         BaseWidgetUtils.createLabel( mainGroup, "Data:", 1 );
77         if ( value != null && value.isString() )
78         {
79             valueText = new Text( mainGroup, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY );
80             valueText.setFont( JFaceResources.getFont( JFaceResources.TEXT_FONT ) );
81             GridData gd = new GridData( GridData.FILL_BOTH );
82             gd.widthHint = convertHorizontalDLUsToPixels( ( int ) ( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 ) );
83             gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 4 );
84             valueText.setLayoutData( gd );
85             valueText.setBackground( parent.getBackground() );
86         }
87         else
88         {
89             valueText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 );
90         }
91
92         if ( value != null )
93         {
94
95             super.setMessage( "Value " + Utils.shorten( value.toString(), 30 ) );
96
97             descriptionText.setText( value.getAttribute().getDescription() );
98             // valueText.setText(LdifUtils.mustEncode(value.getBinaryValue())?"Binary":value.getStringValue());
99
valueText.setText( value.isString() ? value.getStringValue() : "Binary" );
100             typeText.setText( value.isString() ? "String" : "Binary" );
101
102             int bytes = value.getBinaryValue().length;
103             int chars = value.isString() ? value.getStringValue().length() : 0;
104             String JavaDoc size = value.isString() ? chars + ( chars > 1 ? " Characters, " : " Character, " ) : "";
105             size += Utils.formatBytes( bytes );
106             sizeText.setText( size );
107         }
108
109         return parent;
110     }
111
112
113     private static IValue getValue( Object JavaDoc element )
114     {
115         IValue value = null;
116         if ( element instanceof IAdaptable )
117         {
118             value = ( IValue ) ( ( IAdaptable ) element ).getAdapter( IValue.class );
119         }
120         return value;
121     }
122
123 }
124
Popular Tags