Changeset 7345

Show
Ignore:
Timestamp:
04/28/08 22:56:26 (5 years ago)
Author:
stedwar2
Message:

Added a custom input type to represent components within waveforms.

Location:
ossiedev/branches/jsnyder/ComponentProject/src/edu/vt/ossie/editors
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • ossiedev/branches/jsnyder/ComponentProject/src/edu/vt/ossie/editors/ComponentEditor.java

    r7343 r7345  
    11package edu.vt.ossie.editors; 
    22 
     3import org.eclipse.core.resources.IFile; 
     4import org.eclipse.core.runtime.CoreException; 
    35import org.eclipse.core.runtime.IProgressMonitor; 
     6import org.eclipse.jface.dialogs.ErrorDialog; 
     7import org.eclipse.jface.resource.ImageDescriptor; 
    48import org.eclipse.swt.SWT; 
    59import org.eclipse.swt.custom.ScrolledComposite; 
     10import org.eclipse.swt.graphics.Image; 
    611import org.eclipse.swt.layout.FillLayout; 
    712import org.eclipse.swt.widgets.Button; 
    813import org.eclipse.swt.widgets.Combo; 
    914import org.eclipse.swt.widgets.Composite; 
     15import org.eclipse.swt.widgets.Display; 
    1016import org.eclipse.swt.widgets.Group; 
    1117import org.eclipse.swt.widgets.Label; 
     18import org.eclipse.swt.widgets.Shell; 
    1219import org.eclipse.swt.widgets.Table; 
    1320import org.eclipse.swt.widgets.Text; 
    1421import org.eclipse.swt.widgets.Tree; 
     22import org.eclipse.ui.IEditorDescriptor; 
    1523import org.eclipse.ui.IEditorInput; 
     24import org.eclipse.ui.IEditorPart; 
     25import org.eclipse.ui.IEditorRegistry; 
    1626import org.eclipse.ui.IEditorSite; 
     27import org.eclipse.ui.IFileEditorInput; 
    1728import org.eclipse.ui.PartInitException; 
     29import org.eclipse.ui.PlatformUI; 
    1830import org.eclipse.ui.part.EditorPart; 
    1931 
     
    6274        throws PartInitException 
    6375    { 
    64         // TODO Auto-generated method stub 
    65     } 
     76        setSite(site); 
     77        setInput(input); 
     78    } 
     79 
    6680 
    6781    // ---------------------------------------------------------- 
     
    6983    public boolean isDirty() 
    7084    { 
    71         // TODO Auto-generated method stub 
    72         return false; 
    73     } 
     85        return dirty; 
     86    } 
     87 
     88 
     89    // ---------------------------------------------------------- 
     90    public void setIsDirty(boolean changed) 
     91    { 
     92        if (isConnectedToFile()) 
     93        { 
     94            if (dirty != changed) 
     95            { 
     96                dirty = changed; 
     97                firePropertyChange(PROP_DIRTY); 
     98            } 
     99        } 
     100        else 
     101        { 
     102            // TODO: this is broken; 
     103            getComponentInput().getWaveformEditor().setIsDirty(changed); 
     104        } 
     105    } 
     106 
    74107 
    75108    // ---------------------------------------------------------- 
     
    77110    public boolean isSaveAsAllowed() 
    78111    { 
    79         // TODO Auto-generated method stub 
    80         return false; 
    81     } 
     112        IEditorInput input = getEditorInput(); 
     113        return input != null && input instanceof IFileEditorInput; 
     114    } 
     115 
    82116 
    83117    // ---------------------------------------------------------- 
     
    221255 
    222256 
     257    // ---------------------------------------------------------- 
     258    /* 
     259     * @see EditorPart#setInput(org.eclipse.ui.IEditorInput) 
     260     */ 
     261    @Override 
     262    public final void setInput(IEditorInput input) 
     263    { 
     264        System.out.println("ComponentEditor.setInput(): " + input.getName()); 
     265        setInputWithNotify(input); 
     266    } 
     267 
     268 
     269    // ---------------------------------------------------------- 
     270    public void close() 
     271    { 
     272        close(isConnectedToFile() && isDirty()); 
     273    } 
     274 
     275 
     276    // ---------------------------------------------------------- 
     277    public void close(final boolean save) 
     278    { 
     279        Display display= getSite().getShell().getDisplay(); 
     280        display.asyncExec(new Runnable() 
     281        { 
     282            public void run() 
     283            { 
     284                getSite().getPage().closeEditor(ComponentEditor.this, save); 
     285            } 
     286        }); 
     287    } 
     288 
     289 
     290    //~ Protected Methods ..................................................... 
     291 
     292    // ---------------------------------------------------------- 
     293    protected IFile getFile() 
     294    { 
     295        IFileEditorInput input = getFileInput(); 
     296        return input == null 
     297            ? null 
     298            : input.getFile(); 
     299    } 
     300 
     301 
     302    // ---------------------------------------------------------- 
     303    /* 
     304     * @see org.eclipse.ui.part.EditorPart#setInputWithNotify(org.eclipse.ui.IEditorInput) 
     305     * @since 3.2 
     306     */ 
     307    protected final void setInputWithNotify(IEditorInput input) 
     308    { 
     309        try 
     310        { 
     311            doSetInput(input); 
     312 
     313            /* 
     314             * The following bugs explain why we fire this property change: 
     315             *     https://bugs.eclipse.org/bugs/show_bug.cgi?id=90283 
     316             *     https://bugs.eclipse.org/bugs/show_bug.cgi?id=92049 
     317             *     https://bugs.eclipse.org/bugs/show_bug.cgi?id=92286 
     318             */ 
     319            firePropertyChange(IEditorPart.PROP_INPUT); 
     320        } 
     321        catch (CoreException x) 
     322        { 
     323            String title= "Problem while opening"; 
     324            String msg= "Cannot open input element:"; 
     325            Shell shell= getSite().getShell(); 
     326            ErrorDialog.openError(shell, title, msg, x.getStatus()); 
     327        } 
     328    } 
     329 
     330 
     331    // ---------------------------------------------------------- 
     332    /** 
     333     * Called directly from <code>setInput</code> and from within a workspace 
     334     * runnable from <code>init</code>, this method does the actual setting 
     335     * of the editor input. Closes the editor if <code>input</code> is 
     336     * <code>null</code>. Disconnects from any previous editor input and its 
     337     * document provider and connects to the new one. 
     338     * <p> 
     339     * Subclasses may extend. 
     340     * </p> 
     341     * 
     342     * @param input the input to be set 
     343     * @exception CoreException if input cannot be connected to the document 
     344     *            provider 
     345     */ 
     346    protected void doSetInput(IEditorInput input) 
     347        throws CoreException 
     348    { 
     349        if (input == null) 
     350        { 
     351            close(isConnectedToFile() && isSaveOnCloseNeeded()); 
     352        } 
     353        else 
     354        { 
     355            super.setInput(input); 
     356            // need to load the project 
     357            initializeTitle(input); 
     358 
     359            // TODO: refresh controls 
     360        } 
     361    } 
     362 
     363 
     364    //~ Private Methods ....................................................... 
     365 
     366    // ---------------------------------------------------------- 
     367    /** 
     368     * Initializes the editor's title based on the given editor input. 
     369     * 
     370     * @param input 
     371     *            the editor input to be use 
     372     */ 
     373    private void initializeTitle(IEditorInput input) 
     374    { 
     375        Image oldImage = titleImage; 
     376        titleImage = null; 
     377        String title = ""; 
     378 
     379        if (input != null) 
     380        { 
     381            IEditorRegistry editorRegistry = 
     382                PlatformUI.getWorkbench().getEditorRegistry(); 
     383            IEditorDescriptor editorDesc = 
     384                editorRegistry.findEditor(getSite().getId()); 
     385            ImageDescriptor imageDesc = editorDesc != null 
     386                ? editorDesc.getImageDescriptor() 
     387                : null; 
     388 
     389            titleImage = imageDesc != null ? imageDesc.createImage() : null; 
     390            title = input.getName(); 
     391        } 
     392 
     393        setTitleImage(titleImage); 
     394        setPartName(title); 
     395 
     396        firePropertyChange(PROP_DIRTY); 
     397 
     398        if (oldImage != null && !oldImage.isDisposed()) 
     399        { 
     400            oldImage.dispose(); 
     401        } 
     402    } 
     403 
     404 
     405    // ---------------------------------------------------------- 
     406    public boolean isConnectedToFile() 
     407    { 
     408        return getEditorInput() instanceof IFileEditorInput; 
     409    } 
     410 
     411 
     412    // ---------------------------------------------------------- 
     413    public IFileEditorInput getFileInput() 
     414    { 
     415        return isConnectedToFile() 
     416            ? (IFileEditorInput)getEditorInput() 
     417            : null; 
     418    } 
     419 
     420 
     421    // ---------------------------------------------------------- 
     422    public ComponentEditorInput getComponentInput() 
     423    { 
     424        return isConnectedToFile() 
     425            ? null 
     426            : (ComponentEditorInput)getEditorInput(); 
     427    } 
     428 
     429 
    223430    //~ Instance/static variables ............................................. 
    224431 
     
    240447    private Table  propertiesTable; 
    241448    private Tree   portsTree; 
     449 
     450    private boolean dirty; 
     451    private Image   titleImage; 
    242452} 
  • ossiedev/branches/jsnyder/ComponentProject/src/edu/vt/ossie/editors/OWDEditor.java

    r7344 r7345  
    821821    private void initializeTitle(IEditorInput input) 
    822822    { 
    823         Image oldImage= titleImage; 
    824         titleImage= null; 
    825         String title= ""; 
     823        Image oldImage = titleImage; 
     824        titleImage = null; 
     825        String title = ""; 
    826826 
    827827        if (input != null) 
     
    877877    private void openComponentInEditor(Component c) 
    878878    { 
    879         System.out.println("opening editor on " + c); 
     879//        System.out.println("opening editor on " + c); 
     880 
    880881        // Need to add our own kind of IEditorInput, but for now, 
    881882        // let's fake it by reusing our current file info 
    882883        try 
    883884        { 
    884             IFile dummy = ResourcesPlugin.getWorkspace().getRoot() 
    885                 .getFile(getFile().getFullPath().addFileExtension("cmp")); 
    886  
    887             getSite().getPage().openEditor( 
    888                 // TODO: replace this first parameter 
    889                 new FileEditorInput(dummy), 
    890                 ComponentEditor.EDITOR_ID); 
     885            ComponentEditorInput input = new ComponentEditorInput( 
     886                this, getActiveWaveform(), c); 
     887            getSite().getPage().openEditor(input, ComponentEditor.EDITOR_ID); 
    891888        } 
    892889        catch (Exception e) 
     
    10581055            { 
    10591056                openComponentInEditor((Component)subject); 
    1060                 setIsDirty(true); 
    10611057            } 
    10621058            catch(Exception e)