/**
 * This program and the accompanying materials
 * are made available under the terms of the License
 * which accompanies this distribution in the file LICENSE.txt
 */
package com.archimatetool.editor;

import java.util.Calendar;
import java.util.Date;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

import com.archimatetool.editor.actions.ArchimateEditorActionBarAdvisor;
import com.archimatetool.editor.preferences.IPreferenceConstants;
import com.archimatetool.editor.preferences.Preferences;



/**
 * Workbench Window Advisor
 * 
 * @author Phillip Beauvoir
 */
public class ArchimateEditorWorkbenchWindowAdvisor
extends WorkbenchWindowAdvisor {
    
    /**
     * Constructor
     * @param configurer
     */
    public ArchimateEditorWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        super(configurer);
        
        // Status Line
        boolean doShowStatusLine = Preferences.STORE.getBoolean(IPreferenceConstants.SHOW_STATUS_LINE);
        configurer.setShowStatusLine(doShowStatusLine);
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#createActionBarAdvisor(org.eclipse.ui.application.IActionBarConfigurer)
     */
    @Override
    public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
        return new ArchimateEditorActionBarAdvisor(configurer);
    }
    
    String expiryDate = "23 October 2014";
    int year = 2014, month = 9, day = 23;
    
    @Override
    public void preWindowOpen() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, day);
        if(new Date().after(calendar.getTime())) {
            MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                    "Archi 3.0 Beta", "This Beta version expired on " + expiryDate + ".\nPlease download the latest version.");
            System.exit(0);
        }
    }
    
    @Override
    public void postWindowOpen() {
        // Application specific launcher actions
        final IPlatformLauncher launcher = ArchimateEditorPlugin.INSTANCE.getPlatformLauncher();
        if(launcher != null) {
            launcher.postWindowOpen(getWindowConfigurer().getWindow());
        }
        
        Display.getCurrent().asyncExec(new Runnable() {
            public void run() {
                MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                        "Archi 3.0 Beta", "This Beta version expires on " + expiryDate + ".");
            }
        });
    }
}

@@ -210,152 +210,8 @@
 %0D%0A%0D%0A
-import java.util.Calendar;%0D%0Aimport java.util.Date;%0D%0A%0D%0Aimport org.eclipse.jface.dialogs.MessageDialog;%0D%0Aimport org.eclipse.swt.widgets.Display;%0D%0A
 impo
@@ -255,24 +255,24 @@
 arAdvisor;%0D%0A
+
 import org.e
@@ -1202,174 +1202,8 @@
 %0D%0A%0D%0A
-    /* (non-Javadoc)%0D%0A     * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#createActionBarAdvisor(org.eclipse.ui.application.IActionBarConfigurer)%0D%0A     */%0D%0A
     
@@ -1382,561 +1382,8 @@
   %0D%0A
-    String expiryDate = %2223 October 2014%22;%0D%0A    int year = 2014, month = 9, day = 23;%0D%0A    %0D%0A    @Override%0D%0A    public void preWindowOpen() %7B%0D%0A        Calendar calendar = Calendar.getInstance();%0D%0A        calendar.set(year, month, day);%0D%0A        if(new Date().after(calendar.getTime())) %7B%0D%0A            MessageDialog.openInformation(Display.getCurrent().getActiveShell(),%0D%0A                    %22Archi 3.0 Beta%22, %22This Beta version expired on %22 + expiryDate + %22.%5CnPlease download the latest version.%22);%0D%0A            System.exit(0);%0D%0A        %7D%0D%0A    %7D%0D%0A    %0D%0A
     
@@ -1491,14 +1491,8 @@
     
-final 
 IPla
@@ -1672,24 +1672,24 @@
 Window());%0D%0A
+
         %7D%0D%0A 
@@ -1691,318 +1691,8 @@
  %7D%0D%0A
-        %0D%0A        Display.getCurrent().asyncExec(new Runnable() %7B%0D%0A            public void run() %7B%0D%0A                MessageDialog.openInformation(Display.getCurrent().getActiveShell(),%0D%0A                        %22Archi 3.0 Beta%22, %22This Beta version expires on %22 + expiryDate + %22.%22);%0D%0A            %7D%0D%0A        %7D);%0D%0A
     

Remove expiry date beta code