Ejemplo n.º 1
0
 /** Create the Instance of the main frame */
 private void makeMainFrame() {
   mainFrame.init(pluginFramework.getHostBundleContext());
   // When the user ask to close OrbisGis it call
   // the shutdown method here,
   // Link the Swing Events with the MainFrame event
   // Thanks to EventHandler we don't have to build a listener class
   mainFrame.addWindowListener(
       EventHandler.create(
           WindowListener.class, // The listener class
           this, // The event target object
           "onMainWindowClosing", // The event target method to call
           null, // the event parameter to pass(none)
           "windowClosing")); // The listener method to use
 }
Ejemplo n.º 2
0
 /** Add new menu to the OrbisGIS core */
 private void addCoreMenu() {
   DefaultAction def =
       new DefaultAction(
           MainFrameAction.MENU_SAVE,
           I18N.tr("&Save"),
           OrbisGISIcon.getIcon("save"),
           EventHandler.create(ActionListener.class, this, "onMenuSaveApplication"));
   def.setParent(MainFrameAction.MENU_FILE).setBefore(MainFrameAction.MENU_EXIT);
   mainFrame.addMenu(def);
   def.setToolTipText(I18N.tr("Save the workspace"));
   JButton saveBt = new CustomButton(def);
   saveBt.setHideActionText(true);
   mainFrame.addToolBarComponent(saveBt, "align left");
 }
Ejemplo n.º 3
0
 /**
  * Stops this application, closes the {@link MainFrame} and saves all properties. This method is
  * called through the MainFrame.MAIN_FRAME_CLOSING event listener.
  */
 public boolean shutdown(boolean stopVM) {
   if (!isShutdownVetoed()) {
     try {
       mainFrame.setVisible(false); // Hide the main panel
       mainContext.saveStatus(); // Save the services status
       // Save dialogs status
       saveSIFState();
       // Save layout
       dockManager.saveLayout();
       this.dispose();
     } finally {
       // While public Plugins are not implemented do not close the VM in finally clause
       if (stopVM) {
         SwingUtilities.invokeLater(
             new Runnable() {
               /**
                * If an error occur while unload resources, java machine may continue to run. In
                * this case, the following command would terminate the application.
                */
               public void run() {
                 System.exit(0);
               }
             });
       }
     }
     return true;
   } else {
     return false;
   }
 }
Ejemplo n.º 4
0
 /**
  * Core constructor, init Model instances
  *
  * @param debugMode Show additional information for debugging purposes
  * @note Call startup() to init Swing
  */
 public Core(CoreWorkspaceImpl coreWorkspace, boolean debugMode, LoadingFrame splashScreen)
     throws InvocationTargetException, InterruptedException {
   ProgressMonitor parentProgress = splashScreen.getProgressMonitor();
   ProgressMonitor progressInfo = parentProgress.startTask(I18N.tr("Loading Workspace.."), 100);
   MainContext.initConsoleLogger(debugMode);
   // Declare empty main frame
   mainFrame = new MainFrame();
   // Set the main frame position and size
   mainFrame.setSize(MAIN_VIEW_SIZE);
   // Try to set the frame at the center of the default screen
   try {
     GraphicsDevice device =
         GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
     Rectangle screenBounds = device.getDefaultConfiguration().getBounds();
     mainFrame.setLocation(
         screenBounds.x + screenBounds.width / 2 - MAIN_VIEW_SIZE.width / 2,
         screenBounds.y + screenBounds.height / 2 - MAIN_VIEW_SIZE.height / 2);
   } catch (Throwable ex) {
     LOGGER.error(ex.getLocalizedMessage(), ex);
   }
   UIFactory.setMainFrame(mainFrame);
   initMainContext(debugMode, coreWorkspace, splashScreen);
   progressInfo.progressTo(10);
   this.viewWorkspace = new ViewWorkspace(this.mainContext.getCoreWorkspace());
   Services.registerService(
       ViewWorkspace.class, I18N.tr("Contains view folders path"), viewWorkspace);
   progressInfo.setTaskName(I18N.tr("Register GUI Sql functions.."));
   addSQLFunctions();
   progressInfo.progressTo(11);
   // Load plugin host
   progressInfo.setTaskName(I18N.tr("Load the plugin framework.."));
   startPluginHost();
   progressInfo.progressTo(18);
   progressInfo.setTaskName(I18N.tr("Connecting to the database.."));
   // Init database
   try {
     mainContext.initDataBase(
         coreWorkspace.getDataBaseUser(), coreWorkspace.getDataBasePassword());
   } catch (SQLException ex) {
     throw new RuntimeException(ex.getLocalizedMessage(), ex);
   }
   initSIF();
   progressInfo.progressTo(20);
 }
Ejemplo n.º 5
0
 /**
  * Starts the application. This method creates the {@link MainFrame}, and manage the Look And Feel
  * declarations
  */
 public void startup(ProgressMonitor progress) throws Exception {
   // Show the application when Swing will be ready
   try {
     initialize(progress);
   } catch (Exception ex) {
     mainFrame.dispose();
     throw ex;
   }
   SwingUtilities.invokeLater(new ShowSwingApplication(progress, mainFrame));
 }
Ejemplo n.º 6
0
 /** Change the state of the main frame in the swing thread */
 @Override
 public void run() {
   try {
     mainFrame.setVisible(true);
   } catch (Exception ex) {
     LOGGER.error(ex.getLocalizedMessage(), ex);
     dispose();
   } finally {
     progress.setCancelled(true);
   }
 }
Ejemplo n.º 7
0
  private void initialize(ProgressMonitor parentProgress) {
    ProgressMonitor progress = parentProgress.startTask(I18N.tr("Loading the main window"), 100);
    makeMainFrame();
    progress.endTask();
    progress.setTaskName(I18N.tr("Loading docking system and frames"));
    // Initiate the docking management system
    DockingManagerImpl dockManagerImpl = new DockingManagerImpl(mainFrame);
    dockManager = dockManagerImpl;
    mainFrame.setDockingManager(dockManager);
    // Initiate the docking panel tracker
    singleFrameTracker =
        new DockingPanelTracker(pluginFramework.getHostBundleContext(), dockManager);
    singleFrameTracker.open();
    toolBarTracker =
        new MenuItemServiceTracker<MainWindow, ToolBarAction>(
            pluginFramework.getHostBundleContext(),
            ToolBarAction.class,
            dockManagerImpl,
            mainFrame);
    toolBarTracker.open();
    progress.endTask();

    // Load the log panels
    makeLoggingPanels();
    progress.endTask();

    // Load the editor factories manager
    makeEditorManager(dockManager);
    progress.endTask();

    // Load the GeoCatalog
    makeGeoCatalogPanel();
    progress.endTask();

    // Load Built-ins Editors
    loadEditorFactories();
    progress.endTask();

    progress.setTaskName(I18N.tr("Restore the former layout.."));
    // Load the docking layout and editors opened in last OrbisGis instance
    File savedDockingLayout = new File(viewWorkspace.getDockingLayoutPath());
    if (!savedDockingLayout.exists()) {
      // Copy the default docking layout
      // First OrbisGIS start
      copyDefaultDockingLayout(savedDockingLayout);
    }
    dockManager.setDockingLayoutPersistanceFilePath(viewWorkspace.getDockingLayoutPath());
    progress.endTask();
    addCoreMenu();
  }
Ejemplo n.º 8
0
  /** Free all resources allocated by this object */
  public void dispose() {
    // Close all running jobs
    final AppContext appContext = AppContext.getAppContext();
    ExecutorService executorService = (ExecutorService) appContext.get(SwingWorker.class);
    if (executorService != null) {
      executorService.shutdown();
    }

    // Free UI resources
    if (editors != null) {
      editors.dispose();
    }
    if (geoCatalog != null) {
      geoCatalog.dispose();
    }
    if (mainFrame != null) {
      mainFrame.dispose();
    }
    if (singleFrameTracker != null) {
      singleFrameTracker.close();
    }
    if (editorFactoryTracker != null) {
      editorFactoryTracker.close();
    }
    if (editorTracker != null) {
      editorTracker.close();
    }
    if (toolBarTracker != null) {
      toolBarTracker.close();
    }
    dockManager.dispose();
    loggerCollection.dispose();

    // Free libraries resources
    mainContext.dispose();

    UIFactory.setMainFrame(null);
  }
Ejemplo n.º 9
0
 /** Find the workspace folder or addDockingPanel a dialog to select one */
 private void initMainContext(
     boolean debugMode, CoreWorkspaceImpl coreWorkspace, LoadingFrame splashScreen)
     throws InterruptedException, InvocationTargetException, RuntimeException {
   String workspaceFolder = coreWorkspace.getWorkspaceFolder();
   if (workspaceFolder == null) {
     File defaultWorkspace = coreWorkspace.readDefaultWorkspacePath();
     if (defaultWorkspace == null || !ViewWorkspace.isWorkspaceValid(defaultWorkspace)) {
       try {
         PromptUserForSelectingWorkspace dial =
             new PromptUserForSelectingWorkspace(coreWorkspace, splashScreen);
         SwingUtilities.invokeAndWait(dial);
         if (!dial.isOk()) {
           throw new InterruptedException("Canceled by user.");
         }
       } catch (InvocationTargetException ex) {
         mainFrame.dispose();
         throw ex;
       }
     } else {
       coreWorkspace.setWorkspaceFolder(defaultWorkspace.getAbsolutePath());
     }
   }
   this.mainContext = new MainContext(debugMode, coreWorkspace, true);
 }