function menu = getPopupSchema(this, manager)
% GETPOPUPSCHEMA 

% Author(s): John Glass, B. Eryilmaz
% Revised: 
% Copyright 1986-2004 The MathWorks, Inc.
% $Revision: 1.1.6.3 $ $Date: 2004/11/18 23:44:20 $

menu  = com.mathworks.mwswing.MJPopupMenu('Default Menu');
item1 = com.mathworks.mwswing.MJMenu('New');
item2 = com.mathworks.mwswing.MJMenuItem('Project...');
item3 = com.mathworks.mwswing.MJMenuItem('Task...');
item4 = com.mathworks.mwswing.MJMenuItem('Load...');
item5 = com.mathworks.mwswing.MJMenuItem('Save...');

menu.add( item1 ); item1.add( item2 ); item1.add( item3 );
menu.addSeparator;
menu.add( item4 );
menu.add( item5 );

h = handle( item2, 'callbackproperties' );
fun = @(x,y) LocalNewProject(this, manager);
h.ActionPerformedCallback = fun;
h.MouseClickedCallback    = fun;

h = handle( item3, 'callbackproperties' );
fun = @(x,y) LocalNewTask(this, manager);
h.ActionPerformedCallback = fun;
h.MouseClickedCallback    = fun;

h = handle( item4, 'callbackproperties' );
fun = @(x,y) LocalLoad(this, manager);
h.ActionPerformedCallback = fun;
h.MouseClickedCallback    = fun;

h = handle( item5, 'callbackproperties' );
fun = @(x,y) LocalSave(this, manager);
h.ActionPerformedCallback = fun;
h.MouseClickedCallback    = fun;

% --------------------------------------------------------------------------- %
function LocalNewProject(this, manager)
% Create the new project dialog and let it handle the rest
newdlg = explorer.NewProjectDialog(this);
awtinvoke(newdlg.Dialog, 'setVisible', true)

% --------------------------------------------------------------------------- %
function LocalNewTask(this, manager)
% Create the new task dialog and let it handle the rest
% Find non-MPC projects
theseChildren = setdiff(this.getChildren, ...
                        this.find('-class','mpcnodes.MPCGUI','-depth',1));
if isempty(theseChildren)
  newdlg = explorer.NewProjectDialog(this);
else
  newdlg = explorer.NewTaskDialog(this);
end
awtinvoke(newdlg.Dialog, 'setVisible', true)

% --------------------------------------------------------------------------- %
function LocalLoad(this, manager)
manager.loadfrom(this.getChildren);

% --------------------------------------------------------------------------- %
function LocalSave(this, manager)
manager.saveas(this.getChildren)
