001: /*
002: * Copyright (c) 2004-2006, Jean-François Brazeau. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * 2. Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: *
014: * 3. The name of the author may not be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
018: * IMPLIEDWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
019: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
020: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
021: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
022: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
023: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
024: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
025: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
026: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: */
028: package jfb.tools.activitymgr.ui;
029:
030: import jfb.tools.activitymgr.core.ModelMgr;
031: import jfb.tools.activitymgr.ui.DatabaseUI.IDbStatusListener;
032: import jfb.tools.activitymgr.ui.images.ImagesDatas;
033: import jfb.tools.activitymgr.ui.util.CfgMgr;
034: import jfb.tools.activitymgr.ui.util.SafeRunner;
035:
036: import org.apache.log4j.Logger;
037: import org.apache.log4j.PropertyConfigurator;
038: import org.eclipse.swt.SWT;
039: import org.eclipse.swt.events.ShellAdapter;
040: import org.eclipse.swt.events.ShellEvent;
041: import org.eclipse.swt.graphics.Image;
042: import org.eclipse.swt.graphics.Rectangle;
043: import org.eclipse.swt.layout.FillLayout;
044: import org.eclipse.swt.layout.GridData;
045: import org.eclipse.swt.layout.GridLayout;
046: import org.eclipse.swt.widgets.Display;
047: import org.eclipse.swt.widgets.Label;
048: import org.eclipse.swt.widgets.Shell;
049: import org.eclipse.swt.widgets.TabFolder;
050: import org.eclipse.swt.widgets.TabItem;
051:
052: /**
053: * Classe principale de l'application des gestion des l'activité.
054: */
055: public class Main {
056:
057: /** Logger */
058: private static Logger log = Logger.getLogger(Main.class);
059:
060: /** Onglets */
061: private static TabItem databaseTab;
062: private static TabItem durationsTab;
063: private static TabItem collaboratorsTab;
064: private static TabItem tasksTab;
065: private static TabItem contributionsTab;
066: private static TabItem aboutTab;
067:
068: /** Contenu des onglets */
069: private static DatabaseUI databaseUI;
070: private static DurationsUI durationsUI;
071: private static CollaboratorsUI collaboratorsUI;
072: private static TasksUI tasksUI;
073: private static ContributionsUI contributionsUI;
074:
075: public static void main(String[] args) {
076: try {
077: // Initialisation des logs et chargement de la config
078: PropertyConfigurator.configure("cfg/log4j.properties");
079: CfgMgr.load();
080: Display display = new Display();
081:
082: // Splash screen
083: Shell splash = new Shell(display, SWT.ON_TOP);
084: splash.setLayout(new FillLayout());
085: Label splashLabel = new Label(splash, SWT.NONE);
086: Image splashImage = new Image(splash.getDisplay(),
087: ImagesDatas.APPLICATION_LOGO);
088: splashLabel.setImage(splashImage);
089: splash.pack();
090: Rectangle splashRect = splash.getBounds();
091: Rectangle displayRect = display.getBounds();
092: int x = (displayRect.width - splashRect.width) / 2;
093: int y = (displayRect.height - splashRect.height) / 2;
094: splash.setLocation(x, y);
095: splash.open();
096:
097: // Ouverture de la fenêtre
098: final Shell shell = new Shell(display);
099: shell.setSize(910, 550);
100: shell.setText("ActivityManager V0.3");
101: shell.setLayout(new GridLayout(1, false));
102: shell.setImage(new Image(display,
103: ImagesDatas.APPLICATION_ICON));
104: shell.addShellListener(new ShellAdapter() {
105: public void shellClosed(ShellEvent e) {
106: new SafeRunner() {
107: protected Object runUnsafe() throws Exception {
108: ModelMgr.closeDatabaseAccess();
109: return null;
110: }
111: }.run(shell);
112: }
113: });
114:
115: // Création du groupe d'onglets
116: final TabFolder tabFolder = new TabFolder(shell, SWT.TOP);
117: tabFolder.setLayout(new FillLayout(SWT.VERTICAL));
118: tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
119: true, true));
120:
121: // Création de l'onglet de paramétrage de l'accès à la base de données
122: databaseTab = new TabItem(tabFolder, SWT.NONE);
123: databaseTab.setText("Database");
124: databaseUI = new DatabaseUI(databaseTab);
125:
126: // Création de l'onglet de gestion des durées
127: durationsTab = new TabItem(tabFolder, SWT.NONE);
128: durationsTab.setText("Durations");
129: durationsUI = new DurationsUI(durationsTab);
130:
131: // Création de l'onglet de gestion des collaborateurs
132: collaboratorsTab = new TabItem(tabFolder, SWT.NONE);
133: collaboratorsTab.setText("Collaborators");
134: collaboratorsUI = new CollaboratorsUI(collaboratorsTab);
135:
136: // Création de l'onglet de gestion des taches
137: tasksTab = new TabItem(tabFolder, SWT.NONE);
138: tasksTab.setText("Tasks");
139: tasksUI = new TasksUI(tasksTab);
140:
141: // Création de l'onglet de gestion des contributions
142: contributionsTab = new TabItem(tabFolder, SWT.NONE);
143: contributionsTab.setText("Contributions");
144: contributionsUI = new ContributionsUI(contributionsTab);
145:
146: // Création de l'onglet contenant les informations générales
147: aboutTab = new TabItem(tabFolder, SWT.NONE);
148: aboutTab.setText("About");
149: new AboutUI(aboutTab);
150:
151: // Enregistrement des listeners
152: databaseUI.addDbStatusListener(durationsUI);
153: databaseUI.addDbStatusListener(collaboratorsUI);
154: databaseUI.addDbStatusListener(tasksUI);
155: databaseUI.addDbStatusListener(contributionsUI);
156: durationsUI.addDurationListener(contributionsUI);
157: collaboratorsUI.addCollaboratorListener(contributionsUI);
158: tasksUI.addTaskListener(contributionsUI);
159:
160: // Barre de statut
161: final Label statusBar = new Label(shell, SWT.NONE);
162: statusBar.setLayoutData(new GridData(SWT.RIGHT, SWT.NONE,
163: false, false));
164: statusBar.setAlignment(SWT.RIGHT);
165: statusBar.setText("Not connected");
166: databaseUI.addDbStatusListener(new IDbStatusListener() {
167: public void databaseOpened() {
168: statusBar.setText("Connected");
169: }
170:
171: public void databaseClosed() {
172: statusBar.setText("Not connected");
173: }
174: });
175:
176: // Ouverture de la fenêtre
177: shell.open();
178: shell.setEnabled(false);
179:
180: // Initialisation des attributs de connexion par défaut
181: databaseUI.initUI();
182:
183: // Fermeture du splash
184: splash.dispose();
185: splashLabel.dispose();
186: splashImage.dispose();
187: shell.setEnabled(true);
188: log.info("Application started");
189:
190: // Exécution jusqu'à l'arrêt
191: while (!shell.isDisposed()) {
192: if (!display.readAndDispatch())
193: display.sleep();
194: }
195: } catch (Throwable t) {
196: t.printStackTrace();
197: }
198: }
199:
200: }
|