码迷,mamicode.com
首页 > 其他好文 > 详细

5.27save

时间:2014-05-29 07:56:21      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:style   c   class   blog   code   java   

bubuko.com,布布扣
public void doSave(IProgressMonitor monitor) {
        // TODO Auto-generated method stub

        performSave(monitor, getEditorInput()); 自定义的一个save函数,作用是?
        getCommandStack().markSaveLocation();

Marks the last executed or redone Command as the point at which the changes were saved. Calculation of isDirty() will be based on this checkpoint.


    }
bubuko.com,布布扣
bubuko.com,布布扣
public void doSaveAs() {
        // TODO Auto-generated method stub
        
        Shell shell = getSite().getShell();
        final IEditorInput input = getEditorInput();IEditorInput是什么?
         
        
        SaveAsDialog dialog = new SaveAsDialog(shell);建立一个save as的dialog

        IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile(): null;
               if (original != null){
            dialog.setOriginalFile(original);}
                
            dialog.create(); 这个是用来做什么?

creates this window‘s widgetry in a new top-level shell.

The default implementation of this framework method creates this window‘s shell (by calling createShell),

and its controls (by calling createContents),

then initializes this window‘s shell bounds (by calling initializeBounds). 

            int result = dialog.open();返回值是ok或者cancel
                    if (result == Window.CANCEL) {
                return;这个return到哪里去?
            }



IPath filePath
= dialog.getResult();the path, or null if Cancel was pressed IFile file = null;
if (filePath == null) { return; } else { file = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);通过路径找到文件。 } if (input.exists()) { } else { dialog.setErrorMessage(null); dialog.setMessage(WARN_FILEEXIST, IMessageProvider.WARNING); return; } if(file.exists()){ }else{ try { file.create(ResourceURLHelper.getNullInputStream(), true, null); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } DiagramEditorInput newInput = new DiagramEditorInput(file.getLocation()); performSave(getProgressMonitor(),newInput); }
bubuko.com,布布扣
bubuko.com,布布扣
public boolean isSaveAsAllowed() {
        // TODO Auto-generated method stub
        return true;
    }
bubuko.com,布布扣
bubuko.com,布布扣
private void performSave(IProgressMonitor monitor, IEditorInput input) {
        if (diagram == null)
            return;
        同样的问题,return到哪里去?
        diagram.doSaveXML();自定义save函数
        Document xmlTree = diagram.getDiagramDoc();自定义函数

        if (xmlTree == null)
            return;

        IFile file = ResourceUtil.getFile(getEditorInput());

        OutputFormat format = OutputFormat.createPrettyPrint();
        try {
            FileWriter fileWriter;
            fileWriter = new FileWriter((String) input.getAdapter(Path.class));

            XMLWriter writer = new XMLWriter(fileWriter, format);
            writer.write(xmlTree);
            writer.close();

            if (file != null) {
                file.refreshLocal(IResource.DEPTH_ZERO,
                        new NullProgressMonitor());
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
bubuko.com,布布扣

 

 

5.27save,布布扣,bubuko.com

5.27save

标签:style   c   class   blog   code   java   

原文地址:http://www.cnblogs.com/liyuhui20093357/p/3755965.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!