|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2005, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2005, 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 21-55
Link Here
|
| 21 |
import org.eclipse.swt.dnd.Transfer; |
21 |
import org.eclipse.swt.dnd.Transfer; |
| 22 |
|
22 |
|
| 23 |
/** |
23 |
/** |
| 24 |
* Clipboard for datapools containing cell, record, and string data. |
24 |
* <p>Clipboard for datapools containing cell, record, and string data.</p> |
| 25 |
* |
25 |
* |
| 26 |
* |
26 |
* |
| 27 |
* @author Peter Sun |
27 |
* @author Peter Sun |
| 28 |
* @author Paul Slauenwhite |
28 |
* @author Paul Slauenwhite |
| 29 |
* @version October 9, 2008 |
29 |
* @version March 29, 2010 |
| 30 |
* @since January 27, 2005 |
30 |
* @since January 27, 2005 |
| 31 |
*/ |
31 |
*/ |
| 32 |
public class DatapoolClipboard |
32 |
public class DatapoolClipboard { |
| 33 |
{ |
33 |
|
| 34 |
private static final String SEPERATOR = "\t"; //$NON-NLS-1$ |
|
|
| 35 |
private static final String LINEFEED = "\n"; //$NON-NLS-1$ |
| 36 |
private static final String CARRIAGERETURN = "\r"; //$NON-NLS-1$ |
| 37 |
|
| 38 |
private Vector recordData = null; |
34 |
private Vector recordData = null; |
| 39 |
private Vector recordStringData = null; |
35 |
private Vector recordStringData = null; |
| 40 |
private Object cellData = null; |
36 |
private Object cellData = null; |
| 41 |
private Object cellStringData = null; |
37 |
private Object cellStringData = null; |
| 42 |
private Clipboard clipboard = null; |
38 |
private Clipboard clipboard = null; |
| 43 |
|
39 |
|
| 44 |
private static final DatapoolClipboard instance = new DatapoolClipboard(); |
40 |
private static DatapoolClipboard instance = null; |
| 45 |
|
41 |
|
| 46 |
public static DatapoolClipboard getInstance() |
42 |
private static final String SEPERATOR_CHARACTRER = "\t"; //$NON-NLS-1$ |
| 47 |
{ |
43 |
private static final String LINE_FEED_CHARACTRER = "\n"; //$NON-NLS-1$ |
|
|
44 |
private static final String CARRIAGE_RETURN_CHARACTRER = "\r"; //$NON-NLS-1$ |
| 45 |
|
| 46 |
public static DatapoolClipboard getInstance(){ |
| 47 |
|
| 48 |
if(instance == null){ |
| 49 |
instance = new DatapoolClipboard(); |
| 50 |
} |
| 51 |
|
| 48 |
return instance; |
52 |
return instance; |
| 49 |
} |
53 |
} |
| 50 |
|
54 |
|
| 51 |
protected DatapoolClipboard() |
55 |
private DatapoolClipboard(){ |
| 52 |
{ |
56 |
|
| 53 |
recordData = new Vector(); |
57 |
recordData = new Vector(); |
| 54 |
recordStringData = new Vector(); |
58 |
recordStringData = new Vector(); |
| 55 |
} |
59 |
} |
|
Lines 125-141
Link Here
|
| 125 |
TextTransfer transfer = TextTransfer.getInstance(); |
129 |
TextTransfer transfer = TextTransfer.getInstance(); |
| 126 |
String data = (String)clipboard.getContents(transfer); |
130 |
String data = (String)clipboard.getContents(transfer); |
| 127 |
|
131 |
|
| 128 |
StringTokenizer dataTokenizer = new StringTokenizer(data, LINEFEED); |
132 |
StringTokenizer dataTokenizer = new StringTokenizer(data, LINE_FEED_CHARACTRER); |
| 129 |
int count = 0; |
133 |
int count = 0; |
| 130 |
boolean isDatapoolData = true; |
134 |
boolean isDatapoolData = true; |
| 131 |
while(dataTokenizer.hasMoreTokens()) |
135 |
while(dataTokenizer.hasMoreTokens()) |
| 132 |
{ |
136 |
{ |
| 133 |
String line = dataTokenizer.nextToken(); |
137 |
String line = dataTokenizer.nextToken(); |
| 134 |
if(line.endsWith(CARRIAGERETURN)) |
138 |
if(line.endsWith(CARRIAGE_RETURN_CHARACTRER)) |
| 135 |
line = line.replaceAll(CARRIAGERETURN, new String()); |
139 |
line = line.replaceAll(CARRIAGE_RETURN_CHARACTRER, new String()); |
| 136 |
line = line.concat(LINEFEED); |
140 |
line = line.concat(LINE_FEED_CHARACTRER); |
| 137 |
if(!line.equals(constructClipboardData()[count])) |
141 |
|
| 138 |
{ |
142 |
if(!line.equals(getRecordStringData(count))){ |
| 139 |
isDatapoolData = false; |
143 |
isDatapoolData = false; |
| 140 |
break; |
144 |
break; |
| 141 |
} |
145 |
} |
|
Lines 146-174
Link Here
|
| 146 |
return recordData.toArray(); |
150 |
return recordData.toArray(); |
| 147 |
|
151 |
|
| 148 |
Vector dataSet = new Vector(); |
152 |
Vector dataSet = new Vector(); |
| 149 |
StringTokenizer lfTokenizer = new StringTokenizer(data, LINEFEED); |
153 |
StringTokenizer lfTokenizer = new StringTokenizer(data, LINE_FEED_CHARACTRER); |
| 150 |
while(lfTokenizer.hasMoreTokens()) |
154 |
while(lfTokenizer.hasMoreTokens()) |
| 151 |
{ |
155 |
{ |
| 152 |
String line = lfTokenizer.nextToken(); |
156 |
String line = lfTokenizer.nextToken(); |
| 153 |
if(line.endsWith(CARRIAGERETURN)) |
157 |
if(line.endsWith(CARRIAGE_RETURN_CHARACTRER)) |
| 154 |
line = line.replaceAll(CARRIAGERETURN, new String()); |
158 |
line = line.replaceAll(CARRIAGE_RETURN_CHARACTRER, new String()); |
| 155 |
|
159 |
|
| 156 |
int index = line.indexOf(SEPERATOR); |
160 |
int index = line.indexOf(SEPERATOR_CHARACTRER); |
| 157 |
int numTokens = 1; |
161 |
int numTokens = 1; |
| 158 |
while(index != -1) |
162 |
while(index != -1) |
| 159 |
{ |
163 |
{ |
| 160 |
numTokens++; |
164 |
numTokens++; |
| 161 |
index = line.indexOf(SEPERATOR, index + 1); |
165 |
index = line.indexOf(SEPERATOR_CHARACTRER, index + 1); |
| 162 |
} |
166 |
} |
| 163 |
|
167 |
|
| 164 |
String[] cellContents = new String[numTokens]; |
168 |
String[] cellContents = new String[numTokens]; |
| 165 |
count = 0; |
169 |
count = 0; |
| 166 |
index = line.indexOf(SEPERATOR); |
170 |
index = line.indexOf(SEPERATOR_CHARACTRER); |
| 167 |
while(index != -1) |
171 |
while(index != -1) |
| 168 |
{ |
172 |
{ |
| 169 |
cellContents[count] = line.substring(0, index); |
173 |
cellContents[count] = line.substring(0, index); |
| 170 |
line = line.substring(index + 1); |
174 |
line = line.substring(index + 1); |
| 171 |
index = line.indexOf(SEPERATOR); |
175 |
index = line.indexOf(SEPERATOR_CHARACTRER); |
| 172 |
count++; |
176 |
count++; |
| 173 |
} |
177 |
} |
| 174 |
cellContents[count] = line; |
178 |
cellContents[count] = line; |
|
Lines 177-201
Link Here
|
| 177 |
return dataSet.toArray(); |
181 |
return dataSet.toArray(); |
| 178 |
} |
182 |
} |
| 179 |
|
183 |
|
| 180 |
public void update() |
184 |
/** |
| 181 |
{ |
185 |
* <p>Update the system clipboard with the datapool clipboard data.</p> |
| 182 |
TextTransfer transfer = TextTransfer.getInstance(); |
186 |
* |
| 183 |
if(recordStringData.size() > 0) |
187 |
* @see Clipboard#setContents(Object[], Transfer[]) |
| 184 |
{ |
188 |
*/ |
| 185 |
int recordCount = recordStringData.size(); |
189 |
public void update(){ |
| 186 |
Transfer[] transfers = new Transfer[recordCount]; |
190 |
|
| 187 |
String[] data = constructClipboardData(); |
191 |
if(recordStringData.size() > 0){ |
| 188 |
for(int i = 0; i < recordCount; i++) |
192 |
clipboard.setContents(new Object[]{getRecordStringData()}, new Transfer[]{TextTransfer.getInstance()}); |
| 189 |
{ |
|
|
| 190 |
transfers[i] = transfer; |
| 191 |
} |
| 192 |
clipboard.setContents(data, transfers); |
| 193 |
} |
193 |
} |
| 194 |
else |
194 |
else{ |
| 195 |
{ |
195 |
clipboard.setContents(new Object[]{cellStringData}, new Transfer[]{TextTransfer.getInstance()}); |
| 196 |
Object[] data = {cellStringData}; |
|
|
| 197 |
Transfer[] transfers = {transfer}; |
| 198 |
clipboard.setContents(data, transfers); |
| 199 |
} |
196 |
} |
| 200 |
} |
197 |
} |
| 201 |
|
198 |
|
|
Lines 239-273
Link Here
|
| 239 |
this.clipboard = clipboard; |
236 |
this.clipboard = clipboard; |
| 240 |
} |
237 |
} |
| 241 |
|
238 |
|
| 242 |
private String[] constructClipboardData() |
239 |
|
| 243 |
{ |
240 |
private String getRecordStringData(int recordIndex){ |
| 244 |
if(recordStringData.size() > 0) |
241 |
|
| 245 |
{ |
242 |
StringBuffer recordStringBuffer = new StringBuffer(); |
| 246 |
int recordCount = recordStringData.size(); |
243 |
|
| 247 |
String[] data = new String[recordCount]; |
244 |
if(recordStringData.size() > 0){ |
| 248 |
for(int i = 0; i < recordCount; i++) |
245 |
|
| 249 |
{ |
246 |
Object[] recordStrings = ((Object[])(recordStringData.get(recordIndex))); |
| 250 |
Object[] rawRecordData = (Object[])recordStringData.get(i); |
247 |
|
| 251 |
String processedRecordData = new String(); |
248 |
for(int counter = 0; counter < recordStrings.length; counter++){ |
| 252 |
for(int j = 0; j < rawRecordData.length; j++) |
249 |
|
| 253 |
{ |
250 |
if(recordStringBuffer.length() > 0){ |
| 254 |
if(j == 0) |
251 |
recordStringBuffer.append(SEPERATOR_CHARACTRER); |
| 255 |
processedRecordData = (String)rawRecordData[j]; |
|
|
| 256 |
else |
| 257 |
{ |
| 258 |
processedRecordData = processedRecordData.concat(SEPERATOR).concat((String)rawRecordData[j]); |
| 259 |
} |
| 260 |
|
| 261 |
} |
252 |
} |
| 262 |
processedRecordData = processedRecordData.concat(LINEFEED); |
253 |
|
| 263 |
data[i] = processedRecordData; |
254 |
recordStringBuffer.append(recordStrings[counter]); |
| 264 |
} |
255 |
} |
| 265 |
return data; |
256 |
|
|
|
257 |
recordStringBuffer.append(LINE_FEED_CHARACTRER); |
| 266 |
} |
258 |
} |
| 267 |
else |
259 |
|
| 268 |
{ |
260 |
return (recordStringBuffer.toString()); |
| 269 |
String[] data = {new String()}; |
261 |
} |
| 270 |
return data; |
262 |
|
|
|
263 |
private String getRecordStringData(){ |
| 264 |
|
| 265 |
StringBuffer recordStringBuffer = new StringBuffer(); |
| 266 |
|
| 267 |
if(recordStringData.size() > 0){ |
| 268 |
|
| 269 |
for(int counter = 0; counter < recordStringData.size(); counter++){ |
| 270 |
recordStringBuffer.append(getRecordStringData(counter)); |
| 271 |
} |
| 271 |
} |
272 |
} |
|
|
273 |
|
| 274 |
return (recordStringBuffer.toString()); |
| 272 |
} |
275 |
} |
| 273 |
} |
276 |
} |