% WORKSPACEBROWSER creates a new Workspace Browser.
%
% CALL:
%         >> workspaceBrowser
%
% M Hewitson 23-11-08
%
% $Id: workspaceBrowser.m,v 1.9 2010/03/23 17:41:29 ingo Exp $
%


classdef workspaceBrowser < handle
  %------------------------------------------------
  %---------- Private read-only Properties --------
  %------------------------------------------------
  properties (SetAccess = public)
    hdl   = [];
    name = '';
    executing = false;
    h1;
    h2;
    h3;
    h4;
    h5;
    h6;
    h7;
    h8;
    h9;
    h10;
  end
  
  %-----------------------------------------
  %  Public methods
  %-----------------------------------------
  methods
    
    % Construct a new workbench
    function wb = workspaceBrowser(varargin)
      
      twb = getappdata(0, 'WorkspaceBrowser');
      
      if isa(twb, mfilename)
        
        disp('*** Found existing Workspace Browser.')
        wb = twb;
        workspaceBrowser.cb_buildModel(wb);
        awtinvoke(wb.hdl, 'setVisible', 'true');
        awtinvoke(wb.hdl, 'toFront');
        
      else
        
        switch nargin
          case 0
            % Create a new WorkspaceBrowser
            wb.hdl = mpipeline.workspace.WorkspaceBrowserDialog([], false);
            pause(0.1);
            % Show the browser
            awtinvoke(wb.hdl, 'setVisible', 'true');
            pause(0.1);
            
        end
        
        %--- called when window is closed
        wb.h1 = handle(wb.hdl, 'callbackproperties');
        wb.h1.WindowClosedCallback = @workspaceBrowser.cb_guiClosed;
        
        % Add button actions
        
        %--- Refresh button
        wb.h2 = handle(wb.hdl.getRefreshBtn,'callbackproperties');
        wb.h2.ActionPerformedCallback = @workspaceBrowser.cb_buildModel;
        
        %--- Plot button
        wb.h3 = handle(wb.hdl.getPlotBtn,'callbackproperties');
        wb.h3.ActionPerformedCallback = @workspaceBrowser.cb_plot;
        
        %--- Display button
        wb.h4 = handle(wb.hdl.getDisplayBtn,'callbackproperties');
        wb.h4.ActionPerformedCallback = @workspaceBrowser.cb_display;
        
        %--- Plot history button
        wb.h5 = handle(wb.hdl.getPlotHistoryBtn,'callbackproperties');
        wb.h5.ActionPerformedCallback = @workspaceBrowser.cb_plothistory;
        
        %--- Submit button
        wb.h6 = handle(wb.hdl.getSubmitBtn,'callbackproperties');
        wb.h6.ActionPerformedCallback = @workspaceBrowser.cb_submit;
        
        %--- Explore button
        wb.h7 = handle(wb.hdl.getExploreBtn,'callbackproperties');
        wb.h7.ActionPerformedCallback = @workspaceBrowser.cb_explore;
        
        %--- Query button
        wb.h8 = handle(wb.hdl.getQueryBtn,'callbackproperties');
        wb.h8.ActionPerformedCallback = @workspaceBrowser.cb_query;
        
        %--- Retrieve button
        wb.h9 = handle(wb.hdl.getRetrieveBtn,'callbackproperties');
        wb.h9.ActionPerformedCallback = @workspaceBrowser.cb_retrieve;
        
        %--- repository Manager button
        wb.h10 = handle(wb.hdl.getRepositoryManagerBtn,'callbackproperties');
        wb.h10.ActionPerformedCallback = @workspaceBrowser.cb_repoManager;
        
        % Store the java gui in the application workspace
        setappdata(0, 'WorkspaceBrowser', wb);
        
        % Set the model
        workspaceBrowser.cb_buildModel
        
      end
    end % End constructor
    
    % Display method to make a quiet output
    function display(varargin)
    end
    
    
  end % End public methods
  
  methods(Access=private)
  end
  
  methods (Static=true)
    
    varargout = getSelectedObjects(varargin)
    varargout = getSelectedVarNames(varargin)
    
    varargout = cb_buildModel(varargin)
    varargout = cb_plot(varargin)
    varargout = cb_display(varargin)
    varargout = cb_plothistory(varargin)
    varargout = cb_submit(varargin)
    varargout = cb_explore(varargin)
    varargout = cb_query(varargin)
    varargout = cb_retrieve(varargin)    
    varargout = cb_guiClosed(varargin)
    varargout = cb_repoManager(varargin)
    
    varargin = retrieveObjectsFromDialog(varargin)
    
  end
  %------------------------------------------------
  % Private static methods
  %------------------------------------------------
  methods(Access=private, Static=true)
  end
  
end

