|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.s60tools.imaker.internal.providers; |
|
20 |
|
21 import java.util.regex.Matcher; |
|
22 import java.util.regex.Pattern; |
|
23 |
|
24 import org.eclipse.jface.viewers.CellEditor; |
|
25 import org.eclipse.jface.viewers.CheckboxCellEditor; |
|
26 import org.eclipse.jface.viewers.ColumnViewer; |
|
27 import org.eclipse.jface.viewers.TableViewer; |
|
28 |
|
29 import com.nokia.s60tools.imaker.internal.model.iContent.IbyEntry; |
|
30 import com.nokia.s60tools.imaker.internal.viewers.DebugTab; |
|
31 |
|
32 public class CheckBoxEditingSupport extends IbyEntryEditingSupport { |
|
33 private final static int ENABLE_COLUMN_ID = 1; |
|
34 public CheckBoxEditingSupport(ColumnViewer viewer, int column) { |
|
35 super(viewer, column); |
|
36 } |
|
37 |
|
38 @Override |
|
39 protected boolean canEdit(Object element) { |
|
40 return true; |
|
41 } |
|
42 |
|
43 @Override |
|
44 protected CellEditor getCellEditor(Object element) { |
|
45 TableViewer tv = (TableViewer) getViewer(); |
|
46 CheckboxCellEditor cellEditor = new CheckboxCellEditor(tv.getTable()); |
|
47 return cellEditor; |
|
48 } |
|
49 |
|
50 @Override |
|
51 protected Object getValue(Object element) { |
|
52 Boolean ret = (column==ENABLE_COLUMN_ID)?new Boolean(getEntry(element).isEnabled()):new Boolean(getEntry(element).isDebug()); |
|
53 return ret; |
|
54 } |
|
55 |
|
56 @Override |
|
57 protected void setValue(Object element, Object value) { |
|
58 Boolean newValue = (Boolean)value; |
|
59 IbyEntry entry = getEntry(element); |
|
60 if(column==ENABLE_COLUMN_ID) { |
|
61 entry.setEnabled(newValue); |
|
62 } else { |
|
63 String dPath = getDebugVersion(entry.getFile(),newValue); |
|
64 if(!dPath.equals(entry.getFile())) { |
|
65 entry.setFile(dPath); |
|
66 entry.setDebug(newValue); |
|
67 } else { |
|
68 return; |
|
69 } |
|
70 } |
|
71 updateWarning(element); |
|
72 getViewer().update(element, null); |
|
73 } |
|
74 |
|
75 private String getDebugVersion(String path, Boolean value) { |
|
76 String pattern; |
|
77 if(value) { |
|
78 pattern = DebugTab.REL_PATTERN; |
|
79 } else { |
|
80 pattern = DebugTab.DEBUG_PATTERN; |
|
81 } |
|
82 Pattern p = Pattern.compile(pattern); |
|
83 Matcher matcher = p.matcher(path); |
|
84 if (matcher.find()) { |
|
85 int start = matcher.start(1); |
|
86 int end = matcher.end(1); |
|
87 String newPath; |
|
88 if(value) { |
|
89 newPath = path.substring(0, start) + "udeb" + path.substring(end); |
|
90 } else { |
|
91 newPath = path.substring(0, start) + "urel" + path.substring(end); |
|
92 } |
|
93 return newPath; |
|
94 } else { |
|
95 return path; |
|
96 } |
|
97 } |
|
98 } |