Package de.FeatureModellingTool.ProjectManager

Source Code of de.FeatureModellingTool.ProjectManager.ProjectManagerImplementation$CloseViewAction

package de.FeatureModellingTool.ProjectManager;

import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.filechooser.FileFilter;

import org.freehep.util.parameterdatabase.DatabaseListener;

import applet.MainApplet;


import manager.IllegalParameterException;
import manager.ManagerInterface;
import model.DrawModel;
import model.FileModel;
import research.Drawing;
import research.DrawingView;
import research.store.StorableOutput;
import service.FileModelService;

import component.FComponent;

import de.FeatureModellingTool.IProjectReader;
import de.FeatureModellingTool.ProjectReaderFromDataBase;
import de.FeatureModellingTool.Customize.CustomizationModel;
import de.FeatureModellingTool.Customize.store.CmdlParser;
import de.FeatureModellingTool.Customize.store.CmdlParserPrototype;
import de.FeatureModellingTool.FeatureModel.ConstraintModel;
import de.FeatureModellingTool.FeatureModel.FeatureModel;
import de.FeatureModellingTool.FeatureModel.FeatureModelPropertyEditor;
import de.FeatureModellingTool.FeatureModel.InteractionModel;
import de.FeatureModellingTool.FeatureModel.store.FmdlParser;
import de.FeatureModellingTool.FeatureModel.store.FmdlParserPrototype;
import de.FeatureModellingTool.GraphicalEditor.DrawingViewContainer;
import de.FeatureModellingTool.GraphicalEditor.store.AdaptedStandardStorageFormat;
import de.FeatureModellingTool.ModelChecker.ModelChecker;
import de.FeatureModellingTool.ProjectManager.reuse.ProjectReader;
import de.reuse.CommonFileFilter;
import de.reuse.Context;
import de.reuse.ContextImplementation;
import de.reuse.GroupMap;
import de.reuse.GroupTreeMap;


/**
* author: zhangwei
* Date: 2003-6-7
* Time: 14:55:49
*/
class ProjectManagerImplementation implements ProjectManager {
    /**
     * ��Ŀ���������������ɶ���(actions)
     */
    protected NewProjectAction newProjectAction = null;
    protected OpenProjectAction openProjectAction = null;
    protected OpenProjectFromDBAction openProjectFromDBAction = null;
    protected ModifyProjectPropertiesAction modifyProjectPropertiesAction = null;
    protected SaveProjectAction saveProjectAction = null;
    protected SaveProjectToDBAction saveProjectToDBAction = null;
    protected SaveAsProjectAction saveAsProjectAction = null;
    protected CloseProjectAction closeProjectAction = null;

    protected NewViewAction newViewAction = null;
    protected CloseViewAction closeViewAction = null;
    protected OpenViewAction openViewAction = null;
    protected RemoveViewAction removeViewAction = null;
    protected ExportViewAction exportViewAction = null;
    protected ChangeViewNameAction changeViewNameAction = null;


    protected Hashtable data = null;

    /**
     * ��Ŀ�������Ļ����д��ڵı���(environments)
     */
    //��ǰ��Ŀ���ڵĴ���
    protected JComponent uiJPanel = null;
    //��ǰ��Ŀ
    protected Project project = null;

    //����ģ��
    protected FComponent featureModelNGObject = null;
    //����ģ�����Ա༭��
    protected FeatureModelPropertyEditor featureModelPropertyEditor = null;


    //ͼԪ�༭�������б�
    //private ActionMap graphicalEditorActionMap = null;
    private FComponent graphicalEditorActionMap = null;
    //DrawingView����
    private DrawingViewContainer drawingViewContainer = null;
    //�ļ�ѡ��Ի���
    private JFileChooser fileChooser = null;
    //ģ��ѡ��Ի���  -- �����ݿ���ѡ��
    private JModelChooser modelChooser = null;

    //��Ŀ��Ϣ���
    private ProjectInfoPane projectInfoPane = new ProjectInfoPane();
    //��ͼ��Ϣ���
    private ViewInfoPane viewInfoPane = new ViewInfoPane();

    //����Ŀ����������������
    protected final Context context = new ContextImplementation();


    //�ر���ͼ��Ч���Լ�����
    protected PropertyChangeListener closeViewEnabledPropertyChangeListener = new CloseViewEnabledPropertyChangeListener();
    //ɾ����ͼ��Ч���Լ�����
    protected PropertyChangeListener removeViewEnabledPropertyChangeListener = new RemoveViewEnabledPropertyChangeListener();
    //������ͼ��Ч���Լ�����
    protected PropertyChangeListener exportViewEnabledPropertyChangeListener = new ExportViewEnabledPropertyChangeListener();
    //�޸���ͼ������Ч���Լ�����
    protected PropertyChangeListener changeViewNameEnabledPropertyChangeListener = new ChangeViewNameEnabledPropertyChangeListener();

    public ProjectManagerImplementation() {
        /**
         * ������Ŀ���������������ɶ�������������뵽�б���
         */
        newProjectAction = new NewProjectAction();
        openProjectAction = new OpenProjectAction();
        openProjectFromDBAction = new OpenProjectFromDBAction();
        modifyProjectPropertiesAction = new ModifyProjectPropertiesAction();
        saveProjectAction = new SaveProjectAction();
        saveProjectToDBAction   = new SaveProjectToDBAction();
        saveAsProjectAction = new SaveAsProjectAction();
        closeProjectAction = new CloseProjectAction();

        newViewAction = new NewViewAction();
        closeViewAction = new CloseViewAction();
        removeViewAction = new RemoveViewAction();
        exportViewAction = new ExportViewAction();
        changeViewNameAction = new ChangeViewNameAction();

        data = new Hashtable();

        data.put(ConstantDefinition.NEW_PROJECT_ACTION, newProjectAction);
        data.put(ConstantDefinition.OPEN_PROJECT_ACTION, openProjectAction);
        data.put(ConstantDefinition.OPEN_PROJECT_ACTION_FROM_DB, openProjectFromDBAction);

        data.put(ConstantDefinition.MODIFY_PROJECT_PROPERTIES_ACTION, modifyProjectPropertiesAction);
        data.put(ConstantDefinition.SAVE_PROJECT_ACTION, saveProjectAction);
        data.put(ConstantDefinition.SAVE_PROJECT_TODB_ACTION, saveProjectToDBAction);
        data.put(ConstantDefinition.SAVE_AS_PROJECT_ACTION, saveAsProjectAction);
        data.put(ConstantDefinition.CLOSE_PROJECT_ACTION, closeProjectAction);
        data.put(ConstantDefinition.NEW_VIEW_ACTION, newViewAction);
        data.put(ConstantDefinition.CLOSE_VIEW_ACTION, closeViewAction);
        data.put(ConstantDefinition.REMOVE_VIEW_ACTION, removeViewAction);
        data.put(ConstantDefinition.EXPORT_VIEW_ACTION, exportViewAction);
        data.put(ConstantDefinition.CHANGE_VIEW_NAME_ACTION, changeViewNameAction);


        /**
         * ��ӻ����仯������
         */
        context.addContextChangeListener(new ContextChangeListener());
    }

    /**
     * ���ݶ������ƻ�ȡ����
     *
     * @param actionName
     * @return Action
     */
    public Action getAction(String actionName) {
        return (Action) data.get(actionName);
    }

    /**
     * ��ȡ����
     *
     * @return Context
     */
    public Context getContext() {
        return context;
    }

    /**
     * �����仯������
     */
    protected class ContextChangeListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent e) {
            contextChange(e);
        }
    }

    /**
     * �ú�����ѵ�ǰ����Ȥ�Ļ����������������ñ�������Ӧ��������.
     * ��ʵ���Ͽ���ֱ�ӵ������л����Щ���ã���΢�е��鷳��
     *
     * @param e
     */
    protected void contextChange(PropertyChangeEvent e) {
        String propertyName = e.getPropertyName();
        /**
         * ÿһ�λ��������仯����Ŀ�����������Ķ����Ŀ�������Ҫ����
         */

        //��ö����ĵ�ǰ����״̬
        Object[] actions = data.values().toArray();
        int size = actions.length;
        int oldV = 0, newV = 1;
        boolean value[][] = new boolean[size][2];
        for (int i = 0; i < size; i++) {
            ProjectAction action = (ProjectAction) actions[i];
            value[i][oldV] = action.isEnabled();
        }

        if (ConstantDefinition.FEATURE_MODEL_PROPERTY_EDITOR.equals(propertyName)) {
            featureModelPropertyEditor = (FeatureModelPropertyEditor) e.getNewValue();
        } else if (ConstantDefinition.PROJECT.equals(propertyName)) {
            project = (Project) e.getNewValue();
        } else if (ConstantDefinition.UI_JPANEL.equals(propertyName)) {
            uiJPanel = (JComponent) e.getNewValue();
        } else if (ConstantDefinition.FEATURE_MODEL.equals(propertyName)) {
            System.out.println(e.getNewValue());
            featureModelNGObject = (FComponent) e.getNewValue();
        } else if (ConstantDefinition.GRAPHICAL_EDITOR_ACTION_MAP.equals(propertyName)) {
            if (graphicalEditorActionMap != null) {
                ((Action) graphicalEditorActionMap.getInterface("closeView")).removePropertyChangeListener(closeViewEnabledPropertyChangeListener);
                ((Action) graphicalEditorActionMap.getInterface("removeView")).removePropertyChangeListener(removeViewEnabledPropertyChangeListener);
                ((Action) graphicalEditorActionMap.getInterface("exportView")).removePropertyChangeListener(exportViewEnabledPropertyChangeListener);
                ((Action) graphicalEditorActionMap.getInterface("changeViewName")).removePropertyChangeListener(changeViewNameEnabledPropertyChangeListener);
            }
            graphicalEditorActionMap = (FComponent) e.getNewValue();
            if (graphicalEditorActionMap != null) {
                ((Action) graphicalEditorActionMap.getInterface("closeView")).addPropertyChangeListener(closeViewEnabledPropertyChangeListener);
                ((Action) graphicalEditorActionMap.getInterface("removeView")).addPropertyChangeListener(removeViewEnabledPropertyChangeListener);
                ((Action) graphicalEditorActionMap.getInterface("exportView")).addPropertyChangeListener(exportViewEnabledPropertyChangeListener);
                ((Action) graphicalEditorActionMap.getInterface("changeViewName")).addPropertyChangeListener(changeViewNameEnabledPropertyChangeListener);
            }
        } else if (ConstantDefinition.DRAWING_VIEW_CONTAINER.equals(propertyName)) {
            drawingViewContainer = (DrawingViewContainer) e.getNewValue();
        } else if (ConstantDefinition.FILE_CHOOSER.equals(propertyName)) {
            fileChooser = (JFileChooser) e.getNewValue();
            projectInfoPane.setFileChooser(fileChooser);
        }else if(ConstantDefinition.MODEL_CHOOSER.equals(propertyName)){
          modelChooser = (JModelChooser)e.getNewValue();
          projectInfoPane.setModelChooser(modelChooser);
        }

        //���¶����Ľ�����Ϣ
        for (int i = 0; i < size; i++) {
            ProjectAction action = (ProjectAction) actions[i];
            value[i][newV] = action.isEnabled();

            if (value[i][oldV] != value[i][newV]) {
                action.firePropertyChange("enabled", Boolean.valueOf(value[i][oldV]), Boolean.valueOf(value[i][newV]));
            }
        }

    }


    protected class CloseViewEnabledPropertyChangeListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();

            if (propertyName.equals("enabled")) {

                boolean newV = ((Boolean) e.getNewValue()).booleanValue();

                if (newV && (closeViewAction.isEnabled())) {
                    closeViewAction.firePropertyChange("enabled", Boolean.FALSE, Boolean.TRUE);
                } else if (!newV && (!closeViewAction.isEnabled())) {
                    closeViewAction.firePropertyChange("enabled", Boolean.TRUE, Boolean.FALSE);
                }
            }
        }
    }


    protected class RemoveViewEnabledPropertyChangeListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();

            if (propertyName.equals("enabled")) {

                boolean newV = ((Boolean) e.getNewValue()).booleanValue();

                if (newV && (removeViewAction.isEnabled())) {
                    removeViewAction.firePropertyChange("enabled", Boolean.FALSE, Boolean.TRUE);
                } else if (!newV && (!closeViewAction.isEnabled())) {
                    removeViewAction.firePropertyChange("enabled", Boolean.TRUE, Boolean.FALSE);
                }
            }
        }
    }

    protected class ExportViewEnabledPropertyChangeListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();

            if (propertyName.equals("enabled")) {

                boolean newV = ((Boolean) e.getNewValue()).booleanValue();

                if (newV && (removeViewAction.isEnabled())) {
                    exportViewAction.firePropertyChange("enabled", Boolean.FALSE, Boolean.TRUE);
                } else if (!newV && (!closeViewAction.isEnabled())) {
                    exportViewAction.firePropertyChange("enabled", Boolean.TRUE, Boolean.FALSE);
                }
            }
        }
    }


    protected class ChangeViewNameEnabledPropertyChangeListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent e) {
            String propertyName = e.getPropertyName();

            if (propertyName.equals("enabled")) {

                boolean newV = ((Boolean) e.getNewValue()).booleanValue();

                if (newV && (removeViewAction.isEnabled())) {
                    changeViewNameAction.firePropertyChange("enabled", Boolean.FALSE, Boolean.TRUE);
                } else if (!newV && (!closeViewAction.isEnabled())) {
                    changeViewNameAction.firePropertyChange("enabled", Boolean.TRUE, Boolean.FALSE);
                }
            }
        }
    }

    /**
     * Action definition of the ProjectManager
     */
    class NewProjectAction extends ProjectAction {
        public NewProjectAction() {
            this.putValue(Action.NAME, "�½���Ŀ...");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/new_prj.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "�½�һ��������ģ��Ŀ");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (uiJPanel == null) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            JPanel jPanel = (JPanel) this.getValue(ConstantDefinition.UI_JPANEL);

            projectInfoPane.setContainer(jPanel);

            projectInfoPane.setProjectNameEditable(true);
            projectInfoPane.setDomainNameEditable(true);
            projectInfoPane.setDescriptionEditable(true);
            projectInfoPane.setPathEditable(true);

            projectInfoPane.clear();
            projectInfoPane.setMode(ProjectInfoPane.NEW_PROJECT_MODE);

            for (; ;) {
                int result = JOptionPane.showConfirmDialog(jPanel, projectInfoPane, "������Ŀ����", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);

                if (result == JOptionPane.OK_OPTION) {
                    if (projectInfoPane.isInfoValid() == false) {
                        JOptionPane.showMessageDialog(jPanel, projectInfoPane.getErrorInfo(), "���洰��", JOptionPane.ERROR_MESSAGE);
                        continue;
                    } else {
                        Project project = new ProjectImplementation(projectInfoPane.getProjectName(),
                                projectInfoPane.getDomainName(),
                                projectInfoPane.getDescription(),
                                projectInfoPane.getProjectFile());

                        FComponent featureModel = null;

                        ManagerInterface mi = de.FeatureModellingTool.FeatureModel.Manager.getInstance();

                        mi.getContext().putValue(de.FeatureModellingTool.FeatureModel.Manager.NAME_CONTEXT, project.getDomainName());
                        mi.getContext().putValue(de.FeatureModellingTool.FeatureModel.Manager.DESCRIPTION_CONTEXT, project.getDescription());

                        try {
                            featureModel = (FComponent) mi.getInstance(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_MODEL_NAME, FComponent.class);
                        } catch (IllegalParameterException ipe) {
                            System.out.println(ipe);
                        }

                        ProjectManager newProjectManager = de.FeatureModellingTool.ProjectManager.Manager.createProjectManager();
                        newProjectManager.getContext().putValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.PROJECT, project);
                        newProjectManager.getContext().putValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.FEATURE_MODEL, featureModel);
                        newProjectManager.getContext().putValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.INFOMATION_MAP, new GroupTreeMap());

                        newProjectManager.getAction(de.FeatureModellingTool.ProjectManager.ConstantDefinition.SAVE_PROJECT_ACTION).actionPerformed((ActionEvent) null);
                        newProjectManager.getAction(de.FeatureModellingTool.ProjectManager.ConstantDefinition.SAVE_PROJECT_TODB_ACTION).actionPerformed((ActionEvent) null);

                        this.firePropertyChange(ConstantDefinition.PROJECT_CREATED, null, newProjectManager);
                    }
                }

                break;
            }
        }

    }
    /**
     *
     * @author baipeng {baipeng8608@gmail.com}
     *
     *  2009-4-2
     */
    class OpenProjectFromDBAction extends ProjectAction{
      protected IProjectReader projectReader = new ProjectReaderFromDataBase();
      protected int modelID  = -1 ;
      public OpenProjectFromDBAction(){
        this.putValue(Action.NAME, "�����ݿ����Ŀ");
        this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/open_prj.png")));
        this.putValue(Action.SHORT_DESCRIPTION, "�����ݿ��һ��������ģ��Ŀ");
      }
       public boolean isEnabled() {
             if (!super.isEnabled()) return false;
             if (uiJPanel == null) return false;

             return true;
         }
    public void actionPerformed(ActionEvent e) {
      if(!isEnabled()) return;
      List<FileModel> models = null;
      try{
        models = FileModelService.getFileModels();
      }catch(Exception exception){
        exception.printStackTrace();
      }
      /**
       * ģ�� OpenProjectFromDBAction �е�д��,������ֵ�� APPROVEDʱ,ִ������IJ���,���򷵻�.
       */
      if(modelChooser.showOpenDialog(uiJPanel,models)==JModelChooser.APPROVE_OPTION){
        modelID = modelChooser.getSelectedModelID();
      }else{
        return ;
      }

      System.out.println("modelID = " +modelID);
      FileModel model = null;
      try{
        model =FileModelService.buildFileModel(modelID);
      }catch(Exception ex){
        ex.printStackTrace();
      }
      projectReader.setDataSource(model);
      boolean result = projectReader.readProject();
            if (result == false) {
                JOptionPane.showInternalMessageDialog(uiJPanel, projectReader.getErrorInfo(), "������Ϣ����", JOptionPane.ERROR_MESSAGE);
                return;
            }
            String domainName = projectReader.getDomainName();
            String[] viewNameArray = projectReader.getViewNameArray();
            Drawing[] drawingArray = projectReader.getDrawingArray();
            GroupMap informationMap = projectReader.getInformationMap();
            FComponent featureModel = projectReader.getFeatureModel();

            ProjectImplementation pi = new ProjectImplementation();
            pi.setProjectId(modelID);
            pi.setProjectName(model.getName());
            pi.setDomainName(domainName);
            for (int i = 0; i < viewNameArray.length; i++)
                pi.addView(viewNameArray[i]);

            ProjectManagerImplementation pmi = new ProjectManagerImplementation();
            pmi.getContext().putValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.PROJECT, pi);
            pmi.getContext().putValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.FEATURE_MODEL, featureModel);
            pmi.getContext().putValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.DRAWING_ARRAY, drawingArray);
            pmi.getContext().putValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.INFOMATION_MAP, informationMap);

            this.firePropertyChange(ConstantDefinition.PROJECT_OPENED, null, pmi);

    }
    }
    class OpenProjectAction extends ProjectAction {

        protected javax.swing.filechooser.FileFilter fileFilter = new CommonFileFilter("fmp", "Feature Model Project Files (*.fmp)");
        protected IProjectReader projectReader = new ProjectReader();
        public OpenProjectAction() {
            this.putValue(Action.NAME, "����Ŀ");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/open_prj.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "��һ��������ģ��Ŀ");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (uiJPanel == null) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            fileChooser.setDialogTitle("ѡ����Ŀ�ļ�");
            fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

            fileChooser.setFileFilter(fileFilter);

            File selectedFile = null;

            if (fileChooser.showOpenDialog(uiJPanel) == JFileChooser.APPROVE_OPTION) {
                selectedFile = fileChooser.getSelectedFile();
            } else {
                fileChooser.resetChoosableFileFilters();
                return;
            }

            // Load and parse the selectedFile.

            projectReader.setDataSource(selectedFile);
            boolean result = projectReader.readProject();
            if (result == false) {
                JOptionPane.showInternalMessageDialog(uiJPanel, projectReader.getErrorInfo(), "������Ϣ����", JOptionPane.ERROR_MESSAGE);
                return;
            }

            String domainName = projectReader.getDomainName();
            String[] viewNameArray = projectReader.getViewNameArray();
            Drawing[] drawingArray = projectReader.getDrawingArray();
            GroupMap informationMap = projectReader.getInformationMap();
            FComponent featureModel = projectReader.getFeatureModel();

            ProjectImplementation pi = new ProjectImplementation();

            String projectName = selectedFile.getName();
            int lastIndex = projectName.lastIndexOf('.');
            pi.setProjectName(projectName.substring(0, lastIndex));
            pi.setStoreFile(selectedFile);

            pi.setDomainName(domainName);
            for (int i = 0; i < viewNameArray.length; i++)
                pi.addView(viewNameArray[i]);

            ProjectManagerImplementation pmi = new ProjectManagerImplementation();
            pmi.getContext().putValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.PROJECT, pi);
            pmi.getContext().putValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.FEATURE_MODEL, featureModel);
            pmi.getContext().putValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.DRAWING_ARRAY, drawingArray);
            pmi.getContext().putValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.INFOMATION_MAP, informationMap);

            this.firePropertyChange(ConstantDefinition.PROJECT_OPENED, null, pmi);
        }
    }

    class ModifyProjectPropertiesAction extends ProjectAction {

        public ModifyProjectPropertiesAction() {
            this.putValue(Action.NAME, "��Ŀ����...");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/pro_prj.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "�޸ĵ�ǰ��Ŀ������");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (uiJPanel == null) return false;
            if (project == null) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            projectInfoPane.setContainer(uiJPanel);
            projectInfoPane.setProjectNameEditable(false);
            projectInfoPane.setPathEditable(false);

            if (featureModelPropertyEditor != null) {
                projectInfoPane.setDomainNameEditable(true);
                projectInfoPane.setDescriptionEditable(true);
            } else {
                projectInfoPane.setDomainNameEditable(false);
                projectInfoPane.setDescriptionEditable(false);
            }

            projectInfoPane.setProjectName(project.getProjectName());
            projectInfoPane.setDomainName(project.getDomainName());
            projectInfoPane.setDescription(project.getDescription());
            projectInfoPane.setStoreDirectory(project.getStoreFile().getParent());

            projectInfoPane.setMode(ProjectInfoPane.MODIFY_PROPERTY_MODE);

            for (; ;) {
                int result = JOptionPane.showConfirmDialog(uiJPanel, projectInfoPane, "������Ŀ����", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);

                if (result == JOptionPane.OK_OPTION) {
                    if (projectInfoPane.isInfoValid() == false) {
                        JOptionPane.showMessageDialog(uiJPanel, projectInfoPane.getErrorInfo(), "���洰��", JOptionPane.ERROR_MESSAGE);
                        continue;

                    } else {
                        ProjectImplementation pi = (ProjectImplementation) project;

                        pi.setDomainName(projectInfoPane.getDomainName());
                        pi.setDescription(projectInfoPane.getDescription());

                        if (featureModelPropertyEditor != null) {
                            featureModelPropertyEditor.setName(projectInfoPane.getDomainName());
                            featureModelPropertyEditor.setDescription(projectInfoPane.getDescription());
                        }

                    }
                }

                break;
            }

        }
    }

    class SaveAsProjectAction extends ProjectAction {
        public SaveAsProjectAction() {
            this.putValue(Action.NAME, "�����Ŀ...");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/save_as_prj.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "��ǰ��Ŀ���Ϊ");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (uiJPanel == null) return false;
            if (project == null) return false;
            //if (drawingViewContainer == null) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            projectInfoPane.setContainer(uiJPanel);
            projectInfoPane.setProjectNameEditable(true);
            projectInfoPane.setPathEditable(true);

            if (featureModelPropertyEditor != null) {
                projectInfoPane.setDomainNameEditable(true);
                projectInfoPane.setDescriptionEditable(true);
            } else {
                projectInfoPane.setDomainNameEditable(false);
                projectInfoPane.setDescriptionEditable(false);
            }

            projectInfoPane.setProjectName(project.getProjectName());
            projectInfoPane.setDomainName(project.getDomainName());
            projectInfoPane.setDescription(project.getDescription());
            projectInfoPane.setStoreDirectory(project.getStoreFile().getParent());

            projectInfoPane.setMode(ProjectInfoPane.NEW_PROJECT_MODE);

            for (; ;) {
                int result = JOptionPane.showConfirmDialog(uiJPanel, projectInfoPane, "���������Ŀ����", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);

                if (result == JOptionPane.OK_OPTION) {
                    if (projectInfoPane.isInfoValid() == false) {
                        JOptionPane.showMessageDialog(uiJPanel, projectInfoPane.getErrorInfo(), "���洰��", JOptionPane.ERROR_MESSAGE);
                        continue;

                    } else {
                        ProjectImplementation pi = (ProjectImplementation) project;

                        pi.setProjectName(projectInfoPane.getProjectName());
                        pi.setDomainName(projectInfoPane.getDomainName());
                        pi.setDescription(projectInfoPane.getDescription());
                        pi.setStoreFile(projectInfoPane.getProjectFile());

                        if (featureModelPropertyEditor != null) {
                            featureModelPropertyEditor.setName(projectInfoPane.getDomainName());
                            featureModelPropertyEditor.setDescription(projectInfoPane.getDescription());
                        }

                        saveProjectAction.actionPerformed((ActionEvent) null);
                    }
                }

                break;
            }
        }
    }

    class SaveProjectToDBAction extends ProjectAction{
      private FileModel fileModel = null;
      public SaveProjectToDBAction(){
        this.putValue(Action.NAME, "������Ŀ�����ݿ���");
        this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/save_prj.png")));
        this.putValue(Action.SHORT_DESCRIPTION, "���浱ǰ��Ŀ�����ݿ���");
      }
      public boolean isEnabled(){
        if(!super.isEnabled()) return false;
        if(project == null) return false;
        return true;
      }
    /* (non-Javadoc)
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(ActionEvent e){
      if(!isEnabled()) return;
      try{
      System.out.println("SaveProjectToDBAction#actionPerformed");
      DrawingView[] drawingViews;

      if(drawingViewContainer!=null){
        drawingViews = drawingViewContainer.getAllDrawingViews();
      }else{
        drawingViews = new DrawingView[0];
      }
      FeatureModel fm = (FeatureModel) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_MODEL_INTERFACE);
            ConstraintModel cm = (ConstraintModel) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.CONSTRAINT_MODEL_INTERFACE);
            InteractionModel im = (InteractionModel) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.INTERACTION_MODEL_INTERFACE);
            //gh start
            CustomizationModel customizationModel = (CustomizationModel) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.CUSTOMIZATION_MODEL_INTERFACE);
            //gh end
            String index =  fm.getName();
            index += " "+drawingViews.length;
            for(int i = 0 ;i<drawingViews.length ;i++){
              index += " " + drawingViews[i].getDrawing().getTitle();
            }
            if(fileModel == null){
              fileModel = new FileModel();
              fileModel.setId(project.getProjectId());
              fileModel.setName(project.getProjectName());
              fileModel.setIndex(index);
            }
//          begin д������ģ�������ļ�
            FmdlParser parser = new FmdlParserPrototype();
            StringWriter sw = new StringWriter();
            try{
              parser.saveFmdl(sw,fm);
            }catch(Exception exce){
              exce.printStackTrace();
            }
            fileModel.setFeatureModel(sw.toString());
            // begin д��Լ��ģ�������ļ�
            sw.close();
            sw = new StringWriter();
            try{
              parser.saveCmdl(sw,cm,fm);
            }catch(Exception exec){
              exec.printStackTrace();
            }
            fileModel.setConstraintModel(sw.toString());

            // begin д�뽻��ģ�������ļ�
            sw.close();
            sw = new StringWriter();
            try{
              parser.saveImdl(sw, im, fm);
            }catch(Exception exec){
              exec.printStackTrace();
            }
            fileModel.setInteractionModel(sw.toString());
            // begin Write the project drawing content.
            sw.close();
            List<DrawModel> drawings  =new ArrayList<DrawModel>();
            AdaptedStandardStorageFormat storef =  new AdaptedStandardStorageFormat();
            try{
              for(int i = 0 ;i<drawingViews.length;i++){
                sw = new StringWriter();
                storef.store(sw, drawingViews[i].getDrawing());
                drawings.add(new DrawModel(drawingViews[i].getDrawing().getId(),drawingViews[i].getDrawing().getTitle(),sw.toString()));
                sw.close();
              }
              fileModel.setDraws(drawings);
            }catch(Exception exec){
              exec.printStackTrace();
            }
            //������Ϣ�Ͷ�����Ϣ��ʱ��������.
            try{
              FileModelService.updateModel(fileModel);
            }catch(Exception exec){
              exec.printStackTrace();
            }
      }catch(Exception exec){
        exec.printStackTrace();
      }

    }

    }
    class SaveProjectAction extends ProjectAction {
        public SaveProjectAction() {
            this.putValue(Action.NAME, "������Ŀ");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/save_prj.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "���浱ǰ��Ŀ");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (project == null) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;
            System.out.println("SaveProjectAction#actionPerformed!");
            File storeFile = project.getStoreFile();

            try {
                ZipOutputStream zipOutStream = new ZipOutputStream(new FileOutputStream(storeFile));

                DrawingView[] drawingViews;

                if (drawingViewContainer != null)
                    drawingViews = drawingViewContainer.getAllDrawingViews();
                else
                    drawingViews = new DrawingView[0];

                ByteArrayOutputStream bufferStream = new ByteArrayOutputStream();

                FeatureModel fm = (FeatureModel) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_MODEL_INTERFACE);
                ConstraintModel cm = (ConstraintModel) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.CONSTRAINT_MODEL_INTERFACE);
                InteractionModel im = (InteractionModel) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.INTERACTION_MODEL_INTERFACE);
                //gh start
                CustomizationModel customizationModel = (CustomizationModel) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.CUSTOMIZATION_MODEL_INTERFACE);
                //gh end

                //begin д����Ŀ�����ļ�
                StorableOutput textOutput = new StorableOutput(bufferStream);

                textOutput.writeString(fm.getName());
                textOutput.writeInt(drawingViews.length);
                for (int i = 0; i < drawingViews.length; i++) {
                    textOutput.writeString(drawingViews[i].getDrawing().getTitle());
                }
                textOutput.close();

                ZipEntry indexZipEntry = new ZipEntry("index.txt");
                zipOutStream.putNextEntry(indexZipEntry);
                bufferStream.writeTo(zipOutStream);
                zipOutStream.closeEntry();
                //end д����Ŀ�����ļ�

                bufferStream.reset();


                //begin д������ģ�������ļ�
                FmdlParser parser = new FmdlParserPrototype();
                parser.saveFmdl(bufferStream, fm);
                ZipEntry fmZipEntry = new ZipEntry(fm.getName() + ".fm");
                zipOutStream.putNextEntry(fmZipEntry);
                bufferStream.writeTo(zipOutStream);
                zipOutStream.closeEntry();
                //end д������ģ�������ļ�

                bufferStream.reset();

                //begin д��Լ��ģ�������ļ�
                parser.saveCmdl(bufferStream, cm, fm);
                ZipEntry cmZipEntry = new ZipEntry(fm.getName() + ".cm");
                zipOutStream.putNextEntry(cmZipEntry);
                bufferStream.writeTo(zipOutStream);
                zipOutStream.closeEntry();
                //end д��Լ��ģ�������ļ�

                bufferStream.reset();

                //begin д�뽻��ģ�������ļ�
                parser.saveImdl(bufferStream, im, fm);
                ZipEntry imZipEntry = new ZipEntry(fm.getName() + ".im");
                zipOutStream.putNextEntry(imZipEntry);
                bufferStream.writeTo(zipOutStream);
                zipOutStream.closeEntry();
                //end д�뽻��ģ�������ļ�

                bufferStream.reset();

                //begin д����Ŀ��ͼ�ļ�
                AdaptedStandardStorageFormat store = new AdaptedStandardStorageFormat();
                for (int i = 0; i < drawingViews.length; i++) {
                    store.store(bufferStream, drawingViews[i].getDrawing());
                    ZipEntry viewZipEntry = new ZipEntry((String) drawingViews[i].getDrawing().getTitle() + ".draw");
                    zipOutStream.putNextEntry(viewZipEntry);
                    bufferStream.writeTo(zipOutStream);
                    zipOutStream.closeEntry();

                    bufferStream.reset();
                }
                //end д����Ŀ��ͼ�ļ�

                bufferStream.reset();

                //begin д��������Ϣ
                GroupMap informationMap = (GroupMap) ProjectManagerImplementation.this.getContext().getValue(de.FeatureModellingTool.ProjectManager.ConstantDefinition.INFOMATION_MAP);

                Iterator iterator = informationMap.keySet().iterator();
                while (iterator.hasNext()) {
                    String id = (String) iterator.next();
                    Set set = informationMap.get(id);

                    if (set != null) {
                        Iterator valueIterator = set.iterator();
                        while (valueIterator.hasNext()) {
                            Drawing drawing = (Drawing) valueIterator.next();
                            store.store(bufferStream, drawing);
                            ZipEntry drawingEntry = new ZipEntry(id + "\\" + drawing.getTitle() + ".draw");
                            zipOutStream.putNextEntry(drawingEntry);
                            bufferStream.writeTo(zipOutStream);
                            zipOutStream.closeEntry();

                            bufferStream.reset();
                        }
                    }
                }
                //end д��������Ϣ

                //begin д�붨����Ϣ
                //gh start
                CmdlParser cParser = new CmdlParserPrototype();

                cParser.saveCustomizationModel(bufferStream , customizationModel);
                ZipEntry customizationZipEntry = new ZipEntry("customization_index.txt");
                zipOutStream.putNextEntry(customizationZipEntry);
                bufferStream.writeTo(zipOutStream);
                zipOutStream.closeEntry();
                bufferStream.reset();

                for (Iterator<String> itCVId = customizationModel.getCustomizationVersionIds().iterator() ; itCVId.hasNext() ; ) {
                  String cvId = itCVId.next();

                  cParser.saveCustomizationVersion(bufferStream , customizationModel.getCustomizationVersion(cvId));
                  ZipEntry cvZipEntry = new ZipEntry(cParser.getCustomizationVersionFileName(cvId));
                  zipOutStream.putNextEntry(cvZipEntry);
                  bufferStream.writeTo(zipOutStream);
                  zipOutStream.closeEntry();

                  bufferStream.reset();
                }
                //gh end
                //end д�붨����Ϣ

                zipOutStream.finish();
                zipOutStream.close();

            } catch (Exception exception) {
                System.out.println("Exception occurs when save current project.\n" + exception);
            }
        }
    }

    class CloseProjectAction extends ProjectAction {
        public CloseProjectAction() {
            this.putValue(Action.NAME, "�ر���Ŀ...");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/close_prj.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "�رյ�ǰ��Ŀ");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (uiJPanel == null) return false;
            if (project == null) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {

            if (!isEnabled()) return;

            System.out.println("CloseProjectAction#actionPerformed()");
            int result = JOptionPane.showConfirmDialog(uiJPanel, "�Ƿ񱣴����ϴδ��̲�����������Ŀ���޸�", "����ȷ�ϴ���", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);

            if (result == JOptionPane.CANCEL_OPTION)
                return;

            //�洢��Ŀ�ļ�
            if (result == JOptionPane.YES_OPTION) {
              //TODO ����Ҫ���浽 ���ݿ���, ������ܺ����ټӽ���.
                Action saveAction = (Action) data.get(ConstantDefinition.SAVE_PROJECT_ACTION);
                if ((saveAction != null) && (saveAction.isEnabled())) {
                    saveAction.actionPerformed(e);
                } else {
                    int rst = JOptionPane.showConfirmDialog(uiJPanel, "�޷�������Ŀ�洢ģ�飬�Ƿ�����ر���Ŀ�IJ�����/n����������ϴδ��̺���޸Ľ��޷�������", "���洰��", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                    if (rst == JOptionPane.CANCEL_OPTION)
                        return;
                }
            }

            context.putValue(ConstantDefinition.CLOSE_REQUEST, Boolean.TRUE);
        }
    }

    class NewViewAction extends ProjectAction {
        public NewViewAction() {
            this.putValue(Action.NAME, "�½���ͼ...");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/new_view.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "�½�һ��������ͼ");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (uiJPanel == null) return false;
            if (project == null) return false;
            if (graphicalEditorActionMap == null) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            for (; ;) {
                int result = JOptionPane.showConfirmDialog(uiJPanel, viewInfoPane, "�½���ͼ", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);

                if (result == JOptionPane.OK_OPTION) {
                    if (viewInfoPane.isInfoValid() == false) {
                        JOptionPane.showMessageDialog(uiJPanel, viewInfoPane.getErrorInfo(), "���洰��", JOptionPane.ERROR_MESSAGE);
                        continue;
                    } else {
                        if (project.contains(viewInfoPane.getViewName())) {
                            JOptionPane.showMessageDialog(uiJPanel, "��ͬ���ֵ���ͼ�Ѿ����ڣ�", "���洰��", JOptionPane.ERROR_MESSAGE);
                            continue;
                        }
                    }
                } else {
                    return;
                }

                break;
            }

            ((ProjectImplementation) project).addView(viewInfoPane.getViewName());

            Action addViewAction = (Action) graphicalEditorActionMap.getInterface("addView");
            addViewAction.putValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.VIEW_NAME, viewInfoPane.getViewName());
            addViewAction.actionPerformed(null);

        }
    }

    class OpenViewAction extends ProjectAction {
        public OpenViewAction() {
            this.putValue(Action.NAME, "����ͼ");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/close_view.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "��������ͼ");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (uiJPanel == null) return false;
            if (project == null) return false;
            if (project.getViewNum() <= 0) return false;
            if (graphicalEditorActionMap == null) return false;
            if (!((Action) graphicalEditorActionMap.getInterface("openView")).isEnabled()) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            //will add in the future.
        }
    }

    class CloseViewAction extends ProjectAction {
        public CloseViewAction() {
            this.putValue(Action.NAME, "�ر���ͼ");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/close_view.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "�رյ�ǰ������ͼ");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (uiJPanel == null) return false;
            if (project == null) return false;
            if (project.getViewNum() <= 0) return false;
            if (graphicalEditorActionMap == null) return false;
            if (!((Action) graphicalEditorActionMap.getInterface("closeView")).isEnabled()) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            Action closeView = (Action) graphicalEditorActionMap.getInterface("closeView");

            closeView.actionPerformed(null);
            String viewName = (String) closeView.getValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.VIEW_NAME);
            closeView.putValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.VIEW_NAME, null);

        }
    }

    class RemoveViewAction extends ProjectAction {
        public RemoveViewAction() {
            this.putValue(Action.NAME, "ɾ����ͼ...");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/remove_view.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "ɾ����ǰ������ͼ");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (uiJPanel == null) return false;
            if (project == null) return false;
            if (project.getViewNum() <= 0) return false;
            if (graphicalEditorActionMap == null) return false;
            if (!((Action) graphicalEditorActionMap.getInterface("removeView")).isEnabled()) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            Action removeView = (Action) graphicalEditorActionMap.getInterface("removeView");

            int result = JOptionPane.showConfirmDialog(uiJPanel, "�����Ҫ����Ŀ��ɾ����ǰ��ͼ��?\n�ڴ��̺�,�⽫��ɲ�����صĺ��.\n(������ͨ���������̵ķ�ʽ,�ָ��ϴδ��̺�ɾ�����޸ĵ���ͼ)", "ɾ����ͼ", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);

            if (result != JOptionPane.OK_OPTION)
                return;

            removeView.actionPerformed(null);
            String viewName = (String) removeView.getValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.VIEW_NAME);
            removeView.putValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.VIEW_NAME, null);

            ((ProjectImplementation) project).removeView(viewName);
        }

    }

    class ChangeViewNameAction extends ProjectAction {
        public ChangeViewNameAction() {
            this.putValue(Action.NAME, "�޸ĵ�ǰ��ͼ����");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/change_view_name.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "�޸ĵ�ǰ������ͼ����");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (uiJPanel == null) return false;
            if (project == null) return false;
            if (project.getViewNum() <= 0) return false;
            if (graphicalEditorActionMap == null) return false;
            if (!((Action) graphicalEditorActionMap.getInterface("changeViewName")).isEnabled()) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            Action changeViewName = (Action) graphicalEditorActionMap.getInterface("changeViewName");

            JTextField nameField = new JTextField(15);

            String oldName = (String)changeViewName.getValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.CURRENT_VIEW_NAME);

            nameField.setText(oldName);
            int result = JOptionPane.showConfirmDialog(uiJPanel, nameField, "�޸ĵ�ǰ��ͼ����", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);

            if (result != JOptionPane.OK_OPTION)
                return;

            String newName = nameField.getText();

            if (newName.equals(oldName))
                return;

            if (newName.trim().equals("")){
                JOptionPane.showMessageDialog(uiJPanel, "��ͼ���Ʋ���Ϊ��,�޸�ʧ�ܣ�", "���洰��", JOptionPane.ERROR_MESSAGE);
                return;
            }

            if (project.contains(newName)){
                JOptionPane.showMessageDialog(uiJPanel, "��ͬ���Ƶ���ͼ�Ѿ�����,�޸�ʧ�ܣ�", "���洰��", JOptionPane.ERROR_MESSAGE);
                return;
            }

            changeViewName.putValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.NEW_VIEW_NAME, newName);
            changeViewName.actionPerformed(null);
            String resultNewViewName = (String) changeViewName.getValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.NEW_VIEW_NAME);
            String resultOldViewName = (String) changeViewName.getValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.OLD_VIEW_NAME);

            if (!newName.equals(resultNewViewName) || !oldName.equals(resultOldViewName)){
                JOptionPane.showMessageDialog(uiJPanel, "�ڲ�����,�޸�ʧ�ܣ�", "���洰��", JOptionPane.ERROR_MESSAGE);
                return;
            }

            changeViewName.putValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.NEW_VIEW_NAME, null);
            changeViewName.putValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.OLD_VIEW_NAME, null);

            ((ProjectImplementation) project).changeViewName(oldName, newName);
        }

    }

    class ExportViewAction extends ProjectAction {

        protected javax.swing.filechooser.FileFilter gifFileFilter = new CommonFileFilter("gif", "GIF Image Files (*.gif)");
        protected javax.swing.filechooser.FileFilter svgFileFilter = new CommonFileFilter("svg", "Scalable Vector Graphics (*.svg)");
        protected javax.swing.filechooser.FileFilter moreFileFilter = new CommonFileFilter("more", "More Other Graphic Format (*.*)");

        public ExportViewAction() {
            this.putValue(Action.NAME, "�����ͼ...");
            this.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("image/export_view.png")));
            this.putValue(Action.SHORT_DESCRIPTION, "�ѵ�ǰ������ͼ���Ϊͼ��");
        }

        public boolean isEnabled() {
            if (!super.isEnabled()) return false;
            if (uiJPanel == null) return false;
            if (project == null) return false;
            if (project.getViewNum() <= 0) return false;
            if (graphicalEditorActionMap == null) return false;

            return true;
        }

        public void actionPerformed(ActionEvent e) {
            if (!isEnabled()) return;

            //begin: get the image file's path from user
            File imageFile = null;

            fileChooser.setDialogTitle("��ͼ����Ϊͼ���ļ�");
            fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);

            FileFilter[] oldFilter = fileChooser.getChoosableFileFilters();

            for (int i = 0; i < oldFilter.length; i++) {
                fileChooser.removeChoosableFileFilter(oldFilter[i]);
            }

            fileChooser.addChoosableFileFilter(gifFileFilter);
            fileChooser.addChoosableFileFilter(svgFileFilter);
            fileChooser.addChoosableFileFilter(moreFileFilter);
            fileChooser.setFileFilter(gifFileFilter);

            PropertyChangeListener fileFilterChangeListener = new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent e) {
                    CommonFileFilter ff = (CommonFileFilter) e.getNewValue();

                    if (!e.getPropertyName().equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY))
                        return;

                    if (ff.getSuffix().equalsIgnoreCase("more")) {
                        fileChooser.cancelSelection();
                        Action action = (Action) graphicalEditorActionMap.getInterface("exportView");
                        action.putValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.IMAGE_TYPE, "more");
                        action.putValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.UI_FRAME, uiJPanel);
                        action.actionPerformed(null);
                        ((JFileChooser) e.getSource()).removePropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, this);
                    }
                }
            };

            fileChooser.addPropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, fileFilterChangeListener);

            for (; ;) {
                if (fileChooser.showDialog(uiJPanel, null) == JFileChooser.APPROVE_OPTION) {
                    imageFile = fileChooser.getSelectedFile();
                    CommonFileFilter currentFilter = (CommonFileFilter) fileChooser.getFileFilter();

                    if (!currentFilter.getSuffix().equalsIgnoreCase(CommonFileFilter.getSuffix(imageFile))) {
                        String path = imageFile.getPath() + "." + currentFilter.getSuffix();
                        imageFile = new File(path);
                    }

                    if (imageFile.exists()) {
                        int result_tmp = JOptionPane.showConfirmDialog(uiJPanel, "�ļ� " + imageFile.getPath() + " �Ѿ����ڣ��Ƿ񸲸Ǹ��ļ���", "ȷ�ϴ���", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);

                        if (result_tmp == JOptionPane.YES_OPTION) {
                            break;
                        } else {
                            continue;
                        }
                    }

                    break;
                } else {
                    break;
                }
            }

            fileChooser.removePropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, fileFilterChangeListener);

            CommonFileFilter selectedFilter = (CommonFileFilter) fileChooser.getFileFilter();

            fileChooser.removeChoosableFileFilter(moreFileFilter);
            fileChooser.removeChoosableFileFilter(svgFileFilter);
            fileChooser.removeChoosableFileFilter(gifFileFilter);

            for (int i = 0; i < oldFilter.length; i++) {
                fileChooser.addChoosableFileFilter(oldFilter[i]);
            }
            fileChooser.setSelectedFile(null);
            //end: get the image file's path from user

            //begin:
            if (imageFile == null)
                return;

            if (!imageFile.exists()) {
                try {
                    imageFile.createNewFile();
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(uiJPanel, "�������ļ�ʧ��,����洢�豸�Ƿ�������", "���洰��", JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }
            //end:

            Action action = (Action) graphicalEditorActionMap.getInterface("exportView");
            action.putValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.FILE, imageFile);
            action.putValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.IMAGE_TYPE, selectedFilter.getSuffix());
            action.putValue(de.FeatureModellingTool.GraphicalEditor.ConstantDefinition.UI_FRAME, uiJPanel);
            action.actionPerformed(null);
        }
    }

    abstract class ProjectAction extends AbstractAction {
        public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
            super.firePropertyChange(propertyName, oldValue, newValue);
        }
    }
}
TOP

Related Classes of de.FeatureModellingTool.ProjectManager.ProjectManagerImplementation$CloseViewAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.
y>