538a4111248031a875a6893a1af369a3b9078815
[sdk/ide/common-eplugin.git] / org.tizen.common.connection / src / org / tizen / common / connection / properties / ConnectionExplorerPermissionPropertyPages.java
1 /*
2 *  Common
3 *
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: 
7 * Hoon Kang <h245.kang@samsung.com>
8 * Hyunsik Noh <hyunsik.noh@samsung.com>
9
10  * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 * Contributors:
23 * - S-Core Co., Ltd
24 *
25 */
26 package org.tizen.common.connection.properties;
27
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Control;
33 import org.eclipse.swt.widgets.Group;
34 import org.eclipse.swt.widgets.Label;
35 import org.eclipse.swt.widgets.Table;
36 import org.eclipse.swt.widgets.TableColumn;
37 import org.eclipse.swt.widgets.TableItem;
38 import org.eclipse.ui.dialogs.PropertyPage;
39
40 import org.tizen.sdblib.FileListingService;
41 import org.tizen.sdblib.FileListingService.FileEntry;
42
43 public class ConnectionExplorerPermissionPropertyPages extends PropertyPage {
44
45         
46         private static final String PERMISSION_TITLE = "Permission:";
47         
48         private TableItem itemUser;
49         private TableItem itemGroup;
50         private TableItem itemOther;
51
52
53         /**
54          * Constructor for SamplePropertyPage.
55          */
56         public ConnectionExplorerPermissionPropertyPages() {
57                 super();
58         
59         }
60
61         private void addFirstSection(Composite parent) {
62                 
63                 FileEntry f = (FileEntry) getElement().getAdapter(FileEntry.class);
64                 String permission = f.getPermissions();
65                 
66                 itemUser.setText(1, permission.charAt(1) != '-' ? "O" : "X");
67                 itemUser.setText(2, permission.charAt(2) != '-' ? "O" : "X");
68                 itemUser.setText(3, permission.charAt(3) != '-' ? "O" : "X");
69                 
70                 itemGroup.setText(1, permission.charAt(4) != '-' ? "O" : "X");
71                 itemGroup.setText(2, permission.charAt(5) != '-' ? "O" : "X");
72                 itemGroup.setText(3, permission.charAt(6) != '-' ? "O" : "X");
73                 
74                 itemOther.setText(1, permission.charAt(7) != '-' ? "O" : "X");
75                 itemOther.setText(2, permission.charAt(8) != '-' ? "O" : "X");
76                 itemOther.setText(3, permission.charAt(9) != '-' ? "O" : "X");
77                 
78                 
79         }
80
81         private void addSeparator(Composite parent) {
82                 Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
83                 GridData gridData = new GridData();
84                 gridData.horizontalAlignment = GridData.FILL;
85                 gridData.grabExcessHorizontalSpace = true;
86                 separator.setLayoutData(gridData);
87         }
88
89         
90         /**
91          * @see PreferencePage#createContents(Composite)
92          */
93         protected Control createContents(Composite parent) {
94                 noDefaultAndApplyButton();
95                 Composite composite = new Composite(parent, SWT.NONE);
96                 GridLayout layout = new GridLayout();
97                 composite.setLayout(layout);
98                 GridData data = new GridData();
99                 composite.setLayoutData(data);
100
101                 FileEntry f = (FileEntry) getElement().getAdapter(FileEntry.class);
102                 if (f.getType() == FileListingService.TYPE_ROOT_DEVICE || 
103                                 f.getType() == FileListingService.TYPE_ROOT_EMULATOR) {
104                         return composite;
105                 }       
106                 createTable(composite);
107                 addFirstSection(composite);
108                 addSeparator(composite);
109                 return composite;
110         }
111         
112         private void createTable(Composite parent) {
113                 Group group = new Group(parent, SWT.NONE);
114                 group.setText(PERMISSION_TITLE);
115                 GridLayout layout = new GridLayout();
116                 layout.numColumns = 1;
117                 group.setLayout(layout);
118                 GridData data = new GridData();
119                 data.horizontalSpan = 1;
120                 group.setLayoutData(data);
121
122                 Table table = new Table(group, SWT.BORDER);
123                 GridData gridData = new GridData();
124                 gridData.horizontalSpan = 3;
125                 gridData.verticalSpan = 3;
126                 table.setLayoutData(gridData);
127                 
128                 table.setHeaderVisible(true);
129                 table.setLinesVisible(true);
130                 
131                 TableColumn colMsg = createTableColumn(table, "", SWT.NONE,
132                "EXECUTE");
133                 colMsg = createTableColumn(table, "Read", SWT.NONE,
134                "EXECUTE");
135                 colMsg = createTableColumn(table, "Write", SWT.NONE,
136                "EXECUTE");
137                 colMsg = createTableColumn(table, "Execute", SWT.NONE,
138                "EXECUTE");
139                 
140                 
141                 itemUser = new TableItem(table, SWT.NONE);
142                 itemUser.setText(0, "User");
143                 
144                 itemGroup = new TableItem(table, SWT.NONE);
145                 itemGroup.setText(0, "Group");
146                 
147                 itemOther = new TableItem(table, SWT.NONE);
148                 itemOther.setText(0, "Other");
149         }
150
151         private TableColumn createTableColumn(Table parent, String header,
152                             int style, String sampleText) {
153                 
154                 TableColumn col = new TableColumn(parent, style);
155
156         col.setText(sampleText);
157         col.setResizable(false);
158         col.pack();
159
160         col.setText(header);
161
162             return col;
163         }
164         
165         
166         public boolean performOk() {
167                 return true;
168         }
169
170 }