[Logo] OLD FORUM - Use new one: https://www.CaptainCasa.online/forum
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Set a limit for parallel openend workpages  XML
Forum Index -> Development - Code Snippets
Author Message
Anonymous



There's a simple way to set a limit for max. opened pages.

You have to override some methods of your Dispatcher class which inherits from WorkpageDispatcher.
Code:
/**
  * This constructor is called initially 
  */
 public Dispatcher() {
   super();
   // Limit nr. of max opened pages
   getWorkpageContainer().setMaxNumberOfWorkpages(Constants.MAXWORKPAGES);
   //getWorkpageContainer().setMaxNumberOfWorkpagesExceededMessage("My own message!");
 }
 
 /**
  * This constructor is called when a new workpage is opened
  * @param workpageContainer
  */
 public Dispatcher(IWorkpageContainer workpageContainer) {
   super(workpageContainer);
   int openedPages = workpageContainer.getAllWorkpages().size();
   System.out.println(openedPages + " Workpages opened!");
   for(Object obj : workpageContainer.getAllWorkpages()) {
     Workpage wp = (Workpage)obj;
     System.out.println(wp.getTitle());
   }		
   if(openedPages >= Constants.MAXWORKPAGES) {
     Workpage wp = (Workpage)workpageContainer.getAllWorkpages().get(0);
     workpageContainer.getAllWorkpages().remove(0);
     System.out.println("Close " + wp.getTitle());
     wp.closeForced();
   }	
 }

If you just want to limit the amount, it's enough to override Dispatcher(), when the user exceeds the number of pages, he gets a popup.
If you want to do further manipulations in your workplace you can override Dispatcher(IWorkpageContainer), this constructor is called everytime a new page is opened!
 
Forum Index -> Development - Code Snippets
Go to:   
Powered by JForum 2.1.6 © JForum Team