[elvystrac] r1734 -

  • From: elvys@xxxxxxxxxxxxxxxxxxxxxx
  • To: elvystrac@xxxxxxxxxxxxx
  • Date: Mon, 15 Feb 2010 16:29:01 +0100

Author: EvaV
Date: 2010-02-15 16:29:01 +0100 (Mon, 15 Feb 2010)
New Revision: 1734

Removed:
   trunk/layouteditor/LayoutDesigner/src/applet/images/
Modified:
   trunk/layouteditor/LayoutDesigner/src/applet/LayoutDesigner.java
   trunk/layouteditor/LayoutDesigner/src/applet/SaveLayoutOnServer.java
   trunk/layouteditor/LayoutDesigner/src/applet/ServerSideContext.java
Log:


Modified: trunk/layouteditor/LayoutDesigner/src/applet/LayoutDesigner.java
===================================================================
--- trunk/layouteditor/LayoutDesigner/src/applet/LayoutDesigner.java    
2010-02-15 15:09:32 UTC (rev 1733)
+++ trunk/layouteditor/LayoutDesigner/src/applet/LayoutDesigner.java    
2010-02-15 15:29:01 UTC (rev 1734)
@@ -13,9 +13,8 @@
 import javax.swing.border.LineBorder;
 import javax.swing.JDialog;
 import javax.swing.JApplet;
-//import netscape.javascript.*;
+import java.lang.reflect.*;
 
-
 /**
  * LayoutDesigner is main applet class. Initializes individual components and
  * displays applet.
@@ -25,28 +24,46 @@
        private static final long serialVersionUID = 5212730162755861066L;
 
        // fields
-       private JMenuBar menuBar;                                       /** 
menu bar */
-       private JTabbedPane propertiesManager;          /** properties manager 
tabbed pane */
-       private JPanel statusBar;                                       /** 
status bar */
-       private TabbedPane tabbedPane;                          /** main tabbed 
pane */
-       private JToolBar toolBar;                                       /** 
tool bar */
-       private Layout layoutToOpen = null;                     /** layout read 
from server - if editing layout 
-                                                                               
                        is empty - if creating new layout */                    
-       private Applet instance;                                        /** 
this applet */
-       private Vector<String> allPossibleDocumentTypes;                /** all 
possible document types */
-       private ComponentSizes componentSizes;                                  
/** size of components */
-       private Properties properties;                                          
        /** properties */
-       private JRootPane rootPane;                                             
        /** rootPane of this applet */ 
+       private JMenuBar menuBar;
+       /** menu bar */
+       private JTabbedPane propertiesManager;
+       /** properties manager tabbed pane */
+       private JPanel statusBar;
+       /** status bar */
+       private TabbedPane tabbedPane;
+       /** main tabbed pane */
+       private JToolBar toolBar;
+       /** tool bar */
+       private Layout layoutToOpen = null;
+       /**
+        * layout read from server - if editing layout is empty - if creating 
new
+        * layout
+        */
+       private Applet instance;
+       /** this applet */
+       private Vector<String> allPossibleDocumentTypes;
+       /** all possible document types */
+       private ComponentSizes componentSizes;
+       /** size of components */
+       private Properties properties;
+       /** properties */
+       private JRootPane rootPane;
+       /** rootPane of this applet */
 
        // constants
-       private final static String PROPERTIES_FILE_NAME = 
"LayoutDesigner.properties";                 /** name of file with properties */
-       private final static String PROPERTIES_FILE_PATH = 
"/webServer2/applets/";                              /** file path to 
properties file */
-       private final static int APPLET_WIDTH = 1000;                           
                                                        /** width of applet */
-       private final static int APPLET_HEIGHT = 500;                           
                                                        /** height of applet */
-       private final static int BAR_HEIGHT = 35;                               
                                                                /** height of 
all bars */
-       private final static int PROPERTIES_MANAGER_WIDTH = 200;                
                                                /** width of properties manager 
*/
+       private final static String PROPERTIES_FILE_NAME = 
"LayoutDesigner.properties";
+       /** name of file with properties */
+       private final static String PROPERTIES_FILE_PATH = 
"/webServer2/applets/";
+       /** file path to properties file */
+       private final static int APPLET_WIDTH = 1000;
+       /** width of applet */
+       private final static int APPLET_HEIGHT = 500;
+       /** height of applet */
+       private final static int BAR_HEIGHT = 35;
+       /** height of all bars */
+       private final static int PROPERTIES_MANAGER_WIDTH = 200;
+       /** width of properties manager */
        private final static String NOT_LOADED_PROPERTIES = "Server 
communication error: It isn't possible to read properties file";
-       
 
        /**
         * Initializes applet
@@ -86,8 +103,8 @@
                                        try {
                                                
properties.load(url.openStream());
                                        } catch (IOException e) {
-                                               new WarningDialog(new 
JFrame(),NOT_LOADED_PROPERTIES, properties
-                                                                               
.getProperty("warning.warning"));
+                                               new WarningDialog(new JFrame(), 
NOT_LOADED_PROPERTIES,
+                                                               
properties.getProperty("warning.warning"));
                                                e.printStackTrace();
                                        }
 
@@ -138,7 +155,9 @@
 
                                        if (isLocked) {
                                                new WarningDialog(new JFrame(), 
properties
-                                                               
.getProperty("warning.isLocked") + 
ServerSideContext.getInstance().getLockedUser(), properties
+                                                               
.getProperty("warning.isLocked")
+                                                               + 
ServerSideContext.getInstance()
+                                                                               
.getLockedUser(), properties
                                                                
.getProperty("warning.warning"));
                                                
closeLayoutDesignerBrowserWindow();
                                        } else {
@@ -239,13 +258,39 @@
        }
 
        /**
-        *      Closes browser window with LayoutDesigner
+        * Closes browser window with LayoutDesigner
         */
        private void closeLayoutDesignerBrowserWindow() {
-                //JSObject win = (JSObject) JSObject.getWindow(this);
-                //win.eval("self.close();");
+
+               /* String jscmd = "window.close()"; 
+               String jsresult = null;
+               boolean success = false;
+               try {
+                       Method getw = null, eval = null;
+                       Object jswin = null;
+                       Class c = 
Class.forName("netscape.javascript.JSObject"); 
+                       Method ms[] = c.getMethods();
+                       for (int i = 0; i < ms.length; i++) {
+                               if (ms[i].getName().compareTo("getWindow") == 
0) {
+                                       getw = ms[i];
+                               }
+                               else if (ms[i].getName().compareTo("eval") == 
0) {
+                                       eval = ms[i];
+                               }
+                       }
+                       
+                       Object a[] = new Object[1]; 
+                       a[0] = this; 
+                       jswin = getw.invoke(c, a);
+                       a[0] = jscmd; 
+                       eval.invoke(jswin, a); 
+                       
+               } catch (Exception e) {
+
+               }*/
+
        }
-       
+
        /**
         * Opens new empty layout
         */
@@ -282,7 +327,8 @@
        }
 
        /**
-        * When applet is started, it locks edited layout, nobodyelse is able 
to edit this layout
+        * When applet is started, it locks edited layout, nobodyelse is able to
+        * edit this layout
         */
        public void start() {
                Layout layout = ServerSideContext.getInstance().getLayout();

Modified: trunk/layouteditor/LayoutDesigner/src/applet/SaveLayoutOnServer.java
===================================================================
--- trunk/layouteditor/LayoutDesigner/src/applet/SaveLayoutOnServer.java        
2010-02-15 15:09:32 UTC (rev 1733)
+++ trunk/layouteditor/LayoutDesigner/src/applet/SaveLayoutOnServer.java        
2010-02-15 15:29:01 UTC (rev 1734)
@@ -67,6 +67,7 @@
                        if (layout.isChangedPositionCount()) {
                                System.out.println("changed position count");
                                layout.setIsNew(true);
+                               ServerSideContext.getInstance().unlockLayout();
                        }
 
                        // this layout has never been saved on server
@@ -84,12 +85,17 @@
                                layout.setRevision(0);
                                layout.setIsChangedPositionCount(false);
                                layout.setInformedThatIsEditing(false);
+                               
ServerSideContext.getInstance().setLayoutID(layoutID);
                        } else {
                                // saves old layout under new name
                                if (oldLayoutName.compareTo(newLayoutName) != 
0) {
+                                       
+                                       
+                                       
                                        System.out.println("old layout saved 
under new name");
                                        layout.setName(newLayoutName);
                                        layout.setIsNew(true);
+                                       layout.setRevision(0);
                                        String xml = new Marshaller()
                                                        
.marshallLayoutToString(layout);
                                        int layoutID = 
ServerSideContext.getInstance()
@@ -103,6 +109,7 @@
                                        layout.setInformedThatIsEditing(false);
                                        designArea.setSaved(true);
                                        
ServerSideContext.getInstance().unlockLayout();
+                                       
ServerSideContext.getInstance().setLayoutID(layoutID);
                                }
                                // saves already saved layout
                                else {
@@ -135,6 +142,9 @@
                                                
layout.setIsChangedPositionCount(false);
                                                
layout.setInformedThatIsEditing(false);
                                                designArea.setSaved(true);
+
+                                               
ServerSideContext.getInstance().unlockLayout();
+                                               
ServerSideContext.getInstance().setLayoutID(layoutID);
                                                
                                                new WarningDialog(new JFrame(), 
properties
                                                                
.getProperty("warning.isNotLocked"), properties

Modified: trunk/layouteditor/LayoutDesigner/src/applet/ServerSideContext.java
===================================================================
--- trunk/layouteditor/LayoutDesigner/src/applet/ServerSideContext.java 
2010-02-15 15:09:32 UTC (rev 1733)
+++ trunk/layouteditor/LayoutDesigner/src/applet/ServerSideContext.java 
2010-02-15 15:29:01 UTC (rev 1734)
@@ -43,6 +43,7 @@
        private static final String LOCK_ACTION = "lock";
        private static final String UNLOCK_ACTION = "unlock";
        private static final String LOCKED_BY_ME_ACTION ="lockedByMe";
+       private static final String IS_LAYOUT_LOCKED="isLocked";
 
        // private constructor- due to singleton
        /**
@@ -114,6 +115,8 @@
                String userID = applet.getParameter(PROPREF_USER_ID);
                instance.userID = Integer.parseInt(userID);
 
+               instance.isLayoutLocked();
+               
                // set permitted document types
                instance.permittedDocumentTypes = 
instance.preparePermittedDocumentTypes();
 
@@ -123,14 +126,16 @@
                instance
                                
.setSupportedResolutions(instance.prepareSupportedResolutions());
 
-               try {
-                       instance.layoutID = Integer.parseInt(layoutID);
-                       instance.layout = instance.getLayoutToEdit(tabbedPane);
-               } catch (Exception e) {
-                       instance.layout = null;
-                       instance.isLocked = false;
+               if(!isLocked) {
+                       
+                       try {
+                               instance.layoutID = Integer.parseInt(layoutID);
+                               instance.layout = 
instance.getLayoutToEdit(tabbedPane);
+                       } catch (Exception e) {
+                               instance.layout = null;
+                               instance.isLocked = false;
+                       }
                }
-
        }
 
        /**
@@ -327,6 +332,14 @@
        }
        
        /**
+        * Finds whatever this layout is locked by another user
+        * @throws Exception
+        */
+       public void isLayoutLocked() throws Exception {
+               postLayoutLocking(IS_LAYOUT_LOCKED);
+       }
+       
+       /**
         * Sends xml of layout to the server and the server stores it into DB.
         * @param xml xml of layout to store
         * @return new id of stored layout
@@ -400,13 +413,28 @@
                        String line;
                        String result = "";
                        while ((line = rd.readLine()) != null) {
-                               result += line; // + "\n";
+                               result += line;
                        }
-                       System.out.println(result);
                        isLockedByMe = result.equals(IS_LOCKED);        
                        
                }
+               
+               else if(type.equals(IS_LAYOUT_LOCKED)) {
+                       String line;
+                       String result = "";
+                       while ((line = rd.readLine()) != null) {
+                               result += line;
+                       }
+                       
+                       isLocked = result.substring(0, 
IS_LOCKED.length()).equals(IS_LOCKED);
 
+                       if(isLocked) {
+                               lockedUser = 
result.substring(IS_LOCKED.length());
+                       }
+
+                       
+               }
+
                                
        }
        
@@ -452,10 +480,6 @@
                        System.out.println("layout not opened");
                        isLocked = false;
                        return null;
-               } else if (result.substring(0, 
IS_LOCKED.length()).equals(IS_LOCKED)) {
-                       isLocked = true;
-                       lockedUser = result.substring(IS_LOCKED.length());
-                       return null;
                } else {
                        ReadLayoutFromServer openFile = new 
ReadLayoutFromServer(
                                        tabbedPane, 
instance.supportedResolutions,


Other related posts:

  • » [elvystrac] r1734 - - elvys