]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java
Salome HOME
Tool bar is improved.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / ImportDocumentAction.java
index e35e72d9e44fd80fb7ea1071d08bae0fb57acb07..d6af46bcf4a4608bd413a62f5ad6a2ec153559f3 100644 (file)
@@ -10,13 +10,9 @@ import java.util.List;
 import java.util.ResourceBundle;
 import java.util.Vector;
 
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
 import org.splat.dal.bo.kernel.User;
 import org.splat.manox.Reader;
 import org.splat.manox.Toolbox;
-import org.splat.dal.dao.som.Database;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.ProgressState;
 import org.splat.service.DocumentService;
@@ -30,6 +26,9 @@ import org.splat.dal.bo.som.DocumentType;
 import org.splat.som.Revision;
 import org.splat.som.Step;
 
+/**
+ * Action for adding a document into a study step.
+ */
 public class ImportDocumentAction extends UploadBaseNextAction {
 
        /**
@@ -65,7 +64,31 @@ public class ImportDocumentAction extends UploadBaseNextAction {
        /**
         * Injected repository service.
         */
-       private RepositoryService _repositoryService;
+       private RepositoryService _repositoryService;   
+       /**
+        * Value of the menu property. 
+        * It can be: none, create, open, study, knowledge, sysadmin, help.
+        */
+       private String _menuProperty;
+       
+       /**
+        * Value of the title bar property. 
+        * It can be: study, knowledge.
+        */
+       private String _titleProperty;
+       
+       /**
+        * Value of the tool bar property. 
+        * It can be: none, standard, study, back.
+        */
+       private String _toolProperty;
+       
+       /**
+        * Property that indicates whether the current open study is editable or not.
+        * On the screen it looks like pen on the status icon, pop-up menu also can be called.
+        * It is necessary for correct building the title bar.
+        */
+       private String _editDisabledProperty = "false";
 
        // ==============================================================================================================================
        // Action methods
@@ -76,9 +99,17 @@ public class ImportDocumentAction extends UploadBaseNextAction {
         * @return SUCCESS in success, otherwise - ERROR
         */
        public String doInitialize() {
-               // -----------------------------
-               Session connex = Database.getCurSession();
-               Transaction transax = connex.beginTransaction();
+               
+               setMenuProperty("study");
+               setTitleProperty("study");
+               setEditDisabledProperty("true");
+               if ("true".equals(getWriteAccess())) {
+                       setToolProperty("study");
+               } else {
+                       setToolProperty("none");
+               }
+        initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
+             
                User user = getConnectedUser();
                File updir = getRepositoryService().getDownloadDirectory(user);
                File upfile = new File(updir.getPath() + "/" + filename);
@@ -88,7 +119,7 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                mystudy = getOpenStudy();
                Step step = mystudy.getSelectedStep();
                doctypes = getStepService().getValidDocumentTypes(step);
-               deftype = ApplicationSettings.getDefaultDocumentType(step, filext);
+               deftype = getApplicationSettings().getDefaultDocumentType(step, filext);
                defuses = new Vector<Document>();
                state = ProgressState.inWORK;
 
@@ -110,10 +141,18 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                                                new Revision().toString());
                                if (slot == null) {
                                        setErrorCode("reference.undefined");
+                                       
+                                       setToolProperty("none");
+                                       initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
+                                       
                                        return ERROR;
                                } else {
                                        if (!slot.isUndefined()) {
                                                setErrorCode("reference.duplicate");
+                                               
+                                               setToolProperty("none");
+                                               initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
+                                               
                                                return ERROR;
                                        }
                                        docref = fileref; // Disables document name and state fields
@@ -133,19 +172,27 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                                        docver = version.toString();
                                } catch (ParseException e) {
                                        setErrorCode("format.version");
+                                       
+                                       setToolProperty("none");
+                                       initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
+                                       
                                        return ERROR;
                                }
                        docname = tool.extractProperty("title"); // Property kept even if the file is not referenced
                        date = tool.extractProperty("date");
                        if (date != null) {
                                ResourceBundle locale = ResourceBundle.getBundle("som",
-                                               ApplicationSettings.getCurrentLocale());
+                                               getApplicationSettings().getCurrentLocale());
                                SimpleDateFormat check = new SimpleDateFormat(
                                                locale.getString("date.format"));
                                try {
                                        check.parse(date);
                                } catch (ParseException e) {
                                        setErrorCode("format.date");
+                                       
+                                       setToolProperty("none");
+                                       initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
+                                       
                                        return ERROR;
                                }
                        } else
@@ -166,7 +213,6 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                Arrays.sort(types, compare);
                doctypes = Arrays.asList(types);
 
-               transax.commit();
                return SUCCESS;
        }
 
@@ -176,14 +222,22 @@ public class ImportDocumentAction extends UploadBaseNextAction {
         */
        public String doImport() {
                // -------------------------
+               
+               setMenuProperty("study");
+               setTitleProperty("study");
+               setEditDisabledProperty("true");
+        initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
+           
                if (action == ToDo.cancel)
                        return "cancel";
                if (doctype == 0) {
                        setErrorCode("import.type");
+                       
+                       setToolProperty("none");
+                       initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
+                       
                        return ERROR;
                }
-               Session connex = Database.getCurSession();
-               Transaction transax = connex.beginTransaction();
                try {
                        // Getting user inputs
                        mystudy = getOpenStudy();
@@ -219,7 +273,7 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                        } else { // Importation of a previously created template-based document
                                if (date.length() > 0) {
                                        ResourceBundle locale = ResourceBundle.getBundle("som",
-                                                       ApplicationSettings.getCurrentLocale());
+                                                       getApplicationSettings().getCurrentLocale());
                                        SimpleDateFormat get = new SimpleDateFormat(
                                                        locale.getString("date.format"));
                                        dprop.setDate(get.parse(date));
@@ -260,10 +314,9 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                        }
                        // Creation of derived the document formats
                        // Document ndoc = addoc.value();
-                       // Converter send = ApplicationSettings.getConverter(ndoc.getType(), ndoc.getFormat());
+                       // Converter send = getApplicationSettings().getConverter(ndoc.getType(), ndoc.getFormat());
                        //
                        // if (send != null) send.converts(addoc); // Asynchronous process
-                       transax.commit();
 
                        mystudy.add(addoc); // Updates the presentation
                        return SUCCESS;
@@ -274,14 +327,10 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                        logger.error("Reason:", error);
                        setErrorCode("internal");
                }
-               if (transax != null && transax.isActive()) { // Probably useless test
-               // Second try-catch as the rollback could fail as well
-                       try {
-                               transax.rollback();
-                       } catch (HibernateException backerror) {
-                               logger.debug("Error rolling back transaction", backerror);
-                       }
-               }
+               
+               setToolProperty("none");
+               initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
+               
                return ERROR;
        }
 
@@ -458,4 +507,68 @@ public class ImportDocumentAction extends UploadBaseNextAction {
        public void setDocumentTypeService(DocumentTypeService documentTypeService) {
                _documentTypeService = documentTypeService;
        }
+       
+       /**
+        * Get the menuProperty.
+        * @return the menuProperty
+        */
+       public String getMenuProperty() {
+               return _menuProperty;
+       }
+
+       /**
+        * Set the menuProperty.
+        * @param menuProperty the menuProperty to set
+        */
+       public void setMenuProperty(String menuProperty) {
+               this._menuProperty = menuProperty;
+       }
+       
+       /**
+        * Get the _titleProperty.
+        * @return the _titleProperty
+        */
+       public String getTitleProperty() {
+               return _titleProperty;
+       }
+
+       /**
+        * Set the _titleProperty.
+        * @param _titleProperty the titleProperty to set
+        */
+       public void setTitleProperty(String titleProperty) {
+               _titleProperty = titleProperty;
+       }
+
+       /**
+        * Get the editDisabledProperty.
+        * @return the editDisabledProperty
+        */
+       public final String getEditDisabledProperty() {
+               return _editDisabledProperty;
+       }
+
+       /**
+        * Set the editDisabledProperty.
+        * @param editDisabledProperty the editDisabledProperty to set
+        */
+       public final void setEditDisabledProperty(String editDisabledProperty) {
+               _editDisabledProperty = editDisabledProperty;
+       }
+
+       /**
+        * Get the toolProperty.
+        * @return the toolProperty
+        */
+       public String getToolProperty() {
+               return _toolProperty;
+       }
+
+       /**
+        * Set the toolProperty.
+        * @param toolProperty the toolProperty to set
+        */
+       public void setToolProperty(final String toolProperty) {
+               _toolProperty = toolProperty;
+       }
 }
\ No newline at end of file