comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java @ 606:69c0a6ecad57

#165 (part 1) Added tooltips and table headers in the project list. flys-client/trunk@2213 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 23 Jun 2011 09:29:46 +0000
parents 347cf4a5a486
children 3acc631efdf0
comparison
equal deleted inserted replaced
605:9e30c776cbef 606:69c0a6ecad57
10 import com.google.gwt.user.client.rpc.AsyncCallback; 10 import com.google.gwt.user.client.rpc.AsyncCallback;
11 11
12 import com.smartgwt.client.types.Alignment; 12 import com.smartgwt.client.types.Alignment;
13 import com.smartgwt.client.types.ListGridEditEvent; 13 import com.smartgwt.client.types.ListGridEditEvent;
14 import com.smartgwt.client.types.ListGridFieldType; 14 import com.smartgwt.client.types.ListGridFieldType;
15 import com.smartgwt.client.types.SelectionStyle;
16 import com.smartgwt.client.types.SortArrow;
15 import com.smartgwt.client.types.SortDirection; 17 import com.smartgwt.client.types.SortDirection;
18 import com.smartgwt.client.util.BooleanCallback;
16 import com.smartgwt.client.util.SC; 19 import com.smartgwt.client.util.SC;
17 import com.smartgwt.client.widgets.Canvas; 20 import com.smartgwt.client.widgets.Canvas;
18 import com.smartgwt.client.widgets.Label; 21 import com.smartgwt.client.widgets.Label;
19 import com.smartgwt.client.widgets.grid.CellFormatter; 22 import com.smartgwt.client.widgets.grid.CellFormatter;
23 import com.smartgwt.client.widgets.grid.HoverCustomizer;
20 import com.smartgwt.client.widgets.grid.ListGrid; 24 import com.smartgwt.client.widgets.grid.ListGrid;
21 import com.smartgwt.client.widgets.grid.ListGridField; 25 import com.smartgwt.client.widgets.grid.ListGridField;
22 import com.smartgwt.client.widgets.grid.ListGridRecord; 26 import com.smartgwt.client.widgets.grid.ListGridRecord;
23 import com.smartgwt.client.widgets.grid.events.CellClickEvent; 27 import com.smartgwt.client.widgets.grid.events.CellClickEvent;
24 import com.smartgwt.client.widgets.grid.events.CellClickHandler; 28 import com.smartgwt.client.widgets.grid.events.CellClickHandler;
67 public static final int UPDATE_INTERVAL = 30000; 71 public static final int UPDATE_INTERVAL = 30000;
68 72
69 /** Min Interval to refresh the user's projects.*/ 73 /** Min Interval to refresh the user's projects.*/
70 public static final int MIN_UPDATE_INTERVAL = 5000; 74 public static final int MIN_UPDATE_INTERVAL = 5000;
71 75
76 /** The initial width of this panel.*/
77 public static final int MIN_WIDTH = 300;
78
79 public static final String COLUMN_DATE_WIDTH = "100px";
80
81 public static final String COLUMN_TITLE_WIDTH = "*";
82
83 public static final String COLUMN_FAVORITE_WIDTH = "75px";
84
72 /** The interface that provides i18n messages. */ 85 /** The interface that provides i18n messages. */
73 private FLYSConstants messages = GWT.create(FLYSConstants.class); 86 private FLYSConstants messages = GWT.create(FLYSConstants.class);
74 87
75 /** The UserService used to retrieve information about the current user. */ 88 /** The UserService used to retrieve information about the current user. */
76 protected UserCollectionsServiceAsync userCollectionsService = 89 protected UserCollectionsServiceAsync userCollectionsService =
117 updateUserCollections(); 130 updateUserCollections();
118 } 131 }
119 132
120 133
121 protected void initGrid() { 134 protected void initGrid() {
135 grid.setWidth100();
136 grid.setHeight100();
137 grid.setAutoFitMaxWidth(500);
122 grid.setEmptyMessage(messages.no_projects()); 138 grid.setEmptyMessage(messages.no_projects());
123 grid.setLoadingDataMessage(messages.load_projects()); 139 grid.setLoadingDataMessage(messages.load_projects());
124 grid.setShowRecordComponents(true); 140 grid.setCanEdit(false);
125 grid.setShowRecordComponentsByCell(true); 141 grid.setEditEvent(ListGridEditEvent.NONE);
126 grid.setCanRemoveRecords(false); 142 grid.setShowHeaderContextMenu(false);
127 grid.setShowHeader(false); 143 grid.setShowSortArrow(SortArrow.NONE);
128 grid.setWidth100();
129 grid.setHeight100();
130 grid.setSortDirection(SortDirection.DESCENDING); 144 grid.setSortDirection(SortDirection.DESCENDING);
131 grid.setSortField(0); 145 grid.setSortField(0);
132 grid.setCanEdit(false); 146 grid.setSelectionType(SelectionStyle.SINGLE);
133 grid.setEditByCell(true);
134 grid.setEditEvent(ListGridEditEvent.NONE);
135 147
136 ListGridField date = buildDateField(); 148 ListGridField date = buildDateField();
137 ListGridField name = buildNameField(); 149 ListGridField name = buildNameField();
138 ListGridField fav = buildFavoriteField(); 150 ListGridField fav = buildFavoriteField();
139 151
227 }); 239 });
228 240
229 MenuItem del = new MenuItem(messages.delete_project()); 241 MenuItem del = new MenuItem(messages.delete_project());
230 del.addClickHandler(new ClickHandler() { 242 del.addClickHandler(new ClickHandler() {
231 public void onClick(MenuItemClickEvent evt) { 243 public void onClick(MenuItemClickEvent evt) {
232 deleteCollection(record.getCollection()); 244 SC.ask(messages.really_delete(), new BooleanCallback() {
245 public void execute(Boolean value) {
246 if (value) {
247 deleteCollection(record.getCollection());
248 }
249 }
250 });
233 } 251 }
234 }); 252 });
235 253
236 MenuItem rename = new MenuItem(messages.rename_project()); 254 MenuItem rename = new MenuItem(messages.rename_project());
237 rename.addClickHandler(new ClickHandler() { 255 rename.addClickHandler(new ClickHandler() {
251 269
252 /** 270 /**
253 * The init() method handles the layout stuff for this widget. 271 * The init() method handles the layout stuff for this widget.
254 */ 272 */
255 protected void init() { 273 protected void init() {
256 setWidth(300); 274 setWidth(MIN_WIDTH);
275 setMinWidth(MIN_WIDTH);
257 setHeight100(); 276 setHeight100();
258 setShowResizeBar(true); 277 setShowResizeBar(true);
259 setShowEdges(false); 278 setShowEdges(false);
260 setLayoutMargin(0); 279 setLayoutMargin(0);
261 setLayoutAlign(VerticalAlignment.TOP); 280 setLayoutAlign(VerticalAlignment.TOP);
301 320
302 Map newValues = event.getNewValues(); 321 Map newValues = event.getNewValues();
303 String name = (String) newValues.get("name"); 322 String name = (String) newValues.get("name");
304 323
305 c.setName(name); 324 c.setName(name);
306
307 updateCollectionName(c); 325 updateCollectionName(c);
308 } 326 }
309 327
310 328
311 /** 329 /**
468 * project. 486 * project.
469 * 487 *
470 * @return the grid field. 488 * @return the grid field.
471 */ 489 */
472 protected ListGridField buildDateField() { 490 protected ListGridField buildDateField() {
473 ListGridField date = new ListGridField("creationTime", "creationTime"); 491 ListGridField date = new ListGridField(
492 "creationTime", messages.projectlist_creationTime());
493
474 date.setType(ListGridFieldType.DATE); 494 date.setType(ListGridFieldType.DATE);
475 date.setCanEdit(false); 495 date.setCanEdit(false);
476 496
477 date.setCellFormatter(new CellFormatter() { 497 date.setCellFormatter(new CellFormatter() {
478 public String format(Object value, ListGridRecord rec, int r, int c) { 498 public String format(Object value, ListGridRecord rec, int r, int c) {
485 505
486 return dtf.format((Date)value); 506 return dtf.format((Date)value);
487 } 507 }
488 }); 508 });
489 509
490 date.setWidth(100); 510 date.setWidth(COLUMN_DATE_WIDTH);
491 date.setAlign(Alignment.LEFT); 511 date.setAlign(Alignment.CENTER);
492 512
493 return date; 513 return date;
494 } 514 }
495 515
496 516
498 * Builds the field in the grid that displays the name of a project. 518 * Builds the field in the grid that displays the name of a project.
499 * 519 *
500 * @return the grid field. 520 * @return the grid field.
501 */ 521 */
502 protected ListGridField buildNameField() { 522 protected ListGridField buildNameField() {
503 ListGridField name = new ListGridField("name", "name"); 523 ListGridField name = new ListGridField(
524 "name", messages.projectlist_title());
525
504 name.setType(ListGridFieldType.TEXT); 526 name.setType(ListGridFieldType.TEXT);
527 name.setShowHover(true);
528 name.setHoverCustomizer(new HoverCustomizer() {
529 public String hoverHTML(
530 Object value,
531 ListGridRecord record,
532 int row,
533 int col)
534 {
535 CollectionRecord r = (CollectionRecord) record;
536 Collection c = r.getCollection();
537
538 String name = c.getName();
539
540 return name != null && name.length() > 0
541 ? name
542 : c.identifier();
543 }
544 });
505 545
506 name.setCellFormatter(new CellFormatter() { 546 name.setCellFormatter(new CellFormatter() {
507 public String format(Object value, ListGridRecord record, int row, int col) { 547 public String format(Object value, ListGridRecord record, int row, int col) {
508 String n = (String) value; 548 String n = (String) value;
509 int len = n.length(); 549 int len = n.length();
515 int sec = len - 13; 555 int sec = len - 13;
516 return n.substring(0, 12) + "..." + n.substring(sec, len-1); 556 return n.substring(0, 12) + "..." + n.substring(sec, len-1);
517 } 557 }
518 }); 558 });
519 559
520 name.setWidth(165); 560 name.setWidth(COLUMN_TITLE_WIDTH);
521 name.setAlign(Alignment.LEFT); 561 name.setAlign(Alignment.LEFT);
522 562
523 return name; 563 return name;
524 } 564 }
525 565
526 566
527 protected ListGridField buildFavoriteField() { 567 protected ListGridField buildFavoriteField() {
528 ListGridField fav = new ListGridField("ttl", "ttl"); 568 ListGridField fav = new ListGridField(
569 "ttl", messages.projectlist_favorite());
570
529 fav.setType(ListGridFieldType.IMAGE); 571 fav.setType(ListGridFieldType.IMAGE);
530 String base = GWT.getHostPageBaseURL(); 572 String base = GWT.getHostPageBaseURL();
531 fav.setImageURLPrefix(base + "images/"); 573 fav.setImageURLPrefix(base + "images/");
532 fav.setImageURLSuffix(".png"); 574 fav.setImageURLSuffix(".png");
533 fav.setWidth(30); 575 fav.setWidth(COLUMN_FAVORITE_WIDTH);
534 fav.setAlign(Alignment.RIGHT); 576 fav.setAlign(Alignment.CENTER);
535 fav.setCanEdit(false); 577 fav.setCanEdit(false);
536 578
537 return fav; 579 return fav;
538 } 580 }
539 } 581 }

http://dive4elements.wald.intevation.org