svn commit: r17429 - trunk/src/argouml-app/src/org/argouml/ui/explorer

Thomas Neustupny <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: thn
Date: 2009-10-26 13:02:06-0700
New Revision: 17429

Modified:
   trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionDeployProfile.java
   trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java

Log:
some more progress for profile deployment, makes profile modeling easier

Modified: trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionDeployProfile.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionDeployProfile.java?view=diff&pathrev=17429&r1=17428&r2=17429
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionDeployProfile.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/ui/explorer/ActionDeployProfile.java	2009-10-26 13:02:06-0700
@@ -26,27 +26,20 @@
 
 import java.awt.event.ActionEvent;
 import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
 import java.util.Collection;
 
 import javax.swing.AbstractAction;
 import javax.swing.JFileChooser;
-import javax.swing.filechooser.FileFilter;
 
 import org.apache.log4j.Logger;
-import org.argouml.application.helpers.ApplicationVersion;
-import org.argouml.configuration.Configuration;
-import org.argouml.i18n.Translator;
 import org.argouml.model.Model;
-import org.argouml.model.UmlException;
-import org.argouml.model.XmiWriter;
 import org.argouml.persistence.PersistenceManager;
 import org.argouml.persistence.ProjectFileView;
-import org.argouml.persistence.UmlFilePersister;
-import org.argouml.profile.Profile;
 import org.argouml.profile.ProfileException;
+import org.argouml.profile.ProfileFacade;
+import org.argouml.profile.ProfileManager;
+import org.argouml.profile.UserDefinedProfile;
+import org.argouml.ui.ProjectBrowser;
 import org.argouml.util.ArgoFrame;
 
 /**
@@ -70,14 +63,71 @@
      */
     public ActionDeployProfile(Object profile) {
         //super(Translator.localize("action.deploy-profile"));
-        super ("Deploy Profile");
+        super ("Deploy Profile...");
         undeployedProfile = profile;
     }
 
     public void actionPerformed(ActionEvent arg0) {
-        Object profile = Model.getExtensionMechanismsHelper()
-            .makeProfileApplicable(undeployedProfile);
-        LOG.debug("REMOVE ME: " + profile.toString());
-        // TODO: save it, maybe put it into the profile configuration
+        // make the profile ready to be applied
+        //Object profile = Model.getExtensionMechanismsHelper()
+        //    .makeProfileApplicable(undeployedProfile);
+        // get one of the default profile dirs, if available
+        // (as a default value for the following save dialog)
+        ProfileManager profileManager = ProfileFacade.getManager();
+        StringBuffer path = new StringBuffer();
+        Collection dirs = profileManager.getSearchPathDirectories();
+        if (dirs != null && !dirs.isEmpty()) {
+            String s = (String) dirs.iterator().next();
+            path.append(s);
+            if (!(s.endsWith("/") || s.endsWith("\\"))) {
+                path.append('/');
+            }
+        }
+        // save profile
+        path.append(Model.getFacade().getName(undeployedProfile));
+        File f = saveProfile(path.toString());
+        if (f == null) {
+            return;
+        }
+        // register it as a user profile
+        try {
+            profileManager.registerProfile(new UserDefinedProfile(f));
+        } catch (ProfileException e) {
+            LOG.warn("failed to load profile from file " + f.getPath(), e);
+        }
+    }
+
+    /**
+     * Offers the saving of the profile by presenting a file dialog.
+     * 
+     * @param fn the suggested default path for the file dialog
+     * @return the File instance where the profile is saved, null on abort
+     */
+    private File saveProfile(String fn) {
+        File theFile = null;
+        PersistenceManager pm = PersistenceManager.getInstance();
+        // show a chooser dialog for the file name, only xmi is allowed
+        JFileChooser chooser = new JFileChooser();
+        chooser.setDialogTitle("Save Profile");
+        chooser.setFileView(ProjectFileView.getInstance());
+        chooser.setApproveButtonText("Save");
+        chooser.setAcceptAllFileFilterUsed(true);
+        pm.setXmiFileChooserFilter(chooser);
+        if (fn.length() > 0) {
+            fn = PersistenceManager.getInstance().getBaseName(fn);
+            chooser.setSelectedFile(new File(fn));
+        }
+        int result = chooser.showSaveDialog(ArgoFrame.getFrame());
+        if (result == JFileChooser.APPROVE_OPTION) {
+            theFile = chooser.getSelectedFile();
+            if (theFile != null) {
+                String name = theFile.getName();
+                name = pm.fixXmiExtension(name);
+                theFile = new File(theFile.getParent(), name);
+                ProjectBrowser.getInstance().trySaveWithProgressMonitor(
+                        true, theFile, false);
+            }
+        }
+        return theFile;
     }
 }

Modified: trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java?view=diff&pathrev=17429&r1=17428&r2=17429
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java	2009-10-26 13:02:06-0700
@@ -182,11 +182,6 @@
         // this.add(action);
         // }
 
-        if (!multiSelect && mutableModelElementsOnly) {
-            initMenuCreateDiagrams();
-            this.add(createDiagrams);
-        }
-
         // profile section: dealing with profiles in different states
 
         // 1. a noneditable applied profile
@@ -204,15 +199,19 @@
             this.add(new ActionManageProfiles());
         }
 
-        // 3. UML2 only: the editable unapplied profile
+        // 3. the editable unapplied profile
 
-        if (Model.getFacade().getUmlVersion().charAt(0) == '2'
-             && Model.getFacade().isAProfile(selectedItem)) {
+        if (Model.getFacade().isAProfile(selectedItem)) {
             this.add(new ActionDeployProfile(selectedItem));
         }
 
         // end of profile section
 
+        if (!multiSelect && mutableModelElementsOnly) {
+            initMenuCreateDiagrams();
+            this.add(createDiagrams);
+        }
+
         if (mutableModelElementsOnly) {
             initMenuCreateModelElements();
         }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2411497

To unsubscribe from this discussion, e-mail: [[email protected]].
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.