|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
******************************************************************************/ |
| 11 |
|
| 12 |
package org.eclipse.ui.internal.views.markers; |
| 13 |
|
| 14 |
import java.util.ArrayList; |
| 15 |
import java.util.Arrays; |
| 16 |
import java.util.Iterator; |
| 17 |
import java.util.List; |
| 18 |
import java.util.ListIterator; |
| 19 |
import java.util.Random; |
| 20 |
|
| 21 |
import org.eclipse.jface.dialogs.Dialog; |
| 22 |
import org.eclipse.jface.resource.JFaceResources; |
| 23 |
import org.eclipse.jface.viewers.ISelection; |
| 24 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 25 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
| 26 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 27 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
| 28 |
import org.eclipse.jface.viewers.LabelProvider; |
| 29 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 30 |
import org.eclipse.jface.viewers.TableViewer; |
| 31 |
import org.eclipse.jface.viewers.Viewer; |
| 32 |
import org.eclipse.swt.SWT; |
| 33 |
import org.eclipse.swt.custom.CLabel; |
| 34 |
import org.eclipse.swt.events.ModifyEvent; |
| 35 |
import org.eclipse.swt.events.ModifyListener; |
| 36 |
import org.eclipse.swt.graphics.Image; |
| 37 |
import org.eclipse.swt.layout.FillLayout; |
| 38 |
import org.eclipse.swt.layout.GridData; |
| 39 |
import org.eclipse.swt.layout.GridLayout; |
| 40 |
import org.eclipse.swt.widgets.Button; |
| 41 |
import org.eclipse.swt.widgets.Composite; |
| 42 |
import org.eclipse.swt.widgets.Control; |
| 43 |
import org.eclipse.swt.widgets.Display; |
| 44 |
import org.eclipse.swt.widgets.Event; |
| 45 |
import org.eclipse.swt.widgets.Group; |
| 46 |
import org.eclipse.swt.widgets.Label; |
| 47 |
import org.eclipse.swt.widgets.Listener; |
| 48 |
import org.eclipse.swt.widgets.Shell; |
| 49 |
import org.eclipse.swt.widgets.Table; |
| 50 |
import org.eclipse.swt.widgets.TableColumn; |
| 51 |
import org.eclipse.swt.widgets.Text; |
| 52 |
import org.eclipse.ui.preferences.ViewSettingsDialog; |
| 53 |
import org.eclipse.ui.views.markers.internal.MarkerMessages; |
| 54 |
|
| 55 |
/** |
| 56 |
* This was introduced as a fix to Bug , as an effort to combine the columns and |
| 57 |
* preference dialogs into one. It should be noted that the class can be re-used |
| 58 |
* or turned into a tool for column viewers in general. |
| 59 |
* |
| 60 |
* @since 3.7 |
| 61 |
* |
| 62 |
* @author Hitesh Soliwal |
| 63 |
* |
| 64 |
*/ |
| 65 |
abstract class ViewerColumnsDialog extends ViewSettingsDialog { |
| 66 |
|
| 67 |
/** The list contains columns that are currently visible in viewer */ |
| 68 |
private List visible; |
| 69 |
|
| 70 |
/** The list contains columns that are note shown in viewer */ |
| 71 |
private List nonVisible; |
| 72 |
|
| 73 |
/** |
| 74 |
* The number of elements to show at Max. A zero value may indicate |
| 75 |
* disablement of limit |
| 76 |
*/ |
| 77 |
private int limitValue; |
| 78 |
|
| 79 |
/** The message area */ |
| 80 |
private CLabel messageLabel; |
| 81 |
|
| 82 |
private TableViewer visibleViewer, nonVisibleViewer; |
| 83 |
|
| 84 |
private Button upButton, downButton; |
| 85 |
|
| 86 |
private Button toVisibleBtt, toNonVisibleBtt; |
| 87 |
|
| 88 |
private Text widthText, limitEditor; |
| 89 |
|
| 90 |
/** |
| 91 |
* A listener to validate positive integer numbers only |
| 92 |
*/ |
| 93 |
Listener postivIntTextListener = new Listener() { |
| 94 |
|
| 95 |
private String intialValue; |
| 96 |
|
| 97 |
public void handleEvent(Event event) { |
| 98 |
String string = isValidNumber(event); |
| 99 |
if (string != null) { |
| 100 |
setValid(false, string); |
| 101 |
if (event.type == SWT.FocusOut) { |
| 102 |
Text text = (Text) event.widget; |
| 103 |
text.setText(intialValue != null ? intialValue : Integer |
| 104 |
.toString(0)); |
| 105 |
text.setFocus(); |
| 106 |
text.selectAll(); |
| 107 |
} else { |
| 108 |
event.doit = false; |
| 109 |
} |
| 110 |
return; |
| 111 |
} else if (event.type == SWT.FocusOut) { |
| 112 |
Text text = (Text) event.widget; |
| 113 |
intialValue = text.getText().trim(); |
| 114 |
} else if (event.type == SWT.FocusIn) { |
| 115 |
intialValue = string; |
| 116 |
} |
| 117 |
setValid(true, null); |
| 118 |
} |
| 119 |
|
| 120 |
private String isValidNumber(Event event) { |
| 121 |
Text text = (Text) event.widget; |
| 122 |
String value = text.getText().trim(); |
| 123 |
switch (event.type) { |
| 124 |
case SWT.KeyDown: |
| 125 |
return ((Character.isISOControl(event.character) && value |
| 126 |
.length() != 0) || Character.isDigit(event.character)) ? null |
| 127 |
: errorMessage(); |
| 128 |
case SWT.FocusOut: |
| 129 |
if (value.length() == 0) { |
| 130 |
text.setText(intialValue != null ? intialValue : Integer |
| 131 |
.toString(0)); |
| 132 |
text.selectAll(); |
| 133 |
return null; |
| 134 |
} |
| 135 |
try { |
| 136 |
Integer.parseInt(value); |
| 137 |
return null; |
| 138 |
} catch (Exception e) { |
| 139 |
return e.getLocalizedMessage(); |
| 140 |
} |
| 141 |
} |
| 142 |
return null; |
| 143 |
} |
| 144 |
}; |
| 145 |
|
| 146 |
/** |
| 147 |
* Create a new instance of the receiver. |
| 148 |
* |
| 149 |
* @param parentShell |
| 150 |
*/ |
| 151 |
ViewerColumnsDialog(Shell parentShell) { |
| 152 |
super(parentShell); |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Initialize visible /non-visible columns. |
| 157 |
* |
| 158 |
* @param columnObjs |
| 159 |
*/ |
| 160 |
void setColumnsObjs(Object[] columnObjs) { |
| 161 |
IColumnInfoProvider columnInfo = doGetColumnInfoProvider(); |
| 162 |
IColumnUpdater updater = doGetColumnUpdater(); |
| 163 |
List visible = getVisible(); |
| 164 |
List nonVisible = getNonVisible(); |
| 165 |
visible.clear(); |
| 166 |
nonVisible.clear(); |
| 167 |
Object data = null; |
| 168 |
for (int i = 0; i < columnObjs.length; i++) { |
| 169 |
data = columnObjs[i]; |
| 170 |
if (columnInfo.isColumnVisible(data)) { |
| 171 |
updater.setColumnVisible(data, true); |
| 172 |
updater.setColumnIndex(data, visible.size()); |
| 173 |
visible.add(data); |
| 174 |
} else { |
| 175 |
updater.setColumnVisible(data, false); |
| 176 |
updater.setColumnIndex(data, nonVisible.size()); |
| 177 |
nonVisible.add(data); |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
/* |
| 183 |
* (non-Javadoc) |
| 184 |
* |
| 185 |
* @see |
| 186 |
* org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets |
| 187 |
* .Shell) |
| 188 |
*/ |
| 189 |
protected void configureShell(Shell newShell) { |
| 190 |
super.configureShell(newShell); |
| 191 |
newShell.setText(JFaceResources |
| 192 |
.getString("ConfigureColumnsDialog_Title")); //$NON-NLS-1$ |
| 193 |
} |
| 194 |
|
| 195 |
/* |
| 196 |
* (non-Javadoc) |
| 197 |
* |
| 198 |
* @see org.eclipse.jface.window.Window#getShellStyle() |
| 199 |
*/ |
| 200 |
protected int getShellStyle() { |
| 201 |
return super.getShellStyle() | SWT.RESIZE; |
| 202 |
} |
| 203 |
|
| 204 |
/* |
| 205 |
* (non-Javadoc) |
| 206 |
* |
| 207 |
* @see |
| 208 |
* org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets |
| 209 |
* .Composite) |
| 210 |
*/ |
| 211 |
protected Control createDialogArea(Composite parent) { |
| 212 |
|
| 213 |
Composite dialogArea = (Composite) super.createDialogArea(parent); |
| 214 |
|
| 215 |
dialogArea.setLayout(new GridLayout(1, true)); |
| 216 |
|
| 217 |
initializeDialogUnits(dialogArea); |
| 218 |
|
| 219 |
createMessageArea(dialogArea); |
| 220 |
|
| 221 |
createLimitArea(dialogArea); |
| 222 |
|
| 223 |
createColumnsArea(dialogArea); |
| 224 |
|
| 225 |
applyDialogFont(dialogArea); |
| 226 |
|
| 227 |
return dialogArea; |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Create message area. |
| 232 |
* |
| 233 |
* @param parent |
| 234 |
*/ |
| 235 |
void createMessageArea(Composite parent) { |
| 236 |
messageLabel = new CLabel(parent, SWT.NONE); |
| 237 |
messageLabel.setImage(JFaceResources |
| 238 |
.getImage(Dialog.DLG_IMG_MESSAGE_INFO)); |
| 239 |
messageLabel |
| 240 |
.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); |
| 241 |
} |
| 242 |
|
| 243 |
/** |
| 244 |
* Create element limit area. |
| 245 |
* |
| 246 |
* @param parent |
| 247 |
*/ |
| 248 |
void createLimitArea(Composite parent) { |
| 249 |
Composite composite = new Group(parent, SWT.NONE); |
| 250 |
composite.setLayout(new GridLayout(2, false)); |
| 251 |
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 252 |
|
| 253 |
CLabel cLabel = new CLabel(composite, SWT.NONE); |
| 254 |
cLabel.setText(MarkerMessages.MarkerPreferences_VisibleItems); |
| 255 |
cLabel.setLayoutData(new GridData()); |
| 256 |
|
| 257 |
limitEditor = new Text(composite, SWT.BORDER); |
| 258 |
limitEditor.setText(Integer.toString(getLimitValue())); |
| 259 |
limitEditor.setLayoutData(new GridData()); |
| 260 |
limitEditor.addListener(SWT.FocusIn, postivIntTextListener); |
| 261 |
limitEditor.addListener(SWT.FocusOut, postivIntTextListener); |
| 262 |
limitEditor.addListener(SWT.KeyDown, postivIntTextListener); |
| 263 |
limitEditor.addModifyListener(new ModifyListener() { |
| 264 |
public void modifyText(ModifyEvent e) { |
| 265 |
setLimitValue(Integer.parseInt(limitEditor.getText().trim())); |
| 266 |
} |
| 267 |
}); |
| 268 |
limitEditor.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 269 |
} |
| 270 |
|
| 271 |
/** |
| 272 |
* Create the controls to configure columns. |
| 273 |
* |
| 274 |
* @param dialogArea |
| 275 |
*/ |
| 276 |
void createColumnsArea(Composite dialogArea) { |
| 277 |
Group columnArea = new Group(dialogArea, SWT.NONE); |
| 278 |
columnArea.setLayout(new GridLayout(4, false)); |
| 279 |
GridData gData = new GridData(GridData.FILL_BOTH |
| 280 |
| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL); |
| 281 |
columnArea.setLayoutData(gData); |
| 282 |
columnArea.setText(MarkerMessages.MarkerPreferences_ColumnGroupTitle); |
| 283 |
|
| 284 |
createInvisibleTable(columnArea); |
| 285 |
createMoveButtons(columnArea); |
| 286 |
createVisibleTable(columnArea); |
| 287 |
createUpDownBtt(columnArea); |
| 288 |
createWidthArea(columnArea); |
| 289 |
} |
| 290 |
|
| 291 |
/** |
| 292 |
* The Up and Down button to change column ordering. |
| 293 |
* |
| 294 |
* @param parent |
| 295 |
*/ |
| 296 |
void createUpDownBtt(Composite parent) { |
| 297 |
Composite composite = new Composite(parent, SWT.NONE); |
| 298 |
composite.setLayout(new GridLayout(1, true)); |
| 299 |
composite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); |
| 300 |
upButton = new Button(composite, SWT.PUSH); |
| 301 |
upButton.setText(JFaceResources.getString("ConfigureColumnsDialog_up")); //$NON-NLS-1$ |
| 302 |
upButton.addListener(SWT.Selection, new Listener() { |
| 303 |
public void handleEvent(Event event) { |
| 304 |
handleUpButton(event); |
| 305 |
} |
| 306 |
}); |
| 307 |
upButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 308 |
upButton.setEnabled(false); |
| 309 |
|
| 310 |
downButton = new Button(composite, SWT.PUSH); |
| 311 |
downButton.setText(JFaceResources |
| 312 |
.getString("ConfigureColumnsDialog_down")); //$NON-NLS-1$ |
| 313 |
downButton.addListener(SWT.Selection, new Listener() { |
| 314 |
public void handleEvent(Event event) { |
| 315 |
handleDownButton(event); |
| 316 |
} |
| 317 |
}); |
| 318 |
downButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 319 |
downButton.setEnabled(false); |
| 320 |
} |
| 321 |
|
| 322 |
/** |
| 323 |
* Create the controls responsible to display/edit column widths. |
| 324 |
* |
| 325 |
* @param parent |
| 326 |
*/ |
| 327 |
void createWidthArea(Composite parent) { |
| 328 |
Label widthLabel = new Label(parent, SWT.NONE); |
| 329 |
widthLabel.setText(JFaceResources |
| 330 |
.getString("ConfigureColumnsDialog_WidthOfSelectedColumn")); //$NON-NLS-1$ |
| 331 |
GridData gridData = new GridData(GridData.FILL_HORIZONTAL |
| 332 |
| GridData.HORIZONTAL_ALIGN_END); |
| 333 |
gridData.horizontalSpan = 3; |
| 334 |
widthLabel.setLayoutData(gridData); |
| 335 |
|
| 336 |
widthText = new Text(parent, SWT.SINGLE | SWT.BORDER); |
| 337 |
widthText.setText(Integer.toString(0)); |
| 338 |
gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); |
| 339 |
gridData.widthHint = convertWidthInCharsToPixels(5); |
| 340 |
widthText.setLayoutData(gridData); |
| 341 |
widthText.addListener(SWT.FocusIn, postivIntTextListener); |
| 342 |
widthText.addListener(SWT.FocusOut, postivIntTextListener); |
| 343 |
widthText.addListener(SWT.KeyDown, postivIntTextListener); |
| 344 |
widthText.addModifyListener(new ModifyListener() { |
| 345 |
public void modifyText(ModifyEvent e) { |
| 346 |
if (widthText.isEnabled()) { |
| 347 |
Object data = ((IStructuredSelection) visibleViewer |
| 348 |
.getSelection()).getFirstElement(); |
| 349 |
if (data != null) { |
| 350 |
IColumnUpdater updater = getColumnUpdater(); |
| 351 |
updater.setColumnWidth(data, |
| 352 |
Integer.parseInt(widthText.getText().trim())); |
| 353 |
} |
| 354 |
} |
| 355 |
} |
| 356 |
}); |
| 357 |
widthText.setEditable(false); |
| 358 |
} |
| 359 |
|
| 360 |
/** |
| 361 |
* Adapter to {@link IStructuredContentProvider} |
| 362 |
*/ |
| 363 |
abstract class ContentProviderAdapter implements IStructuredContentProvider { |
| 364 |
|
| 365 |
public void dispose() { |
| 366 |
} |
| 367 |
|
| 368 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* Creates the table that lists out visible columns in the viewer |
| 374 |
* |
| 375 |
* @param parent |
| 376 |
*/ |
| 377 |
void createVisibleTable(Composite parent) { |
| 378 |
final Table table = new Table(parent, SWT.BORDER | SWT.MULTI); |
| 379 |
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); |
| 380 |
data.widthHint = convertWidthInCharsToPixels(30); |
| 381 |
data.heightHint = table.getItemHeight() * 15; |
| 382 |
table.setLayoutData(data); |
| 383 |
table.setHeaderVisible(true); |
| 384 |
|
| 385 |
final TableColumn column = new TableColumn(table, SWT.NONE); |
| 386 |
column.setText(MarkerMessages.MarkerPreferences_VisibleColumnsTitle); |
| 387 |
Listener columnResize = new Listener() { |
| 388 |
public void handleEvent(Event event) { |
| 389 |
column.setWidth(table.getClientArea().width); |
| 390 |
} |
| 391 |
}; |
| 392 |
table.addListener(SWT.Resize, columnResize); |
| 393 |
|
| 394 |
visibleViewer = new TableViewer(table); |
| 395 |
visibleViewer.setLabelProvider(doGetLabelProvider()); |
| 396 |
visibleViewer.setContentProvider(new ContentProviderAdapter() { |
| 397 |
public Object[] getElements(Object inputElement) { |
| 398 |
return getVisible().toArray(); |
| 399 |
} |
| 400 |
}); |
| 401 |
visibleViewer |
| 402 |
.addSelectionChangedListener(new ISelectionChangedListener() { |
| 403 |
public void selectionChanged(SelectionChangedEvent event) { |
| 404 |
handleVisibleSelection(event.getSelection()); |
| 405 |
} |
| 406 |
}); |
| 407 |
table.addListener(SWT.MouseDoubleClick, new Listener() { |
| 408 |
public void handleEvent(Event event) { |
| 409 |
handleToNonVisibleButton(event); |
| 410 |
} |
| 411 |
}); |
| 412 |
visibleViewer.setInput(this); |
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* Creates the table that lists out non-visible columns in the viewer |
| 417 |
* |
| 418 |
* @param parent |
| 419 |
*/ |
| 420 |
void createInvisibleTable(Composite parent) { |
| 421 |
final Table table = new Table(parent, SWT.BORDER | SWT.MULTI); |
| 422 |
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); |
| 423 |
data.widthHint = convertWidthInCharsToPixels(30); |
| 424 |
data.heightHint = table.getItemHeight() * 15; |
| 425 |
table.setLayoutData(data); |
| 426 |
table.setHeaderVisible(true); |
| 427 |
|
| 428 |
final TableColumn column = new TableColumn(table, SWT.NONE); |
| 429 |
column.setText(MarkerMessages.MarkerPreferences_HiddenColumnsTitle); |
| 430 |
Listener columnResize = new Listener() { |
| 431 |
public void handleEvent(Event event) { |
| 432 |
column.setWidth(table.getClientArea().width); |
| 433 |
} |
| 434 |
}; |
| 435 |
table.addListener(SWT.Resize, columnResize); |
| 436 |
|
| 437 |
nonVisibleViewer = new TableViewer(table); |
| 438 |
nonVisibleViewer.setLabelProvider(doGetLabelProvider()); |
| 439 |
nonVisibleViewer.setContentProvider(new ContentProviderAdapter() { |
| 440 |
public Object[] getElements(Object inputElement) { |
| 441 |
return getNonVisible().toArray(); |
| 442 |
} |
| 443 |
}); |
| 444 |
nonVisibleViewer |
| 445 |
.addSelectionChangedListener(new ISelectionChangedListener() { |
| 446 |
public void selectionChanged(SelectionChangedEvent event) { |
| 447 |
handleNonVisibleSelection(event.getSelection()); |
| 448 |
} |
| 449 |
}); |
| 450 |
table.addListener(SWT.MouseDoubleClick, new Listener() { |
| 451 |
public void handleEvent(Event event) { |
| 452 |
handleToVisibleButton(event); |
| 453 |
} |
| 454 |
}); |
| 455 |
nonVisibleViewer.setInput(this); |
| 456 |
} |
| 457 |
|
| 458 |
/** |
| 459 |
* Creates buttons for moving columns from non-visible to visible and |
| 460 |
* vice-versa |
| 461 |
* |
| 462 |
* @param parent |
| 463 |
*/ |
| 464 |
void createMoveButtons(Composite parent) { |
| 465 |
Composite bttArea = new Composite(parent, SWT.NONE); |
| 466 |
bttArea.setLayout(new GridLayout(1, true)); |
| 467 |
bttArea.setLayoutData(new GridData(GridData.FILL_VERTICAL)); |
| 468 |
|
| 469 |
toNonVisibleBtt = new Button(bttArea, SWT.PUSH); |
| 470 |
toNonVisibleBtt |
| 471 |
.setText(getDefaultOrientation() == SWT.RIGHT_TO_LEFT ? MarkerMessages.MarkerPreferences_MoveRight |
| 472 |
: MarkerMessages.MarkerPreferences_MoveLeft); |
| 473 |
toNonVisibleBtt.setLayoutData(new GridData()); |
| 474 |
|
| 475 |
toNonVisibleBtt.addListener(SWT.Selection, new Listener() { |
| 476 |
public void handleEvent(Event event) { |
| 477 |
handleToNonVisibleButton(event); |
| 478 |
} |
| 479 |
}); |
| 480 |
toNonVisibleBtt.setEnabled(false); |
| 481 |
|
| 482 |
toVisibleBtt = new Button(bttArea, SWT.PUSH); |
| 483 |
toVisibleBtt |
| 484 |
.setText(getDefaultOrientation() == SWT.RIGHT_TO_LEFT ? MarkerMessages.MarkerPreferences_MoveLeft |
| 485 |
: MarkerMessages.MarkerPreferences_MoveRight); |
| 486 |
toVisibleBtt.setLayoutData(new GridData()); |
| 487 |
toVisibleBtt.addListener(SWT.Selection, new Listener() { |
| 488 |
public void handleEvent(Event event) { |
| 489 |
handleToVisibleButton(event); |
| 490 |
} |
| 491 |
}); |
| 492 |
toVisibleBtt.setEnabled(false); |
| 493 |
} |
| 494 |
|
| 495 |
/** |
| 496 |
* Display the error message and an appropriate icon. |
| 497 |
* |
| 498 |
* @param state |
| 499 |
*/ |
| 500 |
void setValid(boolean state, String errorMessage) { |
| 501 |
if (state) { |
| 502 |
messageLabel.setImage(JFaceResources |
| 503 |
.getImage(Dialog.DLG_IMG_MESSAGE_INFO)); |
| 504 |
messageLabel |
| 505 |
.setText(MarkerMessages.MarkerPreferences_Zero_Or_Blank_Value_Indicates_No_Limit); |
| 506 |
} else { |
| 507 |
messageLabel.setImage(JFaceResources |
| 508 |
.getImage(Dialog.DLG_IMG_MESSAGE_ERROR)); |
| 509 |
messageLabel.setText(errorMessage); |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
/* |
| 514 |
* (non-Javadoc) |
| 515 |
* |
| 516 |
* @see org.eclipse.ui.preferences.ViewSettingsDialog#performDefaults() |
| 517 |
*/ |
| 518 |
protected void performDefaults() { |
| 519 |
refreshViewers(); |
| 520 |
super.performDefaults(); |
| 521 |
} |
| 522 |
|
| 523 |
/** |
| 524 |
* Handles a selection change in the viewer that lists out the non-visible |
| 525 |
* columns |
| 526 |
* |
| 527 |
* @param selection |
| 528 |
*/ |
| 529 |
void handleNonVisibleSelection(ISelection selection) { |
| 530 |
Object[] nvKeys = ((IStructuredSelection) selection).toArray(); |
| 531 |
toVisibleBtt.setEnabled(nvKeys.length > 0); |
| 532 |
} |
| 533 |
|
| 534 |
/** |
| 535 |
* Handles a selection change in the viewer that lists out the visible |
| 536 |
* columns. Takes care of various enablements. |
| 537 |
* |
| 538 |
* @param selection |
| 539 |
*/ |
| 540 |
void handleVisibleSelection(ISelection selection) { |
| 541 |
List selVCols = ((IStructuredSelection) selection).toList(); |
| 542 |
List allVCols = getVisible(); |
| 543 |
toNonVisibleBtt.setEnabled(selVCols.size() > 0 |
| 544 |
&& allVCols.size() > selVCols.size()); |
| 545 |
|
| 546 |
IColumnInfoProvider infoProvider = doGetColumnInfoProvider(); |
| 547 |
boolean moveDown = !selVCols.isEmpty(), moveUp = !selVCols.isEmpty(); |
| 548 |
Iterator iterator = selVCols.iterator(); |
| 549 |
while (iterator.hasNext()) { |
| 550 |
Object columnObj = iterator.next(); |
| 551 |
if (!infoProvider.isColumnMovable(columnObj)) { |
| 552 |
moveUp = false; |
| 553 |
moveDown = false; |
| 554 |
break; |
| 555 |
} |
| 556 |
int i = allVCols.indexOf(columnObj); |
| 557 |
if (i == 0) { |
| 558 |
moveUp = false; |
| 559 |
if (!moveDown) { |
| 560 |
break; |
| 561 |
} |
| 562 |
} |
| 563 |
if (i == (allVCols.size() - 1)) { |
| 564 |
moveDown = false; |
| 565 |
if (!moveUp) { |
| 566 |
break; |
| 567 |
} |
| 568 |
} |
| 569 |
} |
| 570 |
upButton.setEnabled(moveUp); |
| 571 |
downButton.setEnabled(moveDown); |
| 572 |
|
| 573 |
boolean edit = selVCols.size() == 1 ? infoProvider |
| 574 |
.isColumnResizable(selVCols.get(0)) : false; |
| 575 |
if (edit) { |
| 576 |
widthText.setText(Integer.toString(infoProvider |
| 577 |
.getColumnWidth(selVCols.get(0)))); |
| 578 |
} else { |
| 579 |
widthText.setText(Integer.toString(0)); |
| 580 |
} |
| 581 |
widthText.setEditable(edit); |
| 582 |
|
| 583 |
} |
| 584 |
|
| 585 |
/** |
| 586 |
* Applies to visible columns, and handles the changes in the order of |
| 587 |
* columns |
| 588 |
* |
| 589 |
* @param e |
| 590 |
* event from the button click |
| 591 |
*/ |
| 592 |
void handleDownButton(Event e) { |
| 593 |
IStructuredSelection selection = (IStructuredSelection) visibleViewer |
| 594 |
.getSelection(); |
| 595 |
Object[] selVCols = selection.toArray(); |
| 596 |
List allVCols = getVisible(); |
| 597 |
IColumnUpdater updater = doGetColumnUpdater(); |
| 598 |
for (int i = selVCols.length - 1; i >= 0; i--) { |
| 599 |
Object colObj = selVCols[i]; |
| 600 |
int index = allVCols.indexOf(colObj); |
| 601 |
updater.setColumnIndex(colObj, index + 1); |
| 602 |
allVCols.remove(index); |
| 603 |
allVCols.add(index + 1, colObj); |
| 604 |
} |
| 605 |
visibleViewer.refresh(); |
| 606 |
handleVisibleSelection(selection); |
| 607 |
} |
| 608 |
|
| 609 |
/** |
| 610 |
* Applies to visible columns, and handles the changes in the order of |
| 611 |
* columns |
| 612 |
* |
| 613 |
* @param e |
| 614 |
* event from the button click |
| 615 |
*/ |
| 616 |
void handleUpButton(Event e) { |
| 617 |
IStructuredSelection selection = (IStructuredSelection) visibleViewer |
| 618 |
.getSelection(); |
| 619 |
Object[] selVCols = selection.toArray(); |
| 620 |
List allVCols = getVisible(); |
| 621 |
IColumnUpdater updater = doGetColumnUpdater(); |
| 622 |
for (int i = 0; i < selVCols.length; i++) { |
| 623 |
Object colObj = selVCols[i]; |
| 624 |
int index = allVCols.indexOf(colObj); |
| 625 |
updater.setColumnIndex(colObj, index - 1); |
| 626 |
allVCols.remove(index); |
| 627 |
allVCols.add(index - 1, colObj); |
| 628 |
} |
| 629 |
visibleViewer.refresh(); |
| 630 |
handleVisibleSelection(selection); |
| 631 |
} |
| 632 |
|
| 633 |
/** |
| 634 |
* Moves selected columns from non-visible to visible state |
| 635 |
* |
| 636 |
* @param e |
| 637 |
* event from the button click |
| 638 |
*/ |
| 639 |
void handleToVisibleButton(Event e) { |
| 640 |
IStructuredSelection selection = (IStructuredSelection) nonVisibleViewer |
| 641 |
.getSelection(); |
| 642 |
List selVCols = selection.toList(); |
| 643 |
List nonVisible = getNonVisible(); |
| 644 |
nonVisible.removeAll(selVCols); |
| 645 |
|
| 646 |
List list = getVisible(); |
| 647 |
list.addAll(selVCols); |
| 648 |
|
| 649 |
updateVisibility(selVCols, true); |
| 650 |
updateIndices(getVisible()); |
| 651 |
updateIndices(getNonVisible()); |
| 652 |
|
| 653 |
visibleViewer.refresh(); |
| 654 |
visibleViewer.setSelection(selection); |
| 655 |
nonVisibleViewer.refresh(); |
| 656 |
handleVisibleSelection(selection); |
| 657 |
handleNonVisibleSelection(nonVisibleViewer.getSelection()); |
| 658 |
} |
| 659 |
|
| 660 |
/** |
| 661 |
* Moves selected columns from visible to non-visible state |
| 662 |
* |
| 663 |
* @param e |
| 664 |
* event from the button click |
| 665 |
*/ |
| 666 |
protected void handleToNonVisibleButton(Event e) { |
| 667 |
IStructuredSelection selection = (IStructuredSelection) visibleViewer |
| 668 |
.getSelection(); |
| 669 |
List selVCols = selection.toList(); |
| 670 |
getVisible().removeAll(selVCols); |
| 671 |
getNonVisible().addAll(selVCols); |
| 672 |
|
| 673 |
updateVisibility(selVCols, false); |
| 674 |
updateIndices(getVisible()); |
| 675 |
updateIndices(getNonVisible()); |
| 676 |
|
| 677 |
nonVisibleViewer.refresh(); |
| 678 |
nonVisibleViewer.setSelection(selection); |
| 679 |
visibleViewer.refresh(); |
| 680 |
handleVisibleSelection(visibleViewer.getSelection()); |
| 681 |
handleNonVisibleSelection(nonVisibleViewer.getSelection()); |
| 682 |
} |
| 683 |
|
| 684 |
void updateIndices(List list) { |
| 685 |
ListIterator iterator = list.listIterator(); |
| 686 |
IColumnUpdater updater = doGetColumnUpdater(); |
| 687 |
while (iterator.hasNext()) { |
| 688 |
updater.setColumnIndex(iterator.next(), iterator.previousIndex()); |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
void updateVisibility(List list, boolean visibility) { |
| 693 |
IColumnUpdater updater = doGetColumnUpdater(); |
| 694 |
Iterator iterator = list.iterator(); |
| 695 |
while (iterator.hasNext()) { |
| 696 |
updater.setColumnVisible(iterator.next(), visibility); |
| 697 |
} |
| 698 |
} |
| 699 |
|
| 700 |
/** |
| 701 |
* Updates the UI based on values of the variable |
| 702 |
*/ |
| 703 |
void refreshViewers() { |
| 704 |
if (limitEditor != null) { |
| 705 |
limitEditor.setText(Integer.toString(getLimitValue())); |
| 706 |
} |
| 707 |
if (nonVisibleViewer != null) { |
| 708 |
nonVisibleViewer.refresh(); |
| 709 |
} |
| 710 |
if (visibleViewer != null) { |
| 711 |
visibleViewer.refresh(); |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
/* |
| 716 |
* (non-Javadoc) |
| 717 |
* |
| 718 |
* @see org.eclipse.jface.dialogs.Dialog#isResizable() |
| 719 |
*/ |
| 720 |
protected boolean isResizable() { |
| 721 |
return true; |
| 722 |
} |
| 723 |
|
| 724 |
/* |
| 725 |
* (non-Javadoc) |
| 726 |
* |
| 727 |
* @see org.eclipse.jface.dialogs.Dialog#okPressed() |
| 728 |
*/ |
| 729 |
protected void okPressed() { |
| 730 |
super.okPressed(); |
| 731 |
} |
| 732 |
|
| 733 |
/** |
| 734 |
* @return Returns the limitValue. |
| 735 |
*/ |
| 736 |
public int getLimitValue() { |
| 737 |
return limitValue; |
| 738 |
} |
| 739 |
|
| 740 |
/** |
| 741 |
* @param limitValue |
| 742 |
* The limitValue to set. |
| 743 |
*/ |
| 744 |
void setLimitValue(int limitValue) { |
| 745 |
this.limitValue = limitValue; |
| 746 |
} |
| 747 |
|
| 748 |
/** |
| 749 |
* @return List of visible columns |
| 750 |
*/ |
| 751 |
public List getVisible() { |
| 752 |
if (visible == null) { |
| 753 |
visible = new ArrayList(); |
| 754 |
} |
| 755 |
return visible; |
| 756 |
} |
| 757 |
|
| 758 |
/** |
| 759 |
* @return List of non-visible columns |
| 760 |
*/ |
| 761 |
public List getNonVisible() { |
| 762 |
if (nonVisible == null) { |
| 763 |
nonVisible = new ArrayList(); |
| 764 |
} |
| 765 |
return nonVisible; |
| 766 |
} |
| 767 |
|
| 768 |
/** |
| 769 |
* @return Returns the error message to display for a wrong limit value. |
| 770 |
*/ |
| 771 |
String errorMessage() { |
| 772 |
return JFaceResources.getString("IntegerFieldEditor.errorMessage"); //$NON-NLS-1$ |
| 773 |
} |
| 774 |
|
| 775 |
/** |
| 776 |
* An adapter class to {@link ITableLabelProvider} |
| 777 |
* |
| 778 |
*/ |
| 779 |
class TableLabelProvider extends LabelProvider implements |
| 780 |
ITableLabelProvider { |
| 781 |
public Image getColumnImage(Object element, int columnIndex) { |
| 782 |
return null; |
| 783 |
} |
| 784 |
|
| 785 |
public String getColumnText(Object element, int columnIndex) { |
| 786 |
return getText(element); |
| 787 |
} |
| 788 |
} |
| 789 |
|
| 790 |
/** |
| 791 |
* Internal helper to @see {@link ViewerColumnsDialog#getLabelProvider()} |
| 792 |
*/ |
| 793 |
ITableLabelProvider doGetLabelProvider() { |
| 794 |
return getLabelProvider(); |
| 795 |
} |
| 796 |
|
| 797 |
/** |
| 798 |
* The tables-columns need to be displayed appropriately. The supplied |
| 799 |
* column objects are adapted to text and image as dictacted by this |
| 800 |
* {@link ITableLabelProvider} |
| 801 |
*/ |
| 802 |
protected abstract ITableLabelProvider getLabelProvider(); |
| 803 |
|
| 804 |
/** |
| 805 |
* Internal helper to @see |
| 806 |
* {@link ViewerColumnsDialog#getColumnInfoProvider()} |
| 807 |
*/ |
| 808 |
IColumnInfoProvider doGetColumnInfoProvider() { |
| 809 |
return getColumnInfoProvider(); |
| 810 |
} |
| 811 |
|
| 812 |
/** |
| 813 |
* To configure the columns we need further information. The supplied column |
| 814 |
* objects are adapted for its properties via {@link IColumnInfoProvider} |
| 815 |
*/ |
| 816 |
protected abstract IColumnInfoProvider getColumnInfoProvider(); |
| 817 |
|
| 818 |
/** |
| 819 |
* Internal helper to @see {@link ViewerColumnsDialog#getColumnUpdater()} |
| 820 |
*/ |
| 821 |
IColumnUpdater doGetColumnUpdater() { |
| 822 |
return getColumnUpdater(); |
| 823 |
} |
| 824 |
|
| 825 |
/** |
| 826 |
* To configure properties/order of the columns is achieved via |
| 827 |
* {@link IColumnUpdater} |
| 828 |
*/ |
| 829 |
protected abstract IColumnUpdater getColumnUpdater(); |
| 830 |
|
| 831 |
/** |
| 832 |
* Update various aspects of a columns from a viewer such |
| 833 |
* {@link TableViewer} |
| 834 |
*/ |
| 835 |
public interface IColumnInfoProvider { |
| 836 |
|
| 837 |
/** |
| 838 |
* Get corresponding index for the column |
| 839 |
* |
| 840 |
* @param columnObj |
| 841 |
*/ |
| 842 |
public int getColumnIndex(Object columnObj); |
| 843 |
|
| 844 |
/** |
| 845 |
* Get the width of the column |
| 846 |
* |
| 847 |
* @param columnObj |
| 848 |
*/ |
| 849 |
public int getColumnWidth(Object columnObj); |
| 850 |
|
| 851 |
/** |
| 852 |
* Returns true if the column represented by parameters is showing in |
| 853 |
* the viewer |
| 854 |
* |
| 855 |
* @param columnObj |
| 856 |
*/ |
| 857 |
public boolean isColumnVisible(Object columnObj); |
| 858 |
|
| 859 |
/** |
| 860 |
* Returns true if the column represented by parameters is configured as |
| 861 |
* movable |
| 862 |
* |
| 863 |
* @param columnObj |
| 864 |
*/ |
| 865 |
public boolean isColumnMovable(Object columnObj); |
| 866 |
|
| 867 |
/** |
| 868 |
* Returns true if the column represented by parameters is configured as |
| 869 |
* resizable |
| 870 |
* |
| 871 |
* @param columnObj |
| 872 |
*/ |
| 873 |
public boolean isColumnResizable(Object columnObj); |
| 874 |
|
| 875 |
} |
| 876 |
|
| 877 |
/** |
| 878 |
* Update various aspects of a columns from a viewer such |
| 879 |
* {@link TableViewer} |
| 880 |
*/ |
| 881 |
public interface IColumnUpdater { |
| 882 |
|
| 883 |
/** |
| 884 |
* Set the column represented by parameters as visible |
| 885 |
* |
| 886 |
* @param columnObj |
| 887 |
* @param visible |
| 888 |
*/ |
| 889 |
public void setColumnVisible(Object columnObj, boolean visible); |
| 890 |
|
| 891 |
/** |
| 892 |
* Dummy method - more a result of symmetry |
| 893 |
* |
| 894 |
* @param columnObj |
| 895 |
* @param movable |
| 896 |
*/ |
| 897 |
public void setColumnMovable(Object columnObj, boolean movable); |
| 898 |
|
| 899 |
/** |
| 900 |
* Call back to notify change in the index of the column represented by |
| 901 |
* columnObj |
| 902 |
* |
| 903 |
* @param columnObj |
| 904 |
* @param index |
| 905 |
*/ |
| 906 |
public void setColumnIndex(Object columnObj, int index); |
| 907 |
|
| 908 |
/** |
| 909 |
* Dummy method - more a result of symmetry |
| 910 |
* |
| 911 |
* @param columnObj |
| 912 |
* @param resizable |
| 913 |
*/ |
| 914 |
public void setColumnResizable(Object columnObj, boolean resizable); |
| 915 |
|
| 916 |
/** |
| 917 |
* Call back to notify change in the width of the column represented by |
| 918 |
* columnObj |
| 919 |
* |
| 920 |
* @param columnObj |
| 921 |
* @param newWidth |
| 922 |
*/ |
| 923 |
public void setColumnWidth(Object columnObj, int newWidth); |
| 924 |
|
| 925 |
} |
| 926 |
|
| 927 |
//////////////////////////////////////////////////////////////////////////////////// |
| 928 |
/** |
| 929 |
* Ignore the class below as it is simply meant to test the above. I intend |
| 930 |
* to retain this for a while. |
| 931 |
*/ |
| 932 |
static class TestData { |
| 933 |
|
| 934 |
final Object key; |
| 935 |
|
| 936 |
final int keyIndex; |
| 937 |
|
| 938 |
int newIndex, width; |
| 939 |
|
| 940 |
boolean visibility, movable, resizable; |
| 941 |
|
| 942 |
TestData(Object key, int currIndex) { |
| 943 |
this.key = key; |
| 944 |
this.keyIndex = currIndex; |
| 945 |
} |
| 946 |
|
| 947 |
public int hashCode() { |
| 948 |
final int prime = 31; |
| 949 |
int result = 1; |
| 950 |
result = prime * result + ((key == null) ? 0 : key.hashCode()); |
| 951 |
result = prime * result + keyIndex; |
| 952 |
return result; |
| 953 |
} |
| 954 |
|
| 955 |
public boolean equals(Object obj) { |
| 956 |
if (this == obj) { |
| 957 |
return true; |
| 958 |
} |
| 959 |
if (obj == null) { |
| 960 |
return false; |
| 961 |
} |
| 962 |
if (!(obj instanceof TestData)) { |
| 963 |
return false; |
| 964 |
} |
| 965 |
TestData other = (TestData) obj; |
| 966 |
if (key == null) { |
| 967 |
if (other.key != null) { |
| 968 |
return false; |
| 969 |
} |
| 970 |
} else if (!key.equals(other.key)) { |
| 971 |
return false; |
| 972 |
} |
| 973 |
if (keyIndex != other.keyIndex) { |
| 974 |
return false; |
| 975 |
} |
| 976 |
return true; |
| 977 |
} |
| 978 |
|
| 979 |
public String toString() { |
| 980 |
return key.toString(); |
| 981 |
} |
| 982 |
|
| 983 |
private static ViewerColumnsDialog getColumnsDialog(Shell shell, |
| 984 |
final TestData[] colums) { |
| 985 |
ViewerColumnsDialog dialog = new ViewerColumnsDialog(shell) { |
| 986 |
|
| 987 |
protected IColumnInfoProvider getColumnInfoProvider() { |
| 988 |
return getInfoProvider(colums); |
| 989 |
} |
| 990 |
|
| 991 |
protected ITableLabelProvider getLabelProvider() { |
| 992 |
return new TableLabelProvider(); |
| 993 |
} |
| 994 |
|
| 995 |
protected IColumnUpdater getColumnUpdater() { |
| 996 |
return getUpdater(colums); |
| 997 |
} |
| 998 |
}; |
| 999 |
dialog.setColumnsObjs(colums); |
| 1000 |
return dialog; |
| 1001 |
} |
| 1002 |
|
| 1003 |
private static IColumnUpdater getUpdater(final TestData[] data) { |
| 1004 |
return new IColumnUpdater() { |
| 1005 |
|
| 1006 |
public void setColumnWidth(Object columnObj, int newWidth) { |
| 1007 |
((TestData) columnObj).width = newWidth; |
| 1008 |
} |
| 1009 |
|
| 1010 |
public void setColumnVisible(Object columnObj, boolean visible) { |
| 1011 |
((TestData) columnObj).visibility = visible; |
| 1012 |
} |
| 1013 |
|
| 1014 |
public void setColumnResizable(Object columnObj, |
| 1015 |
boolean resizable) { |
| 1016 |
|
| 1017 |
} |
| 1018 |
|
| 1019 |
public void setColumnMovable(Object columnObj, boolean movable) { |
| 1020 |
((TestData) columnObj).movable = movable; |
| 1021 |
|
| 1022 |
} |
| 1023 |
|
| 1024 |
public void setColumnIndex(Object columnObj, int index) { |
| 1025 |
((TestData) columnObj).newIndex = index; |
| 1026 |
} |
| 1027 |
}; |
| 1028 |
} |
| 1029 |
|
| 1030 |
private static IColumnInfoProvider getInfoProvider( |
| 1031 |
final TestData[] colData) { |
| 1032 |
return new IColumnInfoProvider() { |
| 1033 |
|
| 1034 |
public boolean isColumnVisible(Object columnObj) { |
| 1035 |
return ((TestData) columnObj).visibility; |
| 1036 |
} |
| 1037 |
|
| 1038 |
public boolean isColumnResizable(Object columnObj) { |
| 1039 |
return ((TestData) columnObj).resizable; |
| 1040 |
} |
| 1041 |
|
| 1042 |
public boolean isColumnMovable(Object columnObj) { |
| 1043 |
return ((TestData) columnObj).movable; |
| 1044 |
} |
| 1045 |
|
| 1046 |
public int getColumnWidth(Object columnObj) { |
| 1047 |
return ((TestData) columnObj).width; |
| 1048 |
} |
| 1049 |
|
| 1050 |
public int getColumnIndex(Object columnObj) { |
| 1051 |
return ((TestData) columnObj).newIndex; |
| 1052 |
} |
| 1053 |
}; |
| 1054 |
} |
| 1055 |
|
| 1056 |
private static TestData[] genData(int count) { |
| 1057 |
String[] cols = new String[count]; |
| 1058 |
for (int i = 0; i < cols.length; i++) { |
| 1059 |
cols[i] = new String("Column-" + (i + 1)); //$NON-NLS-1$ |
| 1060 |
} |
| 1061 |
Random random = new Random(); |
| 1062 |
|
| 1063 |
boolean[] visibility = new boolean[cols.length]; |
| 1064 |
Arrays.fill(visibility, true); |
| 1065 |
int ranInt = random.nextInt() % cols.length; |
| 1066 |
for (int i = 0; i < ranInt; i++) { |
| 1067 |
visibility[random.nextInt(ranInt)] = false; |
| 1068 |
} |
| 1069 |
|
| 1070 |
boolean[] resizable = new boolean[cols.length]; |
| 1071 |
Arrays.fill(resizable, true); |
| 1072 |
ranInt = random.nextInt() % cols.length; |
| 1073 |
for (int i = 0; i < ranInt; i++) { |
| 1074 |
resizable[random.nextInt(ranInt)] = false; |
| 1075 |
} |
| 1076 |
|
| 1077 |
boolean[] movable = new boolean[cols.length]; |
| 1078 |
Arrays.fill(movable, true); |
| 1079 |
ranInt = random.nextInt() % cols.length; |
| 1080 |
for (int i = 0; i < ranInt; i++) { |
| 1081 |
movable[random.nextInt(ranInt)] = false; |
| 1082 |
} |
| 1083 |
|
| 1084 |
int[] widths = new int[cols.length]; |
| 1085 |
Arrays.fill(widths, 100); |
| 1086 |
return TestData.generateColumnsData(cols, visibility, resizable, |
| 1087 |
movable, widths); |
| 1088 |
} |
| 1089 |
|
| 1090 |
public static TestData[] generateColumnsData(Object[] keys, |
| 1091 |
boolean[] visibility, boolean[] resizable, boolean[] movable, |
| 1092 |
int[] widths) { |
| 1093 |
TestData[] colData = new TestData[keys.length]; |
| 1094 |
int m = 0, n = 0; |
| 1095 |
for (int i = 0; i < colData.length; i++) { |
| 1096 |
TestData data = new TestData(keys[i], i); |
| 1097 |
data.visibility = visibility[i]; |
| 1098 |
data.resizable = resizable[i]; |
| 1099 |
data.movable = movable[i]; |
| 1100 |
data.width = widths[i]; |
| 1101 |
if (data.visibility) { |
| 1102 |
data.newIndex = m++; |
| 1103 |
} else { |
| 1104 |
data.newIndex = n++; |
| 1105 |
} |
| 1106 |
colData[i] = data; |
| 1107 |
} |
| 1108 |
return colData; |
| 1109 |
} |
| 1110 |
|
| 1111 |
/** |
| 1112 |
* Demo |
| 1113 |
* |
| 1114 |
* @param args |
| 1115 |
*/ |
| 1116 |
public static void main(String[] args) { |
| 1117 |
Display display = new Display(); |
| 1118 |
final Shell shell = new Shell(display); |
| 1119 |
shell.setLayout(new FillLayout()); |
| 1120 |
ViewerColumnsDialog dialog = getColumnsDialog(shell, genData(100)); |
| 1121 |
dialog.open(); |
| 1122 |
shell.dispose(); |
| 1123 |
while (!shell.isDisposed()) { |
| 1124 |
if (!display.readAndDispatch()) { |
| 1125 |
display.sleep(); |
| 1126 |
} |
| 1127 |
} |
| 1128 |
display.dispose(); |
| 1129 |
|
| 1130 |
} |
| 1131 |
|
| 1132 |
} |
| 1133 |
|
| 1134 |
//////////////////////////////////////////////////////////////////////////////////// |
| 1135 |
} |