svn commit: r13094 - branches/gsoc2007/maurelio1234/src_new/org/argouml: i18n persistence ui uml/profile

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: maurelio1234
Date: 2007-07-18 04:44:08-0700
New Revision: 13094

Modified:
   branches/gsoc2007/maurelio1234/src_new/org/argouml/i18n/tab.properties
   branches/gsoc2007/maurelio1234/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java
   branches/gsoc2007/maurelio1234/src_new/org/argouml/ui/ProjectSettingsTabProfile.java
   branches/gsoc2007/maurelio1234/src_new/org/argouml/uml/profile/UserDefinedProfile.java

Log:
saving user defined profiles into the zargo file

Modified: branches/gsoc2007/maurelio1234/src_new/org/argouml/i18n/tab.properties
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/maurelio1234/src_new/org/argouml/i18n/tab.properties?view=diff&rev=13094&p1=branches/gsoc2007/maurelio1234/src_new/org/argouml/i18n/tab.properties&p2=branches/gsoc2007/maurelio1234/src_new/org/argouml/i18n/tab.properties&r1=13093&r2=13094
==============================================================================
--- branches/gsoc2007/maurelio1234/src_new/org/argouml/i18n/tab.properties	(original)
+++ branches/gsoc2007/maurelio1234/src_new/org/argouml/i18n/tab.properties	2007-07-18 04:44:08-0700
@@ -58,4 +58,6 @@
 tab.profiles.directories.remove = Remove
 tab.profiles.directories.refresh = Refresh
 
-tab.profiles.cannotdelete = Only user defined profiles can be unregistered!
\ No newline at end of file
+tab.profiles.cannotdelete = Only user defined profiles can be unregistered!
+tab.profiles.confirmdeleteunregistered = The selected profile is only available in this project, after removed there is no way to add it again. Are you sure you want to remove it?
+tab.profiles.confirmdeleteunregistered.title = Confirm
\ No newline at end of file

Modified: branches/gsoc2007/maurelio1234/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/maurelio1234/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java?view=diff&rev=13094&p1=branches/gsoc2007/maurelio1234/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java&p2=branches/gsoc2007/maurelio1234/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java&r1=13093&r2=13094
==============================================================================
--- branches/gsoc2007/maurelio1234/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java	(original)
+++ branches/gsoc2007/maurelio1234/src_new/org/argouml/persistence/ProfileConfigurationFilePersister.java	2007-07-18 04:44:08-0700
@@ -25,21 +25,32 @@
 package org.argouml.persistence;
 
 import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
 import java.io.Writer;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.Vector;
 
+import org.argouml.application.helpers.ApplicationVersion;
 import org.argouml.kernel.Project;
 import org.argouml.kernel.ProjectMember;
+import org.argouml.model.Model;
+import org.argouml.model.UmlException;
+import org.argouml.model.XmiReader;
+import org.argouml.model.XmiWriter;
 import org.argouml.uml.profile.Profile;
 import org.argouml.uml.profile.ProfileConfiguration;
 import org.argouml.uml.profile.ProfileManagerImpl;
+import org.argouml.uml.profile.StreamModelLoader;
 import org.argouml.uml.profile.UserDefinedProfile;
+import org.xml.sax.InputSource;
 
 /**
  * Persister for Project's Profile Configuration
@@ -92,28 +103,29 @@
 			.getRegisteredProfiles();
 
 		if (line.equals("<userDefined>")) {
-		    String fileName = br.readLine().trim();
+                    line = br.readLine().trim();
+		    String fileName = line.substring(line.indexOf(">")+1, line.indexOf("</")).trim();
 
+                    // consumes the <model> tag
+                    br.readLine();
+                    
 		    File file = new File(fileName);
 
-		    boolean found = false;
-		    for (int i = 0; i < profiles.size(); ++i) {
-			if (profiles.get(i) instanceof UserDefinedProfile) {
-			    UserDefinedProfile p = (UserDefinedProfile) profiles
-				    .get(i);
-			    if (p.getModelFile().equals(file)) {
-				found = true;
-				profile = p;
-				break;
-			    }
-			}
-		    }
-
-		    if (!found) {
-			UserDefinedProfile ud = new UserDefinedProfile(file);
-			profile = ud;
-		    }
-		    
+		    StringBuffer xmi = new StringBuffer();
+                    
+                    while(true) {
+                        line = br.readLine();
+                        if (line == null || line.contains("</model>")) {
+                            break;
+                        }
+                        
+                        xmi.append(line+"\n");
+                    }
+                    
+                    Object model = readModelXMI(xmi.toString());
+                    profile = new UserDefinedProfile(fileName, model);
+                    
+                    // consumes the </userDefined>
 		    line = br.readLine().trim();		    
 		} else if (line.equals("<plugin>")) {
 		    String className = br.readLine().trim();
@@ -181,9 +193,12 @@
 		    if (!pc.getDefaultProfile().equals(profile)) {
 			if (profile instanceof UserDefinedProfile) {
 			    w.println("\t\t<userDefined>");
-			    w.println("\t\t\t"
-				    + ((UserDefinedProfile) profile)
-					    .getModelFile().getCanonicalPath());
+                            w.println("\t\t\t<filename>"+((UserDefinedProfile)profile).getModelFile().getName()+"</filename>");
+                            w.println("\t\t\t<model>");
+                            
+                            printModelXMI(w, profile.getModel());
+                            
+                            w.println("\t\t\t</model>");                            
 			    w.println("\t\t</userDefined>");
 			} else {
 			    w.println("\t\t<plugin>");
@@ -201,4 +216,22 @@
 	}
     }
 
+    private void printModelXMI(PrintWriter w, Object model) throws UmlException {
+        StringWriter myWriter = new StringWriter();
+        XmiWriter xmiWriter = Model.getXmiWriter(model, myWriter, ApplicationVersion
+                .getVersion()
+                + "(" + UmlFilePersister.PERSISTENCE_VERSION + ")");
+        xmiWriter.write();
+        
+        myWriter.flush();
+        w.println("" + myWriter.toString());
+    }
+
+    private Object readModelXMI(String xmi) throws UmlException {
+        XmiReader xmiReader = Model.getXmiReader();
+        InputSource inputSource = new InputSource(new ByteArrayInputStream(xmi.getBytes()));
+        Collection elements = xmiReader.parse(inputSource, true);
+        return elements.iterator().next();
+    }
+
 }

Modified: branches/gsoc2007/maurelio1234/src_new/org/argouml/ui/ProjectSettingsTabProfile.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/maurelio1234/src_new/org/argouml/ui/ProjectSettingsTabProfile.java?view=diff&rev=13094&p1=branches/gsoc2007/maurelio1234/src_new/org/argouml/ui/ProjectSettingsTabProfile.java&p2=branches/gsoc2007/maurelio1234/src_new/org/argouml/ui/ProjectSettingsTabProfile.java&r1=13093&r2=13094
==============================================================================
--- branches/gsoc2007/maurelio1234/src_new/org/argouml/ui/ProjectSettingsTabProfile.java	(original)
+++ branches/gsoc2007/maurelio1234/src_new/org/argouml/ui/ProjectSettingsTabProfile.java	2007-07-18 04:44:08-0700
@@ -386,11 +386,27 @@
             if (usedList.getSelectedIndex() != -1) {

                 Profile selected = modelUsd.getProfileAt(usedList

                         .getSelectedIndex());

-                ProjectManager.getManager().getCurrentProject()

-                        .getProfileConfiguration().removeProfile(selected);

                 

-                modelAvl.fireListeners();

-                modelUsd.fireListeners();

+                boolean remove = true;

+                if (!ProfileManagerImpl.getInstance().getRegisteredProfiles()

+                        .contains(selected)) {

+                    remove = (JOptionPane

+                            .showConfirmDialog(

+                                    this,

+                                    Translator

+                                            .localize("tab.profiles.confirmdeleteunregistered"),

+                                    Translator

+                                            .localize("tab.profiles.confirmdeleteunregistered.title"),

+                                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION);

+                }

+

+                if (remove) {

+                    ProjectManager.getManager().getCurrentProject()

+                            .getProfileConfiguration().removeProfile(selected);

+

+                    modelAvl.fireListeners();

+                    modelUsd.fireListeners();

+                }

             }

 	} else if (arg0.getSource() == unregisterProfile) {

 	    if (availableList.getSelectedIndex() != -1) {


Modified: branches/gsoc2007/maurelio1234/src_new/org/argouml/uml/profile/UserDefinedProfile.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/maurelio1234/src_new/org/argouml/uml/profile/UserDefinedProfile.java?view=diff&rev=13094&p1=branches/gsoc2007/maurelio1234/src_new/org/argouml/uml/profile/UserDefinedProfile.java&p2=branches/gsoc2007/maurelio1234/src_new/org/argouml/uml/profile/UserDefinedProfile.java&r1=13093&r2=13094
==============================================================================
--- branches/gsoc2007/maurelio1234/src_new/org/argouml/uml/profile/UserDefinedProfile.java	(original)
+++ branches/gsoc2007/maurelio1234/src_new/org/argouml/uml/profile/UserDefinedProfile.java	2007-07-18 04:44:08-0700
@@ -35,7 +35,8 @@
 
     private String displayName;
     private File modelFile;
-    private ProfileModelLoader modelLoader;
+    private Object model;
+    private boolean fromZargo;
     
     /**
      * The default constructor for this class
@@ -44,17 +45,32 @@
      */
     public UserDefinedProfile(File file) {
 	this.displayName = file.getName();
-	this.modelLoader = new FileModelLoader();
 	this.modelFile = file;
+        this.model = new FileModelLoader().loadModel(modelFile.getPath());
+        this.fromZargo = false;
     }
     
     /**
-     * @return the string that should represent this profile in the GUI.
+     * This constructor is used by the persitence subsystem
+     * when loading an user defined profile from a zargo file.
+     * 
+     * @param fileName the fake file name
+     * @param model    the model loaded from the zargo file
+     */
+    public UserDefinedProfile(String fileName, Object model) {
+        this.displayName = fileName;
+        this.modelFile = new File(fileName);
+        this.model = model;
+        this.fromZargo = true;
+    }
+    
+    /**
+     * @return the string that should represent this profile in the GUI. An start (*) is placed on it if it comes from the currently opened zargo file.
      * 
      * @see org.argouml.uml.profile.Profile#getDisplayName()
      */
     public String getDisplayName() {
-	return displayName;
+	return displayName + (fromZargo? "*" : "");
     }
 
     /**
@@ -70,7 +86,7 @@
      * @see org.argouml.uml.profile.Profile#getModel()
      */
     public Object getModel() {
-	return modelLoader.loadModel(modelFile.getPath());
+	return model;
     }
 
     /**
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.