Changeset 1340

Show
Ignore:
Timestamp:
11/07/06 09:07:52 (2 years ago)
Author:
dsugar
Message:

Automatically close the graphical editor when the project is closed is deleted.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/gefeditor/src/com/tresys/framework/plugin/editor/policy/graphic/GraphicPolicyEditor.java

    r1337 r1340  
    4040import org.eclipse.jface.viewers.SelectionChangedEvent; 
    4141import org.eclipse.jface.viewers.StructuredSelection; 
     42import org.eclipse.swt.widgets.Display; 
    4243import org.eclipse.swt.widgets.Shell; 
    4344import org.eclipse.ui.IEditorInput; 
     
    4950import org.eclipse.ui.IWorkbenchPart; 
    5051import org.eclipse.ui.texteditor.IDocumentProvider; 
     52import org.eclipse.ui.texteditor.IDocumentProviderExtension2; 
     53import org.eclipse.ui.texteditor.IElementStateListener; 
     54import org.eclipse.ui.texteditor.IElementStateListenerExtension; 
    5155import org.eclipse.ui.views.contentoutline.IContentOutlinePage; 
    5256import org.eclipse.ui.views.properties.PropertySheetPage; 
     
    8084        private PolicyInformation policyInfo = null; 
    8185        private PolicyDiagramEditPart m_diagramEditPart = null; 
     86        private IElementStateListener fElementStateListener= new ElementStateListener(); 
     87 
    8288         
    8389        public static final String ID = SEFramework_Plugin.PLUGIN_ID + ".GraphicPolicyEditor";  //$NON-NLS-1$ 
     
    101107                { 
    102108                        FrameworkNavigator nav = (FrameworkNavigator)ivp; 
    103                         if(getViewer() != null) { 
     109                        if(getViewer() != null)  
     110                        { 
    104111                                getViewer().removeSelectionChangedListener(nav); 
    105112                                nav.getSynchronizer().removeViewer(getViewer()); 
     
    107114                } 
    108115                 
     116                if (fElementStateListener != null)  
     117                { 
     118                        m_provider.removeElementStateListener(fElementStateListener); 
     119                        fElementStateListener= null; 
     120                } 
    109121        } 
    110122         
     
    257269                final PolicyDiagram model = getModel(); 
    258270 
    259                 //TODO - cast could be bad if opened from 'File -> Open' rather then from the Nagivator 
     271                //TODO - cast could be bad if opened from 'File -> Open' rather then from the Navigator 
    260272                final IFile file = ((IFileEditorInput) input).getFile(); 
    261273                IContainer parentDir = file.getParent(); 
     
    266278                final FSysGenerator fsys = new FSysGenerator (); 
    267279                IShapeVisitor fsysGen = new GraphicPolicyMetaVisitor (fsys); 
    268 //              System.out.println("Generate .fsys"); 
     280//              System.out.println("Generate '.fsys'"); 
    269281                model.Accept(fsysGen); 
    270282 
     
    319331                return false; 
    320332        } 
     333 
     334        protected void setDocumentProvider (IEditorInput input) 
     335        { 
     336                 
     337        } 
    321338         
    322339        protected void setInput (IEditorInput input)  
     
    345362                try  
    346363                { 
    347  
    348364                        String metaFileName = getBaseFilename () + "." + FrameworkBuilder.m_mdlExt; 
    349365                        IFile metaFile = parentDir.getFile(new Path (metaFileName)); 
     
    358374                catch (Exception e)  
    359375                { 
    360                         // TODO Auto-generated catch block 
    361376                        e.printStackTrace(); 
    362377                } 
    363         } 
    364  
     378                 
     379                IProgressMonitor rememberedProgressMonitor= null; 
     380         
     381                IDocumentProvider provider= getDocumentProvider(); 
     382                if (provider != null) { 
     383                        provider.removeElementStateListener(fElementStateListener); 
     384                        if (provider instanceof IDocumentProviderExtension2) { 
     385                                IDocumentProviderExtension2 extension= (IDocumentProviderExtension2) provider; 
     386                                rememberedProgressMonitor= extension.getProgressMonitor(); 
     387                                extension.setProgressMonitor(null); 
     388                        } 
     389                } 
     390 
     391                setDocumentProvider(input); 
     392 
     393                provider= getDocumentProvider(); 
     394                if (provider != null) { 
     395                        provider.addElementStateListener(fElementStateListener); 
     396                        if (provider instanceof IDocumentProviderExtension2) { 
     397                                IDocumentProviderExtension2 extension= (IDocumentProviderExtension2) provider; 
     398                                extension.setProgressMonitor(rememberedProgressMonitor); 
     399                        } 
     400                } 
     401 
     402                 
     403                 
     404                if (fElementStateListener instanceof IElementStateListenerExtension)  
     405                { 
     406                        IElementStateListenerExtension extension= (IElementStateListenerExtension) fElementStateListener; 
     407                        extension.elementStateValidationChanged(input, false); 
     408                } 
     409 
     410        } 
     411 
     412         
     413         
    365414        private String getBaseFilename () 
    366415        { 
     
    407456 
    408457         
     458        /** 
     459         * Internal element state listener. 
     460         */ 
     461        class ElementStateListener  
     462                implements IElementStateListener //, IElementStateListenerExtension 
     463        { 
     464 
     465                private Display fDisplay; 
     466 
     467                /* 
     468                 * @see IElementStateListener#elementDirtyStateChanged(Object, boolean) 
     469                 */ 
     470                public void elementDirtyStateChanged(Object element, boolean isDirty) { 
     471                } 
     472 
     473                /* 
     474                 * @see IElementStateListener#elementContentAboutToBeReplaced(Object) 
     475                 */ 
     476                public void elementContentAboutToBeReplaced(Object element)  
     477                { 
     478                } 
     479 
     480                /* 
     481                 * @see IElementStateListener#elementContentReplaced(Object) 
     482                 */ 
     483                public void elementContentReplaced(Object element)  
     484                { 
     485                } 
     486 
     487                /* 
     488                 * @see IElementStateListener#elementDeleted(Object) 
     489                 */ 
     490                public void elementDeleted(Object deletedElement)  
     491                { 
     492                        if (deletedElement != null && deletedElement.equals(getEditorInput()))  
     493                        { 
     494                                Runnable r= new Runnable()  
     495                                { 
     496                                        public void run()  
     497                                        { 
     498                                                close(false); 
     499                                        } 
     500                                }; 
     501                                execute(r, false); 
     502                        } 
     503                } 
     504 
     505                /* 
     506                 * @see IElementStateListener#elementMoved(Object, Object) 
     507                 */ 
     508                public void elementMoved(final Object originalElement, final Object movedElement)  
     509                { 
     510                        if (originalElement != null && originalElement.equals(getEditorInput()))  
     511                        { 
     512                                Runnable r= new Runnable()  
     513                                { 
     514                                        public void run()  
     515                                        { 
     516                                                close(true); 
     517                                        } 
     518                                }; 
     519                                execute(r, false); 
     520                        } 
     521                } 
     522 
     523 
     524                /** 
     525                 * Executes the given runnable in the UI thread. 
     526                 * <p> 
     527                 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=76765 for details 
     528                 * about why the parameter <code>postAsync</code> has been 
     529                 * introduced in the course of 3.1. 
     530                 * 
     531                 * @param runnable runnable to be executed 
     532                 * @param postAsync <code>true</code> if the runnable must be posted asynchronous, <code>false</code> otherwise 
     533                 * @since 3.0 
     534                 */ 
     535                private void execute(Runnable runnable, boolean postAsync)  
     536                { 
     537                        if (postAsync || Display.getCurrent() == null)  
     538                        { 
     539                                if (fDisplay == null) 
     540                                        fDisplay= getSite().getShell().getDisplay(); 
     541                                fDisplay.asyncExec(runnable); 
     542                        } 
     543                        else 
     544                                runnable.run(); 
     545                } 
     546        } 
     547         
    409548        private PolicyDiagram getModel () 
    410549        { 
     
    423562        { 
    424563                 
     564        } 
     565         
     566        public void close (final boolean save) 
     567        { 
     568                Display display= getSite().getShell().getDisplay(); 
     569                display.asyncExec(new Runnable()  
     570                { 
     571                        public void run()  
     572                        { 
     573                                getSite().getPage().closeEditor(GraphicPolicyEditor.this, save); 
     574                        } 
     575                }); 
    425576        } 
    426577