control
Class Controller

java.lang.Object
  extended by org.eclipse.jface.window.Window
      extended by org.eclipse.jface.window.ApplicationWindow
          extended by control.Controller
All Implemented Interfaces:
org.eclipse.jface.operation.IRunnableContext, org.eclipse.jface.window.IShellProvider

public class Controller
extends org.eclipse.jface.window.ApplicationWindow

The Controller class is responsible for manipulating the underlying model. User interaction of the database is delegated to public methods of the Controller.

Author:
pgroudas

Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.jface.window.Window
org.eclipse.jface.window.Window.IExceptionHandler
 
Field Summary
private  AboutAction aboutAction
           
private  View activeView
           
private  AddToOutbox addToOutbox
           
private  java.util.List<View> allViews
           
private static Controller APP
           
private  java.util.List<ChangeViewAction> changeViewActions
           
private  DBHandler dbh
           
private  DeleteFolderAction deleteFolderAction
           
private  DeleteUserAction deleteUserAction
           
private  EmptyTrashAction emptyTrashAction
           
private  ExitAction exitAction
           
private  ExportFeedListAction exportFeedListAction
           
private  ExportOutboxAction exportOutboxAction
           
private  ImportFromFileAction importFromFileAction
           
private  ImportFromURLAction importFromURLAction
           
private  org.eclipse.swt.widgets.Composite mostRecent
           
private  NewArticleAction newArticleAction
           
private  NewFolderAction newFolderAction
           
private  NewUserAction newUserAction
           
private  RefreshAction refreshAction
           
private  ResetAction resetAction
           
private  SubscribeAction subscribeAction
           
private  SwitchUserAction switchUserAction
           
private  TrashAction trashAction
           
private  UnSubscribeFeedAction unSubscribeAction
           
private  UpdateAllFeeds updateAllFeeds
           
private  UpdateFeedAction updateFeedAction
           
 
Fields inherited from class org.eclipse.jface.window.ApplicationWindow
seperator1
 
Fields inherited from class org.eclipse.jface.window.Window
CANCEL, OK
 
Constructor Summary
Controller(DBHandler dbh)
          Constructs a new Controller with the specified DBHandler.
 
Method Summary
 Folder addFolder(Folder parent, Folder child)
          Adds a new folder.
 void checkUser()
          Checks to make sure that there is a valid user profile.
 boolean close()
          Performs maintenance tasks and closes application.
protected  void configureShell(org.eclipse.swt.widgets.Shell shell)
          Configures the shell of the Controller object.
 void createAndSwitchUser(java.lang.String username)
          Tries to creates a new user profile based on the input username, and switches to that userprofile.
protected  org.eclipse.swt.widgets.Control createContents(org.eclipse.swt.widgets.Composite parent)
          Creates the contents for the Controller, based on the active view.
protected  org.eclipse.jface.action.MenuManager createMenuManager()
          Constructs the Menu for the Controller.
protected  org.eclipse.jface.action.StatusLineManager createStatusLineManager()
          Constructs the StatusLineManager for the Controller.
protected  org.eclipse.jface.action.ToolBarManager createToolBarManager(int style)
          Constructs the toolbar for the Controller.
 boolean deleteFolder(Folder f)
          Deletes specifed folder and all of its contents.
 void deleteUser(java.lang.String username)
          Tries to delete the specified user profile.
 void emptyTrash()
          Permanently empties the trash bin.
 View getActiveView()
          Returns the currently active View.
 java.util.List<Feed> getAllFeeds()
          Gets all feeds.
 java.util.List<java.lang.String> getAllUsers()
          Returns a list of all usernames
static Controller getApp()
          Returns the currently running Instance of Controller.
 Article getArticleRandom()
          Gets a random, unread article.
 java.util.List<Article> getArticles(Feed f)
          Gets the List of Articles associated with a feed.
 java.util.List<Feed> getChildrenFeeds(Folder f)
          Gets the children feeds of a folder.
 java.util.List<Folder> getChildrenFolders(Folder f)
          Gets the children folders of a folder.
 int getNumberOfArticles(java.lang.String constraint)
          Gets the number of articles that are found by a search based on the passed in constraing
 int getNumberOfNewArticles(Feed feed)
          Gets the number of new articles in the selected feed.
 Feed getOutbox()
          Gets the Outbox Feed
 Feed getParent(Article a)
          Gets the Parent Feed of an article.
 Folder getParent(Feed f)
          Gets the Parent Folder of a Feed.
 Folder getParent(Folder f)
          Gets the Parent Folder of a Folder.
 java.util.List<java.lang.Object> getRoot()
          Returns a list of top-level Objects.
 org.eclipse.jface.action.StatusLineManager getStatusLine()
          Returns the StatusLineManager of the Controller window.
 Folder getSubscribedFeeds()
          Gets the Subscribed feeds folder
 Feed getTrash()
          Gets the Trash Feed
 boolean isUser(java.lang.String username)
          Checks to see if there is a user profile for the specified user name.
static void main(java.lang.String[] args)
          The Application Entry Point
 Article markRead(Article a)
          Marks the specified article as read.
 Article markUnread(Article a)
          Marks the specified article as new.
 boolean move(Feed source, Folder destination)
          Moves Feed into destination folder.
 boolean move(Folder source, Folder destination)
          Moves Folder into destination folder.
 void moveToOutbox(Article source)
          Copies the specified article to the outbox.
 java.util.List<Article> orderedSearch(java.lang.String string)
          Performs a search based on the specified string and returns a list of Articles ordered by their date.
 void renameFeed(Feed f, java.lang.String newName)
          Tries to rename the specified feed.
 void reset()
          Resets the underlying database.
 void run()
          Runs the Application
 java.util.List<Article> searchArticles(boolean byAuthor, boolean byTitle, boolean byContent, Feed feed, java.lang.String constraint)
          Searches for the articles based on the specified input values.
 java.util.List<Article> searchArticles(boolean byAuthor, boolean byTitle, boolean byContent, java.lang.String constraint)
          Searches for the articles based on the specified input values.
 void setActiveView(View newView)
          Sets the active view to the specified view.
 void setDelete(Article a)
          Deletes the specified article.
 void setFeedUpdateInterval(Feed f, int i)
          Sets a feeds update interval.
 Article setTrash(Article a)
          Puts the specified article in the trash bin.
 Article setUnTrash(Article a)
          Takes the specified article in the trash bin and restores it to its original location.
private  void setupViews()
          Sets up the views.
 Feed subscribe(java.lang.String url)
          Subscribes to the feed at the specified url.
 Feed subscribe(java.lang.String url, Folder destination)
          Subscribes to a new feed, and places that feed into the specified directory.
 void switchUser(java.lang.String username)
          Tries to switch to the specified user profile.
 boolean unSubscribe(Feed f)
          Unsubscribes from specified feed.
 Feed updateFeed(Feed f)
          Refreshes the specified feed by comparing to the current rss feed at the feed object's url.
 void updateFeeds()
          Updates all feeds that are scheduled to be updated based on their update interval.
 
Methods inherited from class org.eclipse.jface.window.ApplicationWindow
addCoolBar, addMenuBar, addStatusLine, addToolBar, canHandleShellCloseEvent, coolBarChildrenExist, createCoolBarControl, createCoolBarManager, createStatusLine, createToolBarControl, createTrimWidgets, getCoolBarControl, getCoolBarManager, getFont, getLayout, getMenuBarManager, getSeperator1, getStatusLineManager, getSymbolicFontName, getToolBarControl, getToolBarManager, run, setStatus, showTopSeperator, toolBarChildrenExist
 
Methods inherited from class org.eclipse.jface.window.Window
constrainShellSize, create, createShell, getConstrainedShellBounds, getContents, getDefaultImage, getDefaultImages, getDefaultOrientation, getInitialLocation, getInitialSize, getParentShell, getReturnCode, getShell, getShellListener, getShellStyle, getWindowManager, handleFontChange, handleShellCloseEvent, initializeBounds, open, setBlockOnOpen, setDefaultImage, setDefaultImages, setDefaultModalParent, setDefaultOrientation, setExceptionHandler, setParentShell, setReturnCode, setShellStyle, setWindowManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APP

private static Controller APP

dbh

private DBHandler dbh

activeView

private View activeView

allViews

private java.util.List<View> allViews

changeViewActions

private java.util.List<ChangeViewAction> changeViewActions

mostRecent

private org.eclipse.swt.widgets.Composite mostRecent

subscribeAction

private SubscribeAction subscribeAction

unSubscribeAction

private UnSubscribeFeedAction unSubscribeAction

exitAction

private ExitAction exitAction

updateFeedAction

private UpdateFeedAction updateFeedAction

updateAllFeeds

private UpdateAllFeeds updateAllFeeds

addToOutbox

private AddToOutbox addToOutbox

trashAction

private TrashAction trashAction

deleteFolderAction

private DeleteFolderAction deleteFolderAction

emptyTrashAction

private EmptyTrashAction emptyTrashAction

importFromFileAction

private ImportFromFileAction importFromFileAction

importFromURLAction

private ImportFromURLAction importFromURLAction

newFolderAction

private NewFolderAction newFolderAction

refreshAction

private RefreshAction refreshAction

exportOutboxAction

private ExportOutboxAction exportOutboxAction

newArticleAction

private NewArticleAction newArticleAction

newUserAction

private NewUserAction newUserAction

switchUserAction

private SwitchUserAction switchUserAction

deleteUserAction

private DeleteUserAction deleteUserAction

aboutAction

private AboutAction aboutAction

resetAction

private ResetAction resetAction

exportFeedListAction

private ExportFeedListAction exportFeedListAction
Constructor Detail

Controller

public Controller(DBHandler dbh)
Constructs a new Controller with the specified DBHandler.

Parameters:
dbh - DBHandler
Method Detail

setupViews

private void setupViews()
Sets up the views. If a new view is to be added, this is where it would go.


createMenuManager

protected org.eclipse.jface.action.MenuManager createMenuManager()
Constructs the Menu for the Controller.

Overrides:
createMenuManager in class org.eclipse.jface.window.ApplicationWindow
Returns:
MenuManager

createToolBarManager

protected org.eclipse.jface.action.ToolBarManager createToolBarManager(int style)
Constructs the toolbar for the Controller.

Overrides:
createToolBarManager in class org.eclipse.jface.window.ApplicationWindow
Returns:
ToolBarManager

createStatusLineManager

protected org.eclipse.jface.action.StatusLineManager createStatusLineManager()
Constructs the StatusLineManager for the Controller. Invoked by the 'addStatusLine()' method call during construction.

Overrides:
createStatusLineManager in class org.eclipse.jface.window.ApplicationWindow
Returns:
StatusLineManager

setActiveView

public void setActiveView(View newView)
Sets the active view to the specified view. This is invoked by ChangeViewActions to switch to a particular view

Parameters:
newView - View to be displayed

getActiveView

public View getActiveView()
Returns the currently active View.

Returns:
View that is currently displayed.

getApp

public static Controller getApp()
Returns the currently running Instance of Controller.

Returns:
The displayed instance of Controller.

createContents

protected org.eclipse.swt.widgets.Control createContents(org.eclipse.swt.widgets.Composite parent)
Creates the contents for the Controller, based on the active view.

Overrides:
createContents in class org.eclipse.jface.window.Window
Returns:
Control

configureShell

protected void configureShell(org.eclipse.swt.widgets.Shell shell)
Configures the shell of the Controller object.

Overrides:
configureShell in class org.eclipse.jface.window.ApplicationWindow

run

public void run()
Runs the Application


close

public boolean close()
Performs maintenance tasks and closes application.

Overrides:
close in class org.eclipse.jface.window.ApplicationWindow
Returns:
boolean

main

public static void main(java.lang.String[] args)
The Application Entry Point

Parameters:
args - Command Line Arguments

updateFeeds

public void updateFeeds()
Updates all feeds that are scheduled to be updated based on their update interval.


setFeedUpdateInterval

public void setFeedUpdateInterval(Feed f,
                                  int i)
                           throws ControlException
Sets a feeds update interval. i must be between 1 and 1440 (the number of minutes in the day). If not, this method throws and exception.

Parameters:
f - Feed who's interval is to be changed
i - Integer representing the interval of minutes between updates
Throws:
ControlException - If there is an internal error or if the interval passed in is invalid.

getParent

public Folder getParent(Folder f)
                 throws ControlException
Gets the Parent Folder of a Folder.

Parameters:
f - Folder to get parent of.
Returns:
Folder that is parent of f.
Throws:
ControlException - if the Feed has no parent.

getParent

public Folder getParent(Feed f)
                 throws ControlException
Gets the Parent Folder of a Feed.

Parameters:
f - Feed to get parent of.
Returns:
Folder that is parent of f.
Throws:
ControlException - if the Feed has no parent.

getParent

public Feed getParent(Article a)
               throws ControlException
Gets the Parent Feed of an article.

Parameters:
f - Feed to get parent of.
Returns:
Folder that is parent of f.
Throws:
ControlException - if the Feed has no parent.

getRoot

public java.util.List<java.lang.Object> getRoot()
                                         throws ControlException
Returns a list of top-level Objects. This should return a list of a folder and two feeds, representign the SubscribedFeeds folder, outbox feed, and trash bin, respectively

Returns:
List of top level folders.
Throws:
ControlException - if Internal database has been corrupted.

getChildrenFolders

public java.util.List<Folder> getChildrenFolders(Folder f)
                                          throws ControlException
Gets the children folders of a folder.

Parameters:
f - Folder parent
Returns:
List of folders contained by the parent folder.
Throws:
ControlException - if there is a problem with the internal data structures or if the argument folder is not represented in the internal data structures.

getChildrenFeeds

public java.util.List<Feed> getChildrenFeeds(Folder f)
                                      throws ControlException
Gets the children feeds of a folder.

Parameters:
f - Folder parent
Returns:
List of feeds contained by the parent folder.
Throws:
ControlException - if there is a problem with the internal data structures or if the argument feed is not represented in the internal data structures.

getArticleRandom

public Article getArticleRandom()
                         throws ControlException
Gets a random, unread article. Only active, non-deleted articles are returned.

Returns:
An article
Throws:
ControlException - If there is a problem getting an article from the database.

getArticles

public java.util.List<Article> getArticles(Feed f)
                                    throws ControlException
Gets the List of Articles associated with a feed.

Parameters:
f - Feed that contains articles
Returns:
List of Articles in the Feed.
Throws:
ControlException - If the feed is not already represented in the internal data structures or if there a problem with the internal data structures.

getAllFeeds

public java.util.List<Feed> getAllFeeds()
                                 throws ControlException
Gets all feeds.

Returns:
List of all feeds.
Throws:
ControlException - if there is an internal error.

getSubscribedFeeds

public Folder getSubscribedFeeds()
                          throws ControlException
Gets the Subscribed feeds folder

Returns:
Folder SubscribedFeeds Folder
Throws:
ControlException - if there is a problem with the internal data structures.

getTrash

public Feed getTrash()
              throws ControlException
Gets the Trash Feed

Returns:
Feed that is the Trash bin
Throws:
ControlException - if there is a problem with the internal data structures.

getOutbox

public Feed getOutbox()
               throws ControlException
Gets the Outbox Feed

Returns:
Feed Outbox feed
Throws:
ControlException - if there is a problem with the internal data structures.

emptyTrash

public void emptyTrash()
                throws ControlException
Permanently empties the trash bin.

Throws:
ControlException - if there is a problem with the internal data structures.

markRead

public Article markRead(Article a)
                 throws ControlException
Marks the specified article as read.

Parameters:
a - Article to be marked as read
Returns:
Article that represents the input article but has been marked as read.
Throws:
ControlException - If the Article is not already represented in the internal data structures or if there a problem with the internal data structures.

markUnread

public Article markUnread(Article a)
                   throws ControlException
Marks the specified article as new.

Parameters:
a - Article
Returns:
Article that represents the input article but has been marked as new.
Throws:
ControlException - If the Article is not already represented in the internal data structures or if there a problem with the internal data structures.

setTrash

public Article setTrash(Article a)
                 throws ControlException
Puts the specified article in the trash bin.

Parameters:
a - Article to be put in the trash
Returns:
Article that represents the input article but has its trash status set appropriately.
Throws:
ControlException - If the Article is not already represented in the internal data structures or if there a problem with the internal data structures.

setUnTrash

public Article setUnTrash(Article a)
                   throws ControlException
Takes the specified article in the trash bin and restores it to its original location.

Parameters:
a - Article to be restored from the trash
Returns:
Article that represents the input article but has its trash status set appropriately.
Throws:
ControlException - If the Article is not already represented in the internal data structures or if there a problem with the internal data structures.

setDelete

public void setDelete(Article a)
               throws ControlException
Deletes the specified article.

Parameters:
a - Article to be deleted
Throws:
ControlException - if there is an internal error.

subscribe

public Feed subscribe(java.lang.String url)
               throws ControlException
Subscribes to the feed at the specified url.

Parameters:
url - of rss feed
Returns:
Feed object
Throws:
ControlException - If url is malformed, there is a problem with the internet connection, or if there is a problem with the internal data structures.

subscribe

public Feed subscribe(java.lang.String url,
                      Folder destination)
               throws ControlException
Subscribes to a new feed, and places that feed into the specified directory.

Parameters:
url - String url of rss feed.
destination - Folder where feed should be placed
Returns:
Feed object
Throws:
ControlException - If url is malformed, there is a problem with the internet connection, or if there is a problem with the internal data structures.

unSubscribe

public boolean unSubscribe(Feed f)
                    throws ControlException
Unsubscribes from specified feed.

Parameters:
f - Feed to be unsubscribed from.
Returns:
True
Throws:
ControlException - if Feed specified is not represented in the internal data structures (i.e. it is not subscribed to), or if the feed cannot be unsubscribed from. For instance, if the feed is the outbox feed or trash bin.

deleteFolder

public boolean deleteFolder(Folder f)
                     throws ControlException
Deletes specifed folder and all of its contents.

Parameters:
f - Folder to be deleted
Returns:
True
Throws:
ControlException - If folder is not represented in the internal data structures, or if the folder is the subscribedFeeds folder.

updateFeed

public Feed updateFeed(Feed f)
                throws ControlException
Refreshes the specified feed by comparing to the current rss feed at the feed object's url.

Parameters:
f - Feed to be updated
Returns:
Feed object that has been updated appropriately.
Throws:
ControlException - If there is an error updating the feed, or if the feed is not already represented in the internal data structures.

addFolder

public Folder addFolder(Folder parent,
                        Folder child)
                 throws ControlException
Adds a new folder. A folder cannot be added to a parent folder that has a child the same name.

Parameters:
parent - Folder that will contain the added folder
child - Folder that is to be added
Returns:
Folder that represents the newly added folder
Throws:
ControlException - if the folder couldn't be added.

getNumberOfNewArticles

public int getNumberOfNewArticles(Feed feed)
                           throws ControlException
Gets the number of new articles in the selected feed.

Parameters:
feed - Selected feed
Returns:
int Count of new articles in the selected feed.
Throws:
ControlException - if there is an internal error or the feed is not currently subscribed to.

getNumberOfArticles

public int getNumberOfArticles(java.lang.String constraint)
                        throws ControlException
Gets the number of articles that are found by a search based on the passed in constraing

Parameters:
constraint - String constraint
Returns:
int Count of articles that are returned by a search
Throws:
ControlException - If there is an internal error

move

public boolean move(Folder source,
                    Folder destination)
             throws ControlException
Moves Folder into destination folder.

Parameters:
source - Folder to be moved
destination - Folder that source folder will be moved into.
Returns:
true
Throws:
ControlException - If either folder argument is not represented in the internal data structures.

move

public boolean move(Feed source,
                    Folder destination)
             throws ControlException
Moves Feed into destination folder.

Parameters:
source - Feed to be moved
destination - Folder that source Feed will be moved into.
Returns:
true
Throws:
ControlException - If either argument is not represented in the internal data structures.

moveToOutbox

public void moveToOutbox(Article source)
                  throws ControlException
Copies the specified article to the outbox.

Parameters:
source - Article to be moved
Throws:
ControlException - if there is an internal error, or if the article is not already represented in the internal data structures.

getStatusLine

public org.eclipse.jface.action.StatusLineManager getStatusLine()
Returns the StatusLineManager of the Controller window. This can be used by actions to utilize the status line as a progress monitor.

Returns:
StatusLineManager

searchArticles

public java.util.List<Article> searchArticles(boolean byAuthor,
                                              boolean byTitle,
                                              boolean byContent,
                                              java.lang.String constraint)
Searches for the articles based on the specified input values. Searches all articles from all feeds. Searches for the string passed in as constraint in all fields who's corresponding input is true. For example: searchArticles(true,false,true, "Jim bob") finds all articles that contain the string "Jim bob" in either their title or summary.

Parameters:
byAuthor -
byTitle -
byContent -
constraint -
Returns:
List
articles that match constraints.

searchArticles

public java.util.List<Article> searchArticles(boolean byAuthor,
                                              boolean byTitle,
                                              boolean byContent,
                                              Feed feed,
                                              java.lang.String constraint)
Searches for the articles based on the specified input values. Searches only articles in the selected feed. Searches for the string passed in as constraint in all fields who's corresponding input is true. For example: searchArticles(true,false,true, myFeed, "Jim bob") finds all articles in myFeed that contain the string "Jim bob" in either their title or summary.

Parameters:
byAuthor -
byTitle -
byContent -
feed -
constraint -
Returns:
List
articles that match constraints.

checkUser

public void checkUser()
Checks to make sure that there is a valid user profile. If there is no valid user profile then prompts the user to create one. Note that this method does nothing to guarantee that the user actually does create a new user profile.


createAndSwitchUser

public void createAndSwitchUser(java.lang.String username)
Tries to creates a new user profile based on the input username, and switches to that userprofile. There are no guarantees that this method will succeed.

Parameters:
username - String Username

isUser

public boolean isUser(java.lang.String username)
Checks to see if there is a user profile for the specified user name.

Parameters:
username - String Username
Returns:
true if there is a user profile with that username, false otherwise.

switchUser

public void switchUser(java.lang.String username)
Tries to switch to the specified user profile. If there is no such profile, then nothing happens.

Parameters:
username - String username

deleteUser

public void deleteUser(java.lang.String username)
                throws ControlException
Tries to delete the specified user profile. If there is no user profile with that username, then this method merely returns. If the username specifies the current user, then this method throws a ControlException

Parameters:
username - String username
Throws:
ControlException - If username is the current user

getAllUsers

public java.util.List<java.lang.String> getAllUsers()
Returns a list of all usernames

Returns:
List of usernames

orderedSearch

public java.util.List<Article> orderedSearch(java.lang.String string)
Performs a search based on the specified string and returns a list of Articles ordered by their date.

Parameters:
string - String constraint
Returns:
List of Articles ordered by date

renameFeed

public void renameFeed(Feed f,
                       java.lang.String newName)
Tries to rename the specified feed.

Parameters:
f - Feed to be renamed
newName - String new name

reset

public void reset()
           throws ControlException
Resets the underlying database. This will delete all user data and thus is only included as a way to reset the software to an initial state and recover if the database gets corrupted.

Throws:
ControlException - If there is a internal error. If that happens, there is a serious problem.