Changeset 2674
- Timestamp:
- 03/08/10 13:28:03 (2 years ago)
- Location:
- molgenis/3.3/src/org/molgenis
- Files:
-
- 28 edited
-
framework/ui/FormController.java (modified) (18 diffs)
-
framework/ui/FormModel.java (modified) (22 diffs)
-
framework/ui/MenuModel.java (modified) (7 diffs)
-
framework/ui/ScreenMessage.java (modified) (5 diffs)
-
framework/ui/ScreenModel.java (modified) (1 diff)
-
framework/ui/SimpleModel.java (modified) (4 diffs)
-
framework/ui/UserInterface.ftl (modified) (1 diff)
-
framework/ui/UserInterface.java (modified) (3 diffs)
-
framework/ui/commands/AddBatchCommand.java (modified) (6 diffs)
-
framework/ui/commands/AddCommand.java (modified) (2 diffs)
-
framework/ui/commands/AddCommand2.java (modified) (3 diffs)
-
framework/ui/commands/ChangeListLimitCommand.java (modified) (1 diff)
-
framework/ui/commands/CommandMenu.java (modified) (3 diffs)
-
framework/ui/commands/DownloadAllCommand.java (modified) (3 diffs)
-
framework/ui/commands/DownloadSelectedCommand.java (modified) (5 diffs)
-
framework/ui/commands/DownloadVisibleCommand.java (modified) (3 diffs)
-
framework/ui/commands/EditSelectedCommand.java (modified) (7 diffs)
-
framework/ui/commands/PluginCommand.java (modified) (1 diff)
-
framework/ui/commands/RemoveSelectedCommand.java (modified) (3 diffs)
-
framework/ui/commands/ScreenCommand.java (modified) (12 diffs)
-
framework/ui/commands/SimpleCommand.java (modified) (13 diffs)
-
framework/ui/commands/ViewEditViewCommand.java (modified) (2 diffs)
-
framework/ui/commands/ViewListViewCommand.java (modified) (1 diff)
-
framework/ui/html/HtmlForm.java (modified) (4 diffs)
-
framework/ui/html/MrefInput.java (modified) (8 diffs)
-
framework/ui/html/XrefInput.java (modified) (8 diffs)
-
generators/ui/FormScreenGen.java.ftl (modified) (7 diffs)
-
generators/ui/PluginScreenGen.java.ftl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molgenis/3.3/src/org/molgenis/framework/ui/FormController.java
r2442 r2674 55 55 * @param view 56 56 */ 57 public FormController(FormModel <E>view)57 public FormController(FormModel view) 58 58 { 59 59 super(view); … … 62 62 try 63 63 { 64 this.pager = new LimitOffsetPager <E>(view.getEntityClass(), view.create().getFields()64 this.pager = new LimitOffsetPager(view.getEntityClass(), view.create().getFields() 65 65 .firstElement()); 66 66 // this.pager = new PrimaryKeyPager<E>(view.getEntityClass(), … … 93 93 94 94 // clear the old messages 95 view.setMessages(new Vector<ScreenMessage <E>>()); // clear messsages95 view.setMessages(new Vector<ScreenMessage>()); // clear messsages 96 96 97 97 try … … 399 399 400 400 // load all records and select rows that can be visible 401 // List <E>allRecords = view.getDatabase().find( view.getEntityClass(),401 // List allRecords = view.getDatabase().find( view.getEntityClass(), 402 402 // allRules ); 403 403 List<E> allRecords = pager.getPage(db); … … 427 427 public boolean doAdd(Database db, Tuple request) throws ParseException, DatabaseException, IOException 428 428 { 429 ScreenMessage <E>msg = null;430 E entity = view.create();429 ScreenMessage msg = null; 430 Entity entity = view.create(); 431 431 boolean result = false; 432 432 … … 451 451 } 452 452 db.commitTx(); 453 msg = new ScreenMessage <E>("ADD SUCCESS: affected " + updatedRows, null, true);453 msg = new ScreenMessage("ADD SUCCESS: affected " + updatedRows, null, true); 454 454 result = true; 455 455 // navigate to newly added record … … 460 460 { 461 461 db.rollbackTx(); 462 msg = new ScreenMessage <E>("ADD FAILED: " + e.getMessage(), null, false);462 msg = new ScreenMessage("ADD FAILED: " + e.getMessage(), null, false); 463 463 result = false; 464 464 } … … 478 478 protected void doUpdate(Database db, Tuple request) throws DatabaseException, IOException, ParseException 479 479 { 480 E entity = view.create();481 ScreenMessage <E>msg = null;480 Entity entity = view.create(); 481 ScreenMessage msg = null; 482 482 try 483 483 { 484 484 entity.set(request); 485 485 int updatedRows = db.update(entity); 486 msg = new ScreenMessage <E>("UPDATE SUCCESS: affected " + updatedRows, null, true);486 msg = new ScreenMessage("UPDATE SUCCESS: affected " + updatedRows, null, true); 487 487 } 488 488 catch (Exception e) 489 489 { 490 490 logger.error("doUpdate(): " + e); 491 msg = new ScreenMessage <E>("UPDATE FAILED: " + e.getMessage(), null, false);491 msg = new ScreenMessage("UPDATE FAILED: " + e.getMessage(), null, false); 492 492 } 493 493 view.getMessages().add(msg); … … 502 502 protected void doRemove(Database db, Tuple request) throws DatabaseException, ParseException, IOException 503 503 { 504 E entity = view.create();505 ScreenMessage <E>msg = null;504 Entity entity = view.create(); 505 ScreenMessage msg = null; 506 506 try 507 507 { 508 508 entity.set(request); 509 509 int updatedRows = db.remove(entity); 510 if (updatedRows > 0) msg = new ScreenMessage <E>("REMOVE SUCCESS: affected " + updatedRows, null, true);510 if (updatedRows > 0) msg = new ScreenMessage("REMOVE SUCCESS: affected " + updatedRows, null, true); 511 511 else 512 msg = new ScreenMessage <E>("REMOVE FAILED: call system administrator", null, false);512 msg = new ScreenMessage("REMOVE FAILED: call system administrator", null, false); 513 513 } 514 514 catch (Exception e) 515 515 { 516 msg = new ScreenMessage <E>("REMOVE FAILED: " + e.getMessage(), null, false);516 msg = new ScreenMessage("REMOVE FAILED: " + e.getMessage(), null, false); 517 517 } 518 518 view.getMessages().add(msg); … … 572 572 // { 573 573 // Database db = view.getDatabase(); 574 // ScreenMessage <E>msg = null;574 // ScreenMessage msg = null; 575 575 // try 576 576 // { … … 588 588 // view.getDatabase().query(view.getEntityClass()).in(view.create() 589 589 // .getIdField(), idList); 590 // List <E>selection = q.find();590 // List selection = q.find(); 591 591 // 592 592 // // delete selected entities 593 593 // db.remove(selection); 594 // msg = new ScreenMessage <E>("REMOVED " + selection.size() + " records",594 // msg = new ScreenMessage("REMOVED " + selection.size() + " records", 595 595 // null, true); 596 596 // } 597 597 // catch (Exception e) 598 598 // { 599 // msg = new ScreenMessage <E>("REMOVE SELECTION FAILED: " + e.getMessage(),599 // msg = new ScreenMessage("REMOVE SELECTION FAILED: " + e.getMessage(), 600 600 // null, false); 601 601 // } … … 618 618 // } 619 619 // 620 // ScreenMessage <E>msg = null;620 // ScreenMessage msg = null; 621 621 // Database db = view.getDatabase(); 622 622 // int row = 0; … … 625 625 // Query q = db.query(view.getEntityClass()).in(view.create().getIdField(), 626 626 // idList); 627 // List <E>entities = q.find();627 // List entities = q.find(); 628 628 // 629 629 // db.beginTx(); … … 635 635 // } 636 636 // db.commitTx(); 637 // msg = new ScreenMessage <E>("MASS UPDATE SUCCESS: updated " +637 // msg = new ScreenMessage("MASS UPDATE SUCCESS: updated " + 638 638 // entities.size() + " rows", null, true); 639 639 // } … … 650 650 // e1.printStackTrace(); 651 651 // } 652 // msg = new ScreenMessage <E>("MASS UPDATE FAILED on item '" + row + "': " +652 // msg = new ScreenMessage("MASS UPDATE FAILED on item '" + row + "': " + 653 653 // e, null, false); 654 654 // } … … 660 660 // { 661 661 // logger.debug("doCsvUpload: " + request); 662 // ScreenMessage <E>msg = null;662 // ScreenMessage msg = null; 663 663 // try 664 664 // { 665 // CsvEntityReader <E>csvReader = this.view.getCsvReader();665 // CsvEntityReader csvReader = this.view.getCsvReader(); 666 666 // 667 667 // int updatedRows = csvReader.importCsv(view.getDatabase(), new … … 670 670 // // logger.debug("parsed: " + entity); 671 671 // //view.getDatabase().add(entities); 672 // msg = new ScreenMessage <E>("CSV UPLOAD SUCCESS: added " + updatedRows +672 // msg = new ScreenMessage("CSV UPLOAD SUCCESS: added " + updatedRows + 673 673 // " rows", null, true); 674 674 // logger.debug("CSV UPLOAD SUCCESS: added " + updatedRows + " rows"); … … 679 679 // { 680 680 // e.printStackTrace(); 681 // msg = new ScreenMessage <E>("CSV UPLOAD FAILED: " + e.getMessage(), null,681 // msg = new ScreenMessage("CSV UPLOAD FAILED: " + e.getMessage(), null, 682 682 // false); 683 683 // logger.error("CSV UPLOAD FAILED: " + e.getMessage()); -
molgenis/3.3/src/org/molgenis/framework/ui/FormModel.java
r2594 r2674 18 18 import java.util.ArrayList; 19 19 import java.util.Arrays; 20 import java.util.LinkedHashMap; 20 21 import java.util.List; 21 22 import java.util.Map; … … 41 42 import org.molgenis.framework.ui.commands.RemoveSelectedCommand; 42 43 import org.molgenis.framework.ui.commands.ScreenCommand; 43 import org.molgenis.framework.ui.commands.SimpleCommand;44 44 import org.molgenis.framework.ui.commands.ViewEditViewCommand; 45 45 import org.molgenis.framework.ui.commands.ViewListViewCommand; … … 53 53 * 54 54 * 55 * @param <E>55 * @param 56 56 */ 57 57 public abstract class FormModel<E extends Entity> extends SimpleModel … … 68 68 private String parentForm; 69 69 private String parentId; 70 private String parentLabel;70 private List<String> parentLabels; 71 71 private String xrefToParent; 72 72 73 public ParentFilter(String parentForm, String parentId, StringparentLabel, String xrefToParent)73 public ParentFilter(String parentForm, String parentId, List<String> parentLabel, String xrefToParent) 74 74 { 75 75 this.parentForm = parentForm; 76 76 this.parentId = parentId; 77 this.parentLabel = parentLabel;77 this.parentLabels = parentLabel; 78 78 this.xrefToParent = xrefToParent; 79 79 } … … 109 109 } 110 110 111 public String getParentLabel()112 { 113 return parentLabel ;114 } 115 116 public void setParentLabel (StringparentLabel)117 { 118 this.parentLabel = parentLabel;111 public List<String> getParentLabels() 112 { 113 return parentLabels; 114 } 115 116 public void setParentLabels(List<String> parentLabel) 117 { 118 this.parentLabels = parentLabel; 119 119 } 120 120 } … … 129 129 * @throws ParseException 130 130 */ 131 public abstract HtmlForm<E> getInputs(E entity, boolean newrecord); 132 131 public abstract HtmlForm getInputs(E entity, boolean newrecord); 132 133 public List<HtmlInput> getInputs() 134 { 135 return getInputs((E)create(),true).getInputs(); 136 } 137 138 public List<HtmlInput> getInputs(E entity) 139 { 140 return getInputs(entity,false).getInputs(); 141 } 142 133 143 /** 134 144 * Provides the class of the entitites managed by this form. Note: Java … … 185 195 186 196 /** List of actions of this screen */ 187 private List<ScreenCommand<E>> actions = new ArrayList<ScreenCommand<E>>();197 private Map<String,ScreenCommand> commands = new LinkedHashMap<String, ScreenCommand>(); 188 198 189 199 /** entity csv reader */ 190 private CsvToDatabase <E>csvReader;200 private CsvToDatabase csvReader; 191 201 192 202 /** currently known offset */ … … 209 219 210 220 /** cache of currently viewable records */ 211 private List <E> records = new ArrayList<E>();221 private List records = new ArrayList(); 212 222 213 223 /** whether this form can be edited */ … … 221 231 222 232 /** messages to show to the user */ 223 private Vector<ScreenMessage <E>> messages;233 private Vector<ScreenMessage> messages; 224 234 225 235 /** Active command (in case of a command with dialog) */ 226 private ScreenCommand <E>currentCommand = null;236 private ScreenCommand currentCommand = null; 227 237 228 238 /** columns that are invisible to the user */ … … 231 241 232 242 /** Helper object that takes care of database paging */ 233 private DatabasePager <E>pager;243 private DatabasePager pager; 234 244 235 245 /** Here the currently selected is are stored */ … … 269 279 270 280 setMode(Mode.LIST_VIEW); 271 setMessages(new Vector<ScreenMessage <E>>());281 setMessages(new Vector<ScreenMessage>()); 272 282 setReadonly(false); 273 283 resetSystemHiddenColumns(); 274 284 resetUserHiddenColumns(); 275 285 276 setController(new FormController <E>(this));286 setController(new FormController(this)); 277 287 278 288 // add all actions … … 280 290 281 291 // File:Download visible 282 ScreenCommand<E> f1 = new DownloadVisibleCommand("download_visible", this); 283 super.addCommand("File", f1); 292 super.addCommand(new DownloadVisibleCommand("download_visible", this)); 284 293 285 294 // File:Download Selected 286 SimpleCommand<E> f2 = new DownloadSelectedCommand<E>("download_selected", this); 287 super.addCommand("File", f2); 295 super.addCommand(new DownloadSelectedCommand("download_selected", this)); 288 296 289 297 // FILE:Download all 290 SimpleCommand<E> f3 = new DownloadAllCommand<E>("download_all", this); 291 super.addCommand("File", f3); 298 super.addCommand(new DownloadAllCommand("download_all", this)); 292 299 293 300 // File: Add batch 294 SimpleCommand<E> f4 = new AddBatchCommand<E>("upload_csv", this); 295 super.addCommand("File", f4); 301 super.addCommand(new AddBatchCommand("upload_csv", this)); 296 302 297 303 // EDIT MENU 298 304 // EDIT: Add new record 299 SimpleCommand<E> e1 = new AddCommand<E>("edit_new", this); 300 e1.setToolbar(true); 301 super.addCommand("Edit", e1); 305 super.addCommand(new AddCommand("edit_new", this)); 302 306 303 307 // EDIT: Update selected 304 SimpleCommand<E> e2 = new EditSelectedCommand<E>("edit_update_selected", this); 305 super.addCommand("Edit", e2); 306 307 SimpleCommand<E> e3 = new RemoveSelectedCommand<E>("edit_remove_selected", this); 308 super.addCommand("Edit", e3); 308 super.addCommand(new EditSelectedCommand("edit_update_selected", this)); 309 310 // EDIT: Remove selected 311 super.addCommand(new RemoveSelectedCommand("edit_remove_selected", this)); 309 312 310 313 // menu VIEW 311 // S impleCommand<E> v2 = new ViewRecordViewCommand<E>("recordview",314 // ScreenCommand v2 = new ViewRecordViewCommand("recordview", 312 315 // this); 313 316 // v2.setToolbar(true); 314 317 // super.addCommand("View", v2); 315 318 316 SimpleCommand<E> v3 = new ViewEditViewCommand<E>("editview", this);317 319 // v3.setToolbar(true); 318 super.addCommand("View", v3); 319 320 SimpleCommand<E> v4 = new ViewListViewCommand<E>("listview", this); 321 v4.setToolbar(true); 322 super.addCommand("View", v4); 323 324 ChangeListLimitCommand<E> view_5 = new ChangeListLimitCommand<E>("view_5show5", this); 320 super.addCommand(new ViewEditViewCommand("editview", this)); 321 super.addCommand(new ViewListViewCommand("listview", this)); 322 323 ChangeListLimitCommand view_5 = new ChangeListLimitCommand("view_5show5", this); 325 324 view_5.setLimit(5); 326 super.addCommand( "View",view_5);327 328 ChangeListLimitCommand <E> view_10 = new ChangeListLimitCommand<E>("view_6show10", this);325 super.addCommand(view_5); 326 327 ChangeListLimitCommand view_10 = new ChangeListLimitCommand("view_6show10", this); 329 328 view_5.setLimit(10); 330 super.addCommand( "View",view_10);331 332 ChangeListLimitCommand <E> view_20 = new ChangeListLimitCommand<E>("view_7show20", this);329 super.addCommand(view_10); 330 331 ChangeListLimitCommand view_20 = new ChangeListLimitCommand("view_7show20", this); 333 332 view_20.setLimit(20); 334 super.addCommand( "View",view_20);335 336 ChangeListLimitCommand <E> view_50 = new ChangeListLimitCommand<E>("view_8show50", this);333 super.addCommand(view_20); 334 335 ChangeListLimitCommand view_50 = new ChangeListLimitCommand("view_8show50", this); 337 336 view_50.setLimit(50); 338 super.addCommand( "View",view_50);339 340 ChangeListLimitCommand <E> view_100 = new ChangeListLimitCommand<E>("view_9show100", this);337 super.addCommand(view_50); 338 339 ChangeListLimitCommand view_100 = new ChangeListLimitCommand("view_9show100", this); 341 340 view_100.setLimit(100); 342 super.addCommand( "View",view_100);343 344 ChangeListLimitCommand <E> view_500 = new ChangeListLimitCommand<E>("view_10show500", this);341 super.addCommand(view_100); 342 343 ChangeListLimitCommand view_500 = new ChangeListLimitCommand("view_10show500", this); 345 344 view_500.setLimit(500); 346 super.addCommand( "View",view_500);345 super.addCommand(view_500); 347 346 348 347 // add the plugged-in actions 349 for (ScreenCommand <E> command : this.actions)350 { 351 super.addCommand(command .getMenu(), command);348 for (ScreenCommand command : this.commands.values()) 349 { 350 super.addCommand(command); 352 351 } 353 352 } 354 353 355 354 @Override 356 public boolean isVisible() 357 { 358 return this.getSecurity().canRead(this.create().getClass()); 355 public boolean isVisible() 356 { 357 try 358 { 359 return this.getSecurity().canRead(this.create().getClass()); 360 } 361 catch (DatabaseException e) 362 { 363 // TODO Auto-generated catch block 364 e.printStackTrace(); 365 } 366 return false; 359 367 } 360 368 … … 368 376 Vector<ScreenCommand> toolbar = new Vector<ScreenCommand>(); 369 377 370 for (CommandMenu <E>menu : this.getMenus())371 { 372 for (ScreenCommand <E>c : menu.getCommands())378 for (CommandMenu menu : this.getMenus()) 379 { 380 for (ScreenCommand c : menu.getCommands()) 373 381 { 374 382 if (c.isToolbar() && c.isVisible()) … … 442 450 // xref only 443 451 Object value = records.get(0).get(pf.getParentId()); 444 Object label = records.get(0).get(pf.getParentLabel());445 452 if (!(value instanceof List) && value != null) 446 453 { 447 454 entity.set(pf.getXrefToParent(), value); 448 entity.set(pf.getXrefToParent()+"_"+pf.getParentLabel(), label); 455 } 456 457 for(String labelName: pf.getParentLabels()) 458 { 459 Object label = records.get(0).get(labelName); 460 entity.set(pf.getXrefToParent()+"_"+labelName, label); 449 461 } 450 462 } … … 482 494 * @throws DatabaseException 483 495 */ 484 public HtmlForm <E>getNewRecordForm() throws DatabaseException496 public HtmlForm getNewRecordForm() throws DatabaseException 485 497 { 486 498 E entity = this.create(); … … 495 507 * row on screen. 496 508 */ 497 public Vector<HtmlForm <E>> getRecordInputs()498 { 499 Vector<HtmlForm <E>> records = new Vector<HtmlForm<E>>();509 public Vector<HtmlForm> getRecordInputs() 510 { 511 Vector<HtmlForm> records = new Vector<HtmlForm>(); 500 512 501 513 try … … 503 515 for (E entity : getRecords()) 504 516 { 505 HtmlForm <E>record = getInputs(entity, false);517 HtmlForm record = getInputs(entity, false); 506 518 record.setReadonly(!getSecurity().canWrite(entity)); 507 519 records.add(record); … … 663 675 * @param recordlist 664 676 */ 665 public void setRecords(List <E>recordlist)677 public void setRecords(List recordlist) 666 678 { 667 679 this.records = recordlist; … … 786 798 * @param messages 787 799 */ 788 public void setMessages(Vector<ScreenMessage <E>> messages)800 public void setMessages(Vector<ScreenMessage> messages) 789 801 { 790 802 this.messages = messages; 791 803 } 792 804 793 public void setMessages(ScreenMessage <E>... messages)794 { 795 this.messages = new Vector<ScreenMessage <E>>(Arrays.asList(messages));805 public void setMessages(ScreenMessage... messages) 806 { 807 this.messages = new Vector<ScreenMessage>(Arrays.asList(messages)); 796 808 } 797 809 … … 799 811 * @return Messages to inform the user of state changes and succes. 800 812 */ 801 public Vector<ScreenMessage <E>> getMessages()813 public Vector<ScreenMessage> getMessages() 802 814 { 803 815 return this.messages; … … 873 885 } 874 886 875 public CsvToDatabase <E>getCsvReader()887 public CsvToDatabase getCsvReader() 876 888 { 877 889 return csvReader; 878 890 } 879 891 880 public void setCsvReader(CsvToDatabase <E>csvReader)892 public void setCsvReader(CsvToDatabase csvReader) 881 893 { 882 894 this.csvReader = csvReader; … … 888 900 } 889 901 890 public List<ScreenCommand<E>> getActions() 891 { 892 return actions; 893 } 894 895 public void addAction(ScreenCommand<E> action) 896 { 897 this.actions.add(action); 898 } 899 900 public ScreenCommand<E> getCurrentCommand() 902 public List<ScreenCommand> getCommands() 903 { 904 return new ArrayList<ScreenCommand>(commands.values()); 905 } 906 907 public ScreenCommand getCurrentCommand() 901 908 { 902 909 return currentCommand; 903 910 } 904 911 905 public void setCurrentCommand(ScreenCommand <E>currentCommand)912 public void setCurrentCommand(ScreenCommand currentCommand) 906 913 { 907 914 this.currentCommand = currentCommand; -
molgenis/3.3/src/org/molgenis/framework/ui/MenuModel.java
r2442 r2674 17 17 import java.util.List; 18 18 19 20 21 19 /** 22 20 * This class describes the functionality needed for a menu-screen. The … … 31 29 public enum Position 32 30 { 33 /* put on top of subform, float to right */31 /* put on top of subform, float to right */ 34 32 TOP_RIGHT, 35 33 /* put on top of subform, float to left */ … … 59 57 super(name, parent); 60 58 setController(new MenuController(this)); 61 // macro has exact name as class, but then ending with 'view'.59 // macro has exact name as class, but then ending with 'view'. 62 60 setViewMacro(MenuModel.class.getSimpleName().replace("Model", "View")); 63 61 } … … 71 69 public void hide(String name) 72 70 { 73 if (this.get(name) != null) hiddenScreenNames.add(name); 71 if (this.get(name) != null) 72 hiddenScreenNames.add(name); 74 73 75 74 } … … 110 109 { 111 110 List<ScreenModel> subscreens = getVisibleChildren(); 112 if (subscreens.contains(super.getSelected()))111 if (subscreens.contains(super.getSelected())) 113 112 { 114 113 return super.getSelected(); 115 114 } 116 else if (subscreens.size() > 0)115 else if (subscreens.size() > 0) 117 116 { 118 117 return subscreens.get(0); … … 128 127 { 129 128 // the menu is visible if one its children is visible. 130 if (this.getVisibleChildren().size() > 0) return true; 129 if (this.getVisibleChildren().size() > 0) 130 return true; 131 131 return false; 132 132 } … … 141 141 this.position = position; 142 142 } 143 144 public String getCustomHtmlHeaders() 145 { 146 if (this.getSelected() != null) 147 { 148 return this.getSelected().getCustomHtmlHeaders(); 149 } 150 return ""; 151 } 143 152 } -
molgenis/3.3/src/org/molgenis/framework/ui/ScreenMessage.java
r2308 r2674 10 10 package org.molgenis.framework.ui; 11 11 12 import org.molgenis.util.Entity; 13 12 14 // imports 13 15 … … 20 22 * @version 1.0.0 21 23 */ 22 public class ScreenMessage <E>24 public class ScreenMessage 23 25 { 24 26 // constructor … … 31 33 * @param success Indicates whether the transaction was succesfull. 32 34 */ 33 public ScreenMessage(String message, E entity, boolean success)35 public ScreenMessage(String message, Entity entity, boolean success) 34 36 { 35 37 this.entity = entity; … … 65 67 * @return The entity. 66 68 */ 67 public E getEntity()69 public Entity getEntity() 68 70 { 69 71 return entity; … … 106 108 107 109 /** The entity that was used in the database and generated this message */ 108 private E entity;110 private Entity entity; 109 111 110 112 /** Whether the operation on the database was succesfull */ -
molgenis/3.3/src/org/molgenis/framework/ui/ScreenModel.java
r2442 r2674 58 58 SHOW_MAIN("inline"), 59 59 /** 60 * Show the current screen or command as popup. This means the layout template is applied on this element .60 * Show the current screen or command as popup. This means the layout template is applied on this element only. 61 61 */ 62 62 SHOW_DIALOG("popup"), 63 63 /** 64 * Pass current screen in handlerequest the outputstreamso it can be64 * Don't layout the screen. Instead pass use the outputstream in handleRequest so it can be 65 65 * downloaded. This result in a download file. 66 66 */ -
molgenis/3.3/src/org/molgenis/framework/ui/SimpleModel.java
r2629 r2674 190 190 191 191 /** COMMANDS for on the menu bar. Idea: move to screen? * */ 192 public void addCommand(String menu_name, ScreenCommandcommand)192 public <E extends ScreenCommand>void addCommand(E command) 193 193 { 194 194 // link the command to the screen … … 199 199 if (getCommand(command.getName()) != null) 200 200 { 201 throw new RuntimeException("addCommand failed:command with name '" + command.getName()202 + "' already exists ");201 logger.warn("command with name '" + command.getName() 202 + "' already exists; replaced"); 203 203 } 204 204 205 205 // create new menu if not exists 206 if (menubar.containsKey( menu_name) == false)207 { 208 menubar.put( menu_name, new CommandMenu(menu_name, (FormModel) this, menu_name, "", ""));206 if (menubar.containsKey(command.getMenu()) == false) 207 { 208 menubar.put(command.getMenu(), new CommandMenu(command.getMenu(), (FormModel) this, command.getMenu(), "", "")); 209 209 } 210 210 211 211 // put the command in the menu 212 menubar.get( menu_name).addCommand(command);212 menubar.get(command.getMenu()).addCommand(command); 213 213 this.logger.debug("added action " + command.getName()); 214 214 } … … 237 237 public String getCustomHtmlHeaders() 238 238 { 239 if (this.getSelected() != null)240 {241 return this.getSelected().getCustomHtmlHeaders();242 }243 else244 {239 // if (this.getSelected() != null) 240 // { 241 // return this.getSelected().getCustomHtmlHeaders(); 242 // } 243 // else 244 // { 245 245 String result = ""; 246 246 for(ScreenModel m: this.getChildren()) … … 249 249 } 250 250 return result; 251 }251 // } 252 252 253 253 } -
molgenis/3.3/src/org/molgenis/framework/ui/UserInterface.ftl
r2442 r2674 31 31 <div id="container"> 32 32 33 <#list screen. getVisibleChildren()as subscreen>33 <#list screen.children as subscreen> 34 34 <@layout subscreen /> 35 35 </#list> -
molgenis/3.3/src/org/molgenis/framework/ui/UserInterface.java
r2442 r2674 19 19 * of authentication/authorization). 20 20 */ 21 public class UserInterface extends MenuModel implements ScreenController21 public class UserInterface extends SimpleModel implements ScreenController 22 22 { 23 23 public static String MOLGENIS_TEMP_PATH = "molgenis_temp"; … … 181 181 } 182 182 183 /**184 * This enables plugin developers to add their custom css or javascript (or185 * whatever) headers.186 *187 * @return valid header html such as css or javascript references188 */189 public String getCustomHtmlHeaders() {190 return this.getSelected().getCustomHtmlHeaders();191 }192 193 183 public String getVersion() 194 184 { … … 210 200 this.emailService = emailService; 211 201 } 202 203 @Override 204 public boolean isVisible() 205 { 206 // TODO Auto-generated method stub 207 return true; 208 } 212 209 } -
molgenis/3.3/src/org/molgenis/framework/ui/commands/AddBatchCommand.java
r2442 r2674 14 14 import org.molgenis.framework.ui.ScreenMessage; 15 15 import org.molgenis.framework.ui.ScreenModel; 16 import org.molgenis.framework.ui.ScreenModel.Show;17 16 import org.molgenis.framework.ui.html.ActionInput; 18 17 import org.molgenis.framework.ui.html.HtmlInput; … … 25 24 * The command to add in batch/upload csv 26 25 */ 27 public class AddBatchCommand <E extends Entity> extends SimpleCommand<E>26 public class AddBatchCommand extends SimpleCommand 28 27 { 29 28 30 public AddBatchCommand(String name, FormModel <E>owner)29 public AddBatchCommand(String name, FormModel owner) 31 30 { 32 31 super(name, owner); … … 34 33 this.setIcon("generated-res/img/upload.png"); 35 34 this.setDialog(true); 35 this.setMenu("File"); 36 36 } 37 37 … … 80 80 if (request.getString(FormModel.INPUT_SHOW) == null) 81 81 { 82 ScreenMessage <E>msg = null;82 ScreenMessage msg = null; 83 83 try 84 84 { 85 CsvToDatabase <E>csvReader = this.getFormScreen().getCsvReader();85 CsvToDatabase csvReader = this.getFormScreen().getCsvReader(); 86 86 87 87 int updatedRows = csvReader.importCsv(db, new CsvStringReader(request … … 90 90 // logger.debug("parsed: " + entity); 91 91 // view.getDatabase().add(entities); 92 msg = new ScreenMessage <E>("CSV UPLOAD SUCCESS: added " + updatedRows + " rows", null, true);92 msg = new ScreenMessage("CSV UPLOAD SUCCESS: added " + updatedRows + " rows", null, true); 93 93 logger.debug("CSV UPLOAD SUCCESS: added " + updatedRows + " rows"); 94 94 getFormScreen().getPager().resetFilters(); … … 98 98 { 99 99 e.printStackTrace(); 100 msg = new ScreenMessage <E>("CSV UPLOAD FAILED: " + e.getMessage(), null, false);100 msg = new ScreenMessage("CSV UPLOAD FAILED: " + e.getMessage(), null, false); 101 101 logger.error("CSV UPLOAD FAILED: " + e.getMessage()); 102 102 } -
molgenis/3.3/src/org/molgenis/framework/ui/commands/AddCommand.java
r2442 r2674 20 20 * The command to add a new record 21 21 */ 22 public class AddCommand <E extends Entity> extends SimpleCommand<E>22 public class AddCommand extends SimpleCommand 23 23 { 24 public AddCommand(String name, FormModel <E>parent)24 public AddCommand(String name, FormModel parent) 25 25 { 26 26 super(name, parent); … … 28 28 this.setIcon("generated-res/img/new.png"); 29 29 this.setDialog(true); 30 30 this.setMenu("Edit"); 31 this.setToolbar(true); 31 32 } 32 33 -
molgenis/3.3/src/org/molgenis/framework/ui/commands/AddCommand2.java
r2442 r2674 25 25 * screen again. 26 26 */ 27 public class AddCommand2<E extends Entity> extends SimpleCommand <E>27 public class AddCommand2<E extends Entity> extends SimpleCommand 28 28 { 29 29 Tuple previousRequest = new SimpleTuple(); 30 Vector<ScreenMessage <E>> messages = new Vector<ScreenMessage<E>>();30 Vector<ScreenMessage> messages = new Vector<ScreenMessage>(); 31 31 boolean success = false; 32 32 33 public AddCommand2(String name, FormModel <E>parent)33 public AddCommand2(String name, FormModel parent) 34 34 { 35 35 super(name, parent); … … 81 81 { 82 82 // delegate to the form controller 83 boolean success = ((FormController <E>) this.getScreen().getController()).doAdd(db, request);83 boolean success = ((FormController) this.getScreen().getController()).doAdd(db, request); 84 84 this.messages = this.getFormScreen().getMessages(); 85 85 } … … 87 87 } 88 88 89 public Vector<ScreenMessage <E>> getMessages()89 public Vector<ScreenMessage> getMessages() 90 90 { 91 91 return messages; 92 92 } 93 93 94 public void setMessages(Vector<ScreenMessage <E>> messages)94 public void setMessages(Vector<ScreenMessage> messages) 95 95 { 96 96 this.messages = messages; -
molgenis/3.3/src/org/molgenis/framework/ui/commands/ChangeListLimitCommand.java
r2442 r2674 21 21 * @param <E> 22 22 */ 23 public class ChangeListLimitCommand <E extends Entity> extends SimpleCommand<E>23 public class ChangeListLimitCommand extends SimpleCommand 24 24 { 25 25 //the limit it should change too 26 26 private int limit = 5; 27 27 28 public ChangeListLimitCommand(String name, FormModel <E>parentScreen)28 public ChangeListLimitCommand(String name, FormModel parentScreen) 29 29 { 30 30 super(name, parentScreen); 31 31 this.setLabel("Show %s items"); 32 32 this.setIcon("generated-res/img/limit.png"); 33 this.setMenu("View"); 33 34 } 34 35 -
molgenis/3.3/src/org/molgenis/framework/ui/commands/CommandMenu.java
r2442 r2674 6 6 import java.util.Map; 7 7 8 import org.apache.log4j.Logger;9 8 import org.molgenis.framework.db.DatabaseException; 10 9 import org.molgenis.framework.ui.FormModel; … … 14 13 15 14 16 public class CommandMenu <E extends Entity> extends SimpleCommand<E>15 public class CommandMenu extends SimpleCommand 17 16 { 18 private static Logger logger = Logger.getLogger(CommandMenu.class);19 20 17 /** menu items with order as entered*/ 21 18 private Map<String,ScreenCommand> menu_items = new LinkedHashMap<String,ScreenCommand>(); 22 19 23 public CommandMenu(String id, FormModel<E>screen, String label, String icon, String action)20 public <E extends Entity>CommandMenu(String id, FormModel screen, String label, String icon, String action) 24 21 { 25 22 super( id, screen ); … … 44 41 if(menu_items.containsKey(command.getName())) 45 42 { 46 throw new IllegalArgumentException("addCommand: command with id '"+command.getName()+"' already exists");43 logger.warn("addCommand: command with id '"+command.getName()+"' already exists; replaced"); 47 44 } 48 45 menu_items.put(command.getName(),command); -
molgenis/3.3/src/org/molgenis/framework/ui/commands/DownloadAllCommand.java
r2442 r2674 21 21 * @param <E> 22 22 */ 23 public class DownloadAllCommand <E extends Entity> extends SimpleCommand<E>23 public class DownloadAllCommand extends SimpleCommand 24 24 { 25 public DownloadAllCommand(String name, FormModel <E>parentScreen)25 public DownloadAllCommand(String name, FormModel parentScreen) 26 26 { 27 27 super(name, parentScreen); … … 29 29 this.setIcon("generated-res/img/download.png"); 30 30 this.setDownload(true); 31 this.setMenu("File"); 31 32 } 32 33 … … 36 37 logger.debug(this.getName()); 37 38 38 FormModel <E>view = this.getFormScreen();39 FormModel view = this.getFormScreen(); 39 40 db.find(view.getEntityClass(), new CsvWriter(csvDownload), view.getRulesExclLimitOffset()); 40 41 -
molgenis/3.3/src/org/molgenis/framework/ui/commands/DownloadSelectedCommand.java
r2442 r2674 20 20 import org.molgenis.framework.ui.html.HtmlInput; 21 21 import org.molgenis.util.CsvWriter; 22 import org.molgenis.util.Entity;23 22 import org.molgenis.util.Tuple; 24 23 … … 28 27 * @param <E> 29 28 */ 30 public class DownloadSelectedCommand <E extends Entity> extends SimpleCommand<E>29 public class DownloadSelectedCommand extends SimpleCommand 31 30 { 32 public DownloadSelectedCommand(String name, FormModel <E>parentScreen)31 public DownloadSelectedCommand(String name, FormModel parentScreen) 33 32 { 34 33 super(name, parentScreen); … … 36 35 this.setIcon("generated-res/img/download.png"); 37 36 this.setDownload(true); 37 this.setMenu("File"); 38 38 } 39 39 … … 51 51 logger.debug(this.getName()); 52 52 53 FormModel <E>view = this.getFormScreen();53 FormModel view = this.getFormScreen(); 54 54 55 55 Object ids = request.getObject(FormModel.INPUT_SELECTED); … … 58 58 if (ids != null) 59 59 { 60 if (ids.getClass().equals(Vector.class)) records = (Vector <String>)ids;60 if (ids.getClass().equals(Vector.class)) records = (Vector)ids; 61 61 else 62 62 records.add(ids.toString()); -
molgenis/3.3/src/org/molgenis/framework/ui/commands/DownloadVisibleCommand.java
r2442 r2674 24 24 * @param <E> 25 25 */ 26 public class DownloadVisibleCommand <E extends Entity> extends SimpleCommand<E>26 public class DownloadVisibleCommand extends SimpleCommand 27 27 { 28 public DownloadVisibleCommand(String name, FormModel <E>parentScreen)28 public DownloadVisibleCommand(String name, FormModel parentScreen) 29 29 { 30 30 super(name, parentScreen); … … 32 32 this.setLabel("Download visible"); 33 33 this.setIcon("generated-res/img/download.png"); 34 this.setMenu("File"); 34 35 } 35 36 … … 40 41 logger.debug(this.getName()); 41 42 42 FormModel <E>view = this.getFormScreen();43 List<E > records = view.getRecords();43 FormModel view = this.getFormScreen(); 44 List<Entity> records = view.getRecords(); 44 45 CsvWriter writer = new CsvWriter(csvDownload, view.create().getFields()); 45 46 writer.writeHeader(); 46 for (E e : records)47 for (Entity e : records) 47 48 writer.writeRow(e); 48 49 -
molgenis/3.3/src/org/molgenis/framework/ui/commands/EditSelectedCommand.java
r2442 r2674 19 19 * template 20 20 */ 21 public class EditSelectedCommand <E extends Entity> extends SimpleCommand<E>21 public class EditSelectedCommand extends SimpleCommand 22 22 { 23 public EditSelectedCommand(String name, FormModel <E>parentScreen)23 public EditSelectedCommand(String name, FormModel parentScreen) 24 24 { 25 25 super(name, parentScreen); … … 27 27 this.setIcon("generated-res/img/update.gif"); 28 28 this.setDialog(true); 29 this.setMenu("Edit"); 29 30 } 30 31 … … 38 39 public boolean isVisible() 39 40 { 40 FormModel <E>view = this.getFormScreen();41 FormModel view = this.getFormScreen(); 41 42 return !view.isReadonly() && view.getMode().equals(Mode.LIST_VIEW); 42 43 } … … 50 51 if (request.getString(FormModel.INPUT_SHOW) == null) 51 52 { 52 FormModel <E>view = this.getFormScreen();53 FormModel view = this.getFormScreen(); 53 54 List<Object> idList = request.getList(FormModel.INPUT_SELECTED); 54 55 for (Object id : idList) … … 57 58 } 58 59 59 ScreenMessage <E>msg = null;60 ScreenMessage msg = null; 60 61 61 62 int row = 0; 62 63 try 63 64 { 64 Query q = db.query(view.getEntityClass()).in(view.create().getIdField(), idList);65 List<E > entities = q.find();65 Query<Entity> q = db.query(view.getEntityClass()).in(view.create().getIdField(), idList); 66 List<Entity> entities = q.find(); 66 67 67 68 db.beginTx(); 68 for (E e : entities)69 for (Entity e : entities) 69 70 { 70 71 row++; … … 73 74 } 74 75 db.commitTx(); 75 msg = new ScreenMessage <E>("MASS UPDATE SUCCESS: updated " + entities.size() + " rows", null, true);76 msg = new ScreenMessage("MASS UPDATE SUCCESS: updated " + entities.size() + " rows", null, true); 76 77 } 77 78 … … 87 88 e1.printStackTrace(); 88 89 } 89 msg = new ScreenMessage <E>("MASS UPDATE FAILED on item '" + row + "': " + e, null, false);90 msg = new ScreenMessage("MASS UPDATE FAILED on item '" + row + "': " + e, null, false); 90 91 } 91 92 -
molgenis/3.3/src/org/molgenis/framework/ui/commands/PluginCommand.java
r2308 r2674 9 9 import org.molgenis.util.Tuple; 10 10 11 public abstract class PluginCommand <E extends Entity> extends SimpleCommand<E>11 public abstract class PluginCommand extends SimpleCommand 12 12 { 13 13 /** Constructor */ 14 public PluginCommand(String name, FormModel <E>parentScreen)14 public PluginCommand(String name, FormModel parentScreen) 15 15 { 16 16 super(name, parentScreen); -
molgenis/3.3/src/org/molgenis/framework/ui/commands/RemoveSelectedCommand.java
r2442 r2674 20 20 import org.molgenis.util.Tuple; 21 21 22 public class RemoveSelectedCommand <E extends Entity> extends SimpleCommand<E>22 public class RemoveSelectedCommand extends SimpleCommand 23 23 { 24 public RemoveSelectedCommand(String name, FormModel <E>parentScreen)24 public RemoveSelectedCommand(String name, FormModel parentScreen) 25 25 { 26 26 super(name, parentScreen); 27 27 this.setLabel("Remove selected"); 28 28 this.setIcon("generated-res/img/delete.png"); 29 this.setMenu("Edit"); 29 30 } 30 31 … … 41 42 logger.debug(this.getName()); 42 43 43 FormModel <E>view = getFormScreen();44 FormModel view = getFormScreen(); 44 45 45 ScreenMessage <E>msg = null;46 ScreenMessage msg = null; 46 47 try 47 48 { … … 55 56 56 57 // find selected entities 57 Query q = db.query(view.getEntityClass()).in(view.create().getIdField(), idList);58 List<E > selection = q.find();58 Query<Entity> q = db.query(view.getEntityClass()).in(view.create().getIdField(), idList); 59 List<Entity> selection = q.find(); 59 60 60 61 // delete selected entities 61 62 db.remove(selection); 62 msg = new ScreenMessage <E>("REMOVED " + selection.size() + " records", null, true);63 msg = new ScreenMessage("REMOVED " + selection.size() + " records", null, true); 63 64 } 64 65 catch (Exception e) 65 66 { 66 msg = new ScreenMessage <E>("REMOVE SELECTION FAILED: " + e.getMessage(), null, false);67 msg = new ScreenMessage("REMOVE SELECTION FAILED: " + e.getMessage(), null, false); 67 68 } 68 69 view.getMessages().add(msg); -
molgenis/3.3/src/org/molgenis/framework/ui/commands/ScreenCommand.java
r2442 r2674 16 16 17 17 /** 18 * A command describes actions to change the state of a screen (each consequence 19 * of command is handled by a Screen.handleRequest function). 18 * A command defines a button on a screen, including the logic when the command 19 * is executed. In architecture it behaves the same as any screen, i.e. it is 20 * Templateable to allow for customized layouts. However, the default layout is 21 * usually sufficient listing inputs (from getInputs) and actions (from 22 * getActions). 23 * <ul> 24 * <li>handleRequest() defines how the action should be processed and how the 25 * result should be shown</li> 26 * <li>getInputs() lists the inputs to be shown</li> 27 * <li>getActions() lists the pushbuttons to be shown</li> 28 * </ul> 20 29 */ 21 public interface ScreenCommand <E extends Entity>extends Templateable30 public interface ScreenCommand extends Templateable 22 31 { 23 32 /** 24 * Retrieve the name of the icon to be shown. No icon will be if null)33 * Retrieve the name of the icon to be shown. No icon will be shown if null. 25 34 * 26 35 * @return path to the icon … … 29 38 30 39 /** 31 * Set the name of the icon to be shown. No icon will be if null )40 * Set the name of the icon to be shown. No icon will be if null. 32 41 * 33 42 * @param icon … … 37 46 38 47 /** 39 * Hide this command40 *41 * @param hide42 * if true, the command will be hidden.43 */44 public void setHidden(boolean hide);45 46 /**47 48 * @return descriptive label of this command 48 49 */ … … 56 57 57 58 /** 58 * Override the default javascript for this command by your own. 59 * Override the default javascript for this command by your own (usally not 60 * necessary, @see 'isDialog'). 59 61 * 60 62 * @param action … … 64 66 65 67 /** 66 * FIXME can this be hidden?68 * Returns the javascript that is run when this action is clicked. 67 69 * 68 70 * @return the javascript that should be executed onClick. … … 72 74 /** 73 75 * @param name 74 * unique action name of this command (unique within one screen) 76 * unique action name of this command (unique within the parent 77 * screen) 75 78 */ 76 79 public void setName(String name); … … 81 84 public String getName(); 82 85 83 /** @return Unique name of the target screen that should handle this command */ 86 /** 87 * @return Unique name of the target screen that should handle this command. 88 * Default this equals getScreen(), i.e. the target is the same as 89 * the screen this command is part of. 90 */ 84 91 public String getTarget(); 85 92 86 93 /** 87 * @param target Unique 88 * name of the target screen that should handle this command 94 * @param target 95 * Unique name of the target screen that should handle this 96 * command 89 97 */ 90 98 public void setTarget(String target); 91 99 92 100 /** 93 * @return The screen this command is a childof101 * @return The screen this command is a part of 94 102 */ 95 103 public ScreenModel getScreen(); 96 104 97 105 /** 98 106 * Helper method to reduce casting … … 106 114 public void setScreen(ScreenModel screen); 107 115 108 /** @return true if this command should show a dialog */ 116 /** 117 * @return true if this command should be shown as a dialog. @see #setDialog 118 */ 109 119 public boolean isDialog(); 110 120 111 121 /** 112 * @param dialog set 113 * to true if MOLGENIS should show this command via a dialog 122 * @param dialog 123 * set to true if MOLGENIS should show this command via a dialog. 124 * This results in javascript that pop-ups a dialog when pushed. 114 125 */ 115 126 public void setDialog(boolean dialog); … … 117 128 /** 118 129 * @return the unique name of the menu this command is part of. Null 119 * indicates it will no wshown on the menu.130 * indicates it will not be shown on the menu. 120 131 */ 121 132 public String getMenu(); … … 123 134 /** 124 135 * @param menu 125 * unique name of the screenmenu this command is part of (typically shown on top of each screen). Not to be confused with the parent ScreenMenu. 136 * unique name of the screenmenu this command is part of 137 * (typically shown on top of each screen). Not to be confused 138 * with the parent ScreenMenu. 126 139 */ 127 140 public void setMenu(String menu); … … 142 155 143 156 /** 144 * Handle the request thrown by this command. Typically handled by subclassing. 145 * 146 * @param db provides access to the database 157 * Handle the request thrown by this command. 158 * 159 * @param db 160 * provides access to the database 147 161 * @param request 162 * provides access to the filled in inputs and actions 148 163 * @param downloadStream 149 * this the request can use to write results as download 150 * @return if their should still be a popup, inline or download 164 * this the request can use to write results as download (in 165 * combination with Show.VIEW_DOWNLOAD 166 * @return a Show.XYZ that indicates if next action should be shown as 167 * popup, back to main screen or as download. @see ScreenModel.Show 151 168 * @throws IOException 152 169 * @throws DatabaseException 153 170 * @throws ParseException 154 171 */ 155 public ScreenModel.Show handleRequest(Database db, Tuple request, PrintWriter downloadStream) throws ParseException,156 DatabaseException, IOException;172 public ScreenModel.Show handleRequest(Database db, Tuple request, PrintWriter downloadStream) 173 throws ParseException, DatabaseException, IOException; 157 174 158 175 /** 159 176 * @return boolean whether this action should be treated as a download 160 * action.177 * button. 161 178 */ 162 179 public boolean isDownload(); 163 180 164 181 /** 165 * @param download true indicates that this action should be treated as a download 166 * action. @see handleRequest() where the download target is passed as stream. 182 * @param download 183 * true indicates that this action should be treated as a 184 * download action. @see handleRequest() where the download 185 * target is passed as stream and ScreenModel.Show can return 186 * Show.VIEW_DOWNLOAD. 167 187 */ 168 188 public void setDownload(boolean download); 169 189 170 190 /** 171 * @return whether this command should be shown on the command menu 191 * @return whether this command should be shown on the command menu. 172 192 */ 173 193 public boolean isToolbar(); … … 176 196 * @param showOnToolbar 177 197 * indicates whether this command should be shown on the command 178 * menu 198 * menu. 179 199 */ 180 200 public void setToolbar(boolean showOnToolbar); 181 201 182 202 /** 183 * @return the layout macro to be used if this command has a dialog 184 */ 185 String getViewName(); 186 187 /** 188 * @return the layout macro to be used if this command has a dialog 189 */ 190 String getViewTemplate(); 203 * @return the layout macro to be used if this command has a dialog. 204 * Defaults to the default layout showing inputs and actions. 205 */ 206 public String getViewName(); 207 208 /** 209 * @return the layout macro to be used if this command has a dialog. 210 * Defaults to the default layout template for commands, 211 * ScreenCommand.ftl 212 */ 213 public String getViewTemplate(); 191 214 192 215 /** -
molgenis/3.3/src/org/molgenis/framework/ui/commands/SimpleCommand.java
r2442 r2674 12 12 import org.molgenis.framework.ui.ScreenModel; 13 13 import org.molgenis.framework.ui.ScreenModel.Show; 14 import org.molgenis.framework.ui.html.HtmlForm; 14 15 import org.molgenis.framework.ui.html.HtmlInput; 15 16 import org.molgenis.util.Entity; … … 17 18 18 19 /** 19 * Base class to link a command to a formscreen. <br> 20 * TODO: this may be very useful for other screens also. 20 * Implementation of screen command. 21 21 */ 22 public abstract class SimpleCommand <E extends Entity> implements ScreenCommand<E>22 public abstract class SimpleCommand implements ScreenCommand 23 23 { 24 24 /** Logger */ 25 25 public Logger logger = Logger.getLogger(this.getClass().getSimpleName()); 26 26 27 /** Internal name of this command (unique within the screen (*/27 /** Internal name of this command (unique within the screen) */ 28 28 private String name; 29 29 30 /** The pretty label of this command (default: getName() */30 /** The pretty label of this command (default: getName()) */ 31 31 private String label; 32 32 33 /** Path to an icon image */33 /** Path to an icon image to show on this command */ 34 34 private String icon; 35 35 36 /** Piece of javascript (default: autogenerated) */ 37 private String action; 38 39 /** The name of the screen to be target (default: parent screen) */ 40 private String target; 36 /** Piece of javascript; if none is provide it is autogenerated depend on all settings */ 37 private String onClickJavascript; 38 39 /** The Screen this command is linked to */ 40 private ScreenModel screen; 41 42 /** The name of the screen to be target (default: this.screen) */ 43 private String targetScreen; 41 44 42 45 /** Indicates to the screen to show a dialog box for this action */ 43 private boolean dialog = false;46 private boolean showDialog = false; 44 47 45 48 /** Indicates to the screen to start a download procedure for this action */ 46 49 private boolean download = false; 47 50 48 /** The Screen this command is linked to */49 private ScreenModel screen;50 51 51 /** The name of the menu this command should be shown on */ 52 52 private String menu; 53 53 54 54 /** Indicates to the screen to show this command on the toolbar */ 55 private boolean toolbar; 56 57 /** 58 * Tells that this action should be hidden for now (for dynamic menu 59 * options) 60 */ 61 private boolean visible; 62 63 /** 64 * Default constructure. Note that this.setScreen needs to be called 65 * elsewhere. 66 */ 67 public SimpleCommand() 68 { 69 this.setName(this.getClass().getSimpleName()); 70 // note that this.setScreen needs to be called elsewhere. 71 } 55 private boolean showOnToolbar; 72 56 73 57 /** … … 78 62 * @param parentScreen 79 63 */ 80 public SimpleCommand(String name, FormModel <E>parentScreen)64 public SimpleCommand(String name, FormModel parentScreen) 81 65 { 82 66 this.setName(name); … … 89 73 public String getJavaScriptAction() 90 74 { 91 if ( action== null)75 if (onClickJavascript == null) 92 76 { 93 77 if (this.getScreen() == null) throw new NullPointerException("setScreen() has not been set on command '" … … 156 140 return jScript.toString(); 157 141 } 158 return action;142 return onClickJavascript; 159 143 } 160 144 … … 193 177 194 178 @Override 195 public void setHidden(boolean hidden)196 {197 this.visible = hidden;198 }199 200 @Override201 179 public void setJavaScriptAction(String action) 202 180 { 203 this. action= action;181 this.onClickJavascript = action; 204 182 } 205 183 … … 219 197 public String getTarget() 220 198 { 221 return this.target ;199 return this.targetScreen; 222 200 } 223 201 … … 225 203 public void setTarget(String target) 226 204 { 227 this.target = target;205 this.targetScreen = target; 228 206 } 229 207 … … 235 213 236 214 @Override 237 public FormModel<E > getFormScreen()215 public FormModel<Entity> getFormScreen() 238 216 { 239 217 return (FormModel) this.screen; … … 249 227 public boolean isDialog() 250 228 { 251 return dialog;229 return showDialog; 252 230 } 253 231 … … 255 233 public void setDialog(boolean dialog) 256 234 { 257 this. dialog = dialog;235 this.showDialog = dialog; 258 236 } 259 237 … … 297 275 public boolean isToolbar() 298 276 { 299 return toolbar;277 return showOnToolbar; 300 278 } 301 279 … … 303 281 public void setToolbar(boolean toolbar) 304 282 { 305 this. toolbar = toolbar;283 this.showOnToolbar = toolbar; 306 284 } 307 285 -
molgenis/3.3/src/org/molgenis/framework/ui/commands/ViewEditViewCommand.java
r2442 r2674 16 16 import org.molgenis.util.Tuple; 17 17 18 public class ViewEditViewCommand <E extends Entity> extends SimpleCommand<E>18 public class ViewEditViewCommand extends SimpleCommand 19 19 { 20 public ViewEditViewCommand(String name, FormModel <E>parentScreen)20 public ViewEditViewCommand(String name, FormModel parentScreen) 21 21 { 22 22 super(name, parentScreen); 23 23 this.setLabel("Edit Record"); 24 24 this.setIcon("generated-res/img/editview.gif"); 25 this.setMenu("View"); 25 26 } 26 27 … … 42 43 && !this.getFormScreen().isReadonly() 43 44 && this.getFormScreen().getRecordInputs().size() != 0 44 && !this.getFormScreen().getRecord Inputs().get(0).isReadonly();45 && !this.getFormScreen().getRecords().get(0).isReadonly(); 45 46 } 46 47 -
molgenis/3.3/src/org/molgenis/framework/ui/commands/ViewListViewCommand.java
r2442 r2674 15 15 import org.molgenis.framework.ui.FormModel.Mode; 16 16 import org.molgenis.framework.ui.html.HtmlInput; 17 import org.molgenis.util.Entity;18 17 import org.molgenis.util.Tuple; 19 18 20 public class ViewListViewCommand <E extends Entity> extends SimpleCommand<E>19 public class ViewListViewCommand extends SimpleCommand 21 20 { 22 public ViewListViewCommand(String name, FormModel <E>parentScreen)21 public ViewListViewCommand(String name, FormModel parentScreen) 23 22 { 24 23 super(name, parentScreen); 25 24 this.setLabel("List Records"); 26 25 this.setIcon("generated-res/img/listview.png"); 26 this.setMenu("View"); 27 27 } 28 28 -
molgenis/3.3/src/org/molgenis/framework/ui/html/HtmlForm.java
r2442 r2674 4 4 import java.util.ArrayList; 5 5 import java.util.List; 6 import java.util.Vector;7 6 8 7 import org.molgenis.util.Entity; … … 10 9 import org.molgenis.util.Tuple; 11 10 12 public class HtmlForm <E extends Entity>11 public class HtmlForm 13 12 { 14 13 /** The entity to be shown in this form*/ 15 private E entity = null;14 private Entity entity = null; 16 15 /** Some columns can be hidden, using the name*/ 17 16 private List<String> hiddenColumns = new ArrayList<String>(); … … 49 48 } 50 49 51 public HtmlForm(E entity)50 public HtmlForm(Entity entity) 52 51 { 53 52 this.entity = entity; … … 65 64 } 66 65 67 public E getEntity()66 public Entity getEntity() 68 67 { 69 68 return entity; 70 69 } 71 70 72 public void setEntity(E entity)71 public void setEntity(Entity entity) 73 72 { 74 73 this.entity = entity; -
molgenis/3.3/src/org/molgenis/framework/ui/html/MrefInput.java
r2381 r2674 17 17 import java.util.Arrays; 18 18 import java.util.List; 19 import java.util.Map; 19 20 20 21 import org.molgenis.framework.db.QueryRule; … … 29 30 //private List<ValueLabel> options = new Vector<ValueLabel>(); 30 31 //The label of the value to show in the box 31 private List<String> valueLabels; 32 //xrefLabel,values 33 private Map<String,List> valueLabels; 32 34 //what is this? 33 35 private String targetfield; … … 36 38 private String xrefEntity; 37 39 private String xrefField; 38 private String xrefLabel;40 private List<String> xrefLabels = new ArrayList<String>(); 39 41 private List<QueryRule> xrefFilters = new ArrayList<QueryRule>(); 40 42 … … 57 59 input.setXrefEntity(this.getXrefEntity()); 58 60 input.setXrefField(this.getXrefField()); 59 input.setXrefLabel (this.getXrefLabel());61 input.setXrefLabels(this.getXrefLabels()); 60 62 input.setReadonly(this.isReadonly()); 61 63 input.setStyle("display: block;"); … … 68 70 { 69 71 input.setValue(values.get(i)); 70 input.setValueLabel(this.getValueLabels().get(i)); 72 73 String result = ""; 74 75 for(String labelName: this.getXrefLabels()) 76 { 77 input.setValueLabel(labelName, this.getValueLabels(labelName).get(i)); 78 } 71 79 input.setId(this.getName()+i); 72 80 html.append(input.toHtml()); … … 80 88 } 81 89 82 String buttons = String.format("<button style=\"\" type=\"button\" onclick=\"mref_addInput('%s','%s','%s','%s','%s',this.parentNode);\">+</button>", getName(), getXrefEntity(), getXrefField(), getXrefLabel (), getXrefFilterRESTString());90 String buttons = String.format("<button style=\"\" type=\"button\" onclick=\"mref_addInput('%s','%s','%s','%s','%s',this.parentNode);\">+</button>", getName(), getXrefEntity(), getXrefField(), getXrefLabels(), getXrefFilterRESTString()); 83 91 buttons +="<button type=\"button\" onclick=\"mref_removeInput(this.parentNode);\">-</button>"; 84 92 … … 92 100 public String getValue() 93 101 { 94 95 if(this.getValueLabels() == null) 96 return ""; 102 String result = ""; 97 103 98 List<String> labels = this.getValueLabels(); 99 String result = ""; 100 for(int i = 0; i < labels.size(); i++) 104 int size = this.getValueLabels(this.getXrefLabels().get(0)).size(); 105 for(int i = 0; i < size ; i++) 101 106 { 102 if(i>0) result += ",\n"; 103 result += labels.get(i); 107 String valueLabel = ""; 108 for(String labelName: this.getXrefLabels()) 109 { 110 111 if(valueLabel.equals("")) 112 valueLabel += this.getValueLabels(labelName).get(i); 113 else 114 valueLabel += ":" + this.getValueLabels(labelName).get(i); 115 } 116 result += valueLabel; 104 117 } 105 106 118 107 119 return result; … … 139 151 } 140 152 141 public String getXrefLabel() { 142 return xrefLabel; 153 public List<String> getXrefLabels() { 154 return xrefLabels; 155 } 156 157 public void setXrefLabels(List<String> xrefLabels) { 158 this.xrefLabels = xrefLabels; 143 159 } 144 160 145 161 public void setXrefLabel(String xrefLabel) { 146 this.xrefLabel = xrefLabel; 162 this.xrefLabels.clear(); 163 this.xrefLabels.add(xrefLabel); 147 164 } 148 165 149 public List<String> getValueLabels( ) {150 return valueLabels ;166 public List<String> getValueLabels(String xrefLabelName) { 167 return valueLabels.get(xrefLabelName); 151 168 } 152 169 153 public void setValueLabels( List<String>valueLabels) {154 this.valueLabels = valueLabels;170 public void setValueLabels(String xrefLabelName, List valueLabels) { 171 this.valueLabels.put(xrefLabelName, valueLabels); 155 172 } 156 173 -
molgenis/3.3/src/org/molgenis/framework/ui/html/XrefInput.java
r2308 r2674 14 14 15 15 // jdk 16 import java.util.LinkedHashMap; 17 import java.util.List; 18 import java.util.Map; 19 16 20 import org.molgenis.util.Entity; 17 21 18 22 /** 19 23 * Input for cross-reference (xref) data. Data will be shown as selection box. 24 * Optionally, multi-column xref_labels can be set. 20 25 */ 21 26 public class XrefInput extends HtmlInput … … 23 28 //private List<ValueLabel> options = new Vector<ValueLabel>(); 24 29 //The label of the value to show in the box 25 private String valueLabel;30 private Map<String,Object> valueLabel = new LinkedHashMap<String,Object>(); 26 31 //what is this? 27 32 private String targetfield; … … 30 35 private String xrefEntity; 31 36 private String xrefField; 32 private String xrefLabel;37 private List<String> xrefLabels; 33 38 34 39 public XrefInput(String name, Object value) … … 40 45 public String toHtml() 41 46 { 42 String readonly = (this.isReadonly()) ? " readonly class=\"readonly\" " : String.format(" onfocus=\"showXrefInput(this,'%s','%s','%s'); return false;\" ", xrefEntity, xrefField, xrefLabel); 47 String xrefLabelString = this.toCsv(xrefLabels); 48 String readonly = (this.isReadonly()) ? " readonly class=\"readonly\" " : String.format(" onfocus=\"showXrefInput(this,'%s','%s','%s'); return false;\" ", xrefEntity, xrefField, xrefLabelString); 43 49 44 50 if (this.isHidden()) … … 54 60 if(super.getObject() != null) 55 61 { 56 optionsHtml.append("\t<option selected value=\""+super.getValue()+"\">"+this.getValue Label()+"</option>\n");62 optionsHtml.append("\t<option selected value=\""+super.getValue()+"\">"+this.getValue()+"</option>\n"); 57 63 } 58 64 if (!this.isReadonly()) … … 64 70 } 65 71 72 private String toCsv(List<String> xrefLabels) 73 { 74 String result = ""; 75 for(String label: xrefLabels) 76 { 77 result+= ","+label; 78 } 79 80 return result.replaceFirst(",", ""); 81 } 82 66 83 @Override 67 84 /** … … 70 87 public String getValue() 71 88 { 72 73 if(this.getValueLabel() == null) 74 return ""; 75 return this.getValueLabel(); 89 String result = ""; 90 for(String label: this.xrefLabels) 91 { 92 if(result.equals("")) 93 result += this.valueLabel.get(label); 94 else 95 result += ":" + this.valueLabel.get(label); 96 } 97 98 return result; 76 99 } 77 100 … … 107 130 } 108 131 109 public StringgetXrefLabel() {110 return xrefLabel ;132 public List<String> getXrefLabel() { 133 return xrefLabels; 111 134 } 112 135 113 136 public void setXrefLabel(String xrefLabel) { 114 this.xrefLabel = xrefLabel; 137 this.xrefLabels.clear(); 138 this.xrefLabels.add(xrefLabel); 139 } 140 141 public void setXrefLabels(List<String> xrefLabels) { 142 this.xrefLabels = xrefLabels; 115 143 } 116 144 117 public String getValueLabel() {118 return valueLabel ;145 public Object getValueLabel(String xrefLabelName) { 146 return valueLabel.get(xrefLabelName); 119 147 } 120 148 121 public void setValueLabel(String valueLabel) {122 this.valueLabel = valueLabel;149 public void setValueLabel(String xrefLabelName, Object valueLabel) { 150 this.valueLabel.put(xrefLabelName, valueLabel); 123 151 } 124 152 -
molgenis/3.3/src/org/molgenis/generators/ui/FormScreenGen.java.ftl
r2594 r2674 55 55 private static final long serialVersionUID = 1L; 56 56 57 public ${Name(form.className)}Form() 58 { 59 this(null); 60 } 61 57 62 public ${Name(form.className)}Form(ScreenModel parent) 58 63 { … … 72 77 <#if field.getType() == "xref" || field.getType() == "mref"> 73 78 <#list superclasses(parent_form.getRecord()) as parent_entity> 74 <#if parent_entity.getName() == field. getXRefEntity()>75 //filter on <#if field.getType() == "mref">ANY </#if>subform_entity.${name(field)} == parentform_entity.${field. getXRefField()}76 this.getParentFilters().add(new ParentFilter("${parent_form.name}","${SqlName(field. getXRefField())}","${SqlName(field.getXRefLabelString())}","${SqlName(name(field))}"));79 <#if parent_entity.getName() == field.xrefEntityName> 80 //filter on <#if field.getType() == "mref">ANY </#if>subform_entity.${name(field)} == parentform_entity.${field.xrefField} 81 this.getParentFilters().add(new ParentFilter("${parent_form.name}","${SqlName(field.xrefField)}",Arrays.asList("${csv(field.xrefLabelNames)}".split(",")),"${SqlName(name(field))}")); 77 82 </#if> 78 83 </#list> … … 85 90 <#if field.getType() == "xref" || field.getType() == "mref"> 86 91 <#list superclasses(form.getRecord()) as subform_entity> 87 <#if subform_entity.getName() == field. getXRefEntity()>88 //filter on subform_entity.${field. getXRefField()} == <#if field.getType() == "mref">ANY </#if> parentform_entity.${name(field)}89 this.getParentFilters().add(new ParentFilter("${parent_form.name}","${SqlName(name(field))}", "${SqlName(field.getXRefLabelString())}","${SqlName(field.getXRefField())}"));92 <#if subform_entity.getName() == field.xrefEntityName> 93 //filter on subform_entity.${field.xrefField} == <#if field.getType() == "mref">ANY </#if> parentform_entity.${name(field)} 94 this.getParentFilters().add(new ParentFilter("${parent_form.name}","${SqlName(name(field))}",Arrays.asList("${csv(field.xrefLabelNames)}".split(",")),"${SqlName(field.xrefField)}")); 90 95 </#if> 91 96 </#list> … … 93 98 </#list> 94 99 </#if> 95 <#list form. actions as action>96 this.add Action(new ${action}<${entity}>(this));100 <#list form.commands as command> 101 this.addCommand(new ${command}(this)); 97 102 </#list> 98 103 <#if form.readOnly> … … 123 128 124 129 @Override 125 public HtmlForm <${entity}>getInputs(${entity} entity, boolean newrecord)126 { 127 HtmlForm <${Name(entity)}> form = new HtmlForm<${Name(entity)}>();130 public HtmlForm getInputs(${entity} entity, boolean newrecord) 131 { 132 HtmlForm form = new HtmlForm(); 128 133 form.setNewRecord(newrecord); 129 134 form.setReadonly(isReadonly()); … … 153 158 </#if> 154 159 <#if inputtype = "Xref" || inputtype = "Mref"> 155 <#assign xref_entity = model.getEntity(field.XRefEntity)> 156 input.setXrefEntity("${xref_entity.getNamespace()}.${JavaName(field.XRefEntity)}"); 157 input.setXrefField("${name(field.XRefField)}"); 158 input.setXrefLabel("${name(field.XRefLabelString)}"); 159 //initialize the ${field.XRefEntity}.${field.XRefLabelString} of current record 160 input.setValueLabel<#if inputtype = "Mref">s</#if>(entity.get${JavaName(field)}Label<#if inputtype = "Mref">s</#if>()); 160 <#assign xref_entity = field.xrefEntity> 161 input.setXrefEntity("${xref_entity.getNamespace()}.${JavaName(field.xrefEntity)}"); 162 input.setXrefField("${name(field.xrefField)}"); 163 input.setXrefLabels(Arrays.asList("${csv(field.xrefLabelNames)}".split(","))); 164 //initialize the ${field.xrefEntityName}.${csv(field.xrefLabelNames)} of current record 165 <#if field.xrefLabelNames[0] != field.xrefFieldName><#list field.xrefLabelNames as label> 166 input.setValueLabel<#if inputtype = "Mref">s</#if>("${label}", entity.get${JavaName(field)}_${label}()); 167 </#list><#else> 168 input.setValueLabel<#if inputtype = "Mref">s</#if>("${field.xrefField}", entity.get${JavaName(field)}()); 169 </#if> 161 170 </#if> 162 171 <#if field.hidden> … … 187 196 <#list form.getRecord().getAllFields() as field> 188 197 <#if field.type="xref" || field.type="mref"> 189 if(fieldName.equals("${name(field)}")) return "${name(field)}_${name(field.getXRefLabelString())}"; 198 <#list field.xrefLabelNames as label> 199 if(fieldName.equals("${name(field)}")) return "${name(field)}_${name(label)}"; 200 </#list> 190 201 </#if> 191 202 </#list> -
molgenis/3.3/src/org/molgenis/generators/ui/PluginScreenGen.java.ftl
r2308 r2674 31 31 super("${plugin.getVelocityName()}", parent); 32 32 this.setLabel("${plugin.label}"); 33 34 <#list plugin.getChildren() as subscreen> 35 <#assign screentype = Name(subscreen.getType().toString()?lower_case) /> 36 new ${package}.${JavaName(subscreen)}${screentype}(this); 37 </#list> 33 38 } 34 39 <#else> … … 36 41 { 37 42 super("${plugin.getVelocityName()}", parent); 38 this.setLabel("${plugin.label}"); 43 this.setLabel("${plugin.label}"); 44 45 <#list plugin.getChildren() as subscreen> 46 <#assign screentype = Name(subscreen.getType().toString()?lower_case) /> 47 new ${package}.${JavaName(subscreen)}${screentype}(this); 48 </#list> 39 49 } 40 50 </#if>
Note: See TracChangeset
for help on using the changeset viewer.