Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 42034

Summary: [Decorators] Adding a readonly decorator
Product: [Eclipse Project] Platform Reporter: Mickey Math <mathmickey>
Component: UIAssignee: Tod Creasey <Tod_Creasey>
Status: RESOLVED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P4 CC: dj.houghton, thomasf, Tod_Creasey
Version: 2.1Keywords: helpwanted
Target Milestone: ---   
Hardware: All   
OS: Windows 2000   
Whiteboard:
Attachments:
Description Flags
Original + modified eclipse source files (zip) none

Description Mickey Math CLA 2003-08-26 17:36:17 EDT
Hi Tod,

The readonly decorator impacts 2 packages:
- org.eclipse.core.resources_2.1.0
- org.eclipse.platform.source_2.1.0

Below you'll find a summary of changes. Better yet I can provide you with the set of new/modified files and their original counterparts so that to easily make a comparison. Or I can make another attempt with the 'Create Patch' stuff in CVS (couldn't make it works the first time).

Best regards,
Mickey
mathmickey@yahoo.com
---------------------------------------------------------------------------

CHANGES:
-------

The following changes have been done:

PACKAGE org.eclipse.ui.internal.dialogs.decorators (NEW)
--------------------------------------------------------
  - NEW class ReadOnlyDecorator that implements the lightweight decorator.
    extends LabelProvider, implements ILightweightLabelDecorator &
    IResourceChangeListener

    This is basically the same class than the one in the demo, with the
    following changes:
    - code cleaned out. No Image registry, no prefix/suffix. Only readonly
      status is supported.
    - The decorator implements IResourceChangeListener.
    - The DecoratorManager is registred as a listener to the
      ReadOnlyDecorator
    - The ReadOnlyDecorator is registred as a listener to the
      DecoratorManager
      (both are done to allow the update of the icon when the property
       sheet exit. It also allows to update the icon when a file is
       selected. This looks a bit too much to register both so there is
       probably a better way to do it)

    - static initializer:
      - add DecoratorManager to listeners of ReadOnlyDecorator
        (LabelProvider.addListener( " DecoratorManager " ))
      - add this to ResourceChangeListener of DecoratorManager.
        --> Listener added to notificationManager's list.
        --> activated by broadcastChanges/handleevent
        by calling IResourceChangeListener.resourceChanged(event)

    - public method refresh:
      - call this.fireLabelEvent
        --> will call LabelProvider.fireLabelProviderChanged(event) for
            current resource.
        --> will call ILabelProviderListener.labelproviderChanged(event)
            (ie. call DecoratorManager)
        --> if a non-NULL resource is given, DecoratorManager will call 
            scheduler to queue decoration request
            (otherwise, DecoratorManager will call the listeners, ie
             ReadOnlyDecorator).

    - public method resourceChanged
      - if resource != NULL and resource is a FILE and event == POST_CHANGE, 
        call this.refresh();

    - public method isLabelProperty
      - return true

    - public method decorate
      - simply add the lock image as overlay on resources of type FILE

    - public method getReadOnlyDecorator
      - if decorator is enabled, return a reference to the class 
        ReadOnlyDecorator

  - Added the image file lock.gif.

----------------------------------------------------------------------------
PACKAGE org.eclipse.ui.internal.dialogs
---------------------------------------
  - Modified class ResourceInfoPage.java
     - method PerformOk modified --> call ReadOnlyDecorator.refresh if 
       readonly changed.

----------------------------------------------------------------------------
PACKAGE org.eclipse.ui.internal.resources
-----------------------------------------
  - Modified class ResourceInfo.java

     - Added field syncReadOnly
     - Added getter and setter method.

  - Modified class SaveManager.java
     - Modified method readElement -->
       now read ReadOnly bit from the disk, and pass it to 
       info.readFrom(flags, input, readOnly)


----------------------------------------------------------------------------
PACKAGE org.eclipse.core.internal.localstore
--------------------------------------------
  - Modified class FileSystemResourceManager.java

     - Added new method updateLocalSync(ResourceInfo info, 
                                        long localSyncInfo, 
                                        boolean localSyncReadOnly)
       --> Also update the readonly state of info object.

  - Modified class RefreshLocalVisitor.java
     - Update method ResourceChanged 
       --> call now FileSystemResourceManager
                      .updateLocalSync(info,
                                       node.getLastModified(),
                                       node.isReadOnly())

     - Updated method CreateResource 
       --> call now FileSystemResourceManager
                      .updateLocalSync(info,
                                       sync.getLastModified(),
                                       read.isReadOnly())

     - Updated method visit -->
        Updated process of test " if (targetType == IResource.FILE &&
                                      node.isFile()) " as follows:
          long lastModifed = 
            target.getResourceInfo(false, false).getLocalSyncInfo();
          boolean lastReadOnly = 
            target.getResourceInfo(false, false).isLocalSyncReadOnly();
          if ( (lastModifed == node.getLastModified()) &&
               (lastReadOnly == node.isReadOnly()) )
            return true;

       ie. readonly is now compared with the stored value.
Comment 1 Mickey Math CLA 2003-08-26 18:24:42 EDT
Created attachment 5865 [details]
Original + modified eclipse source files (zip)

This zip file contains the original files from Eclipse SDK 2.1.0 and the
modified ones) so that to easily track the changes.
Only source files are included (jar files are too big)

Don't miss the README file.
Comment 2 Tod Creasey CLA 2003-08-27 15:42:17 EDT
Added DJ for a core perspective. 

This is an interesting idea but I think this can already be done in Eclipse. 
Any view that has resources has a resource change listener - is it the case 
that changing the read only flag does not fire the listener?

If it doesn't then you should log a PR. Another thing that the Eclipse 
Workbench is being careful to avoid is references to its own decorators as 
they are meant only as a passive object that labels are built from.

I think you can write this decorator without any changes from us but I am 
interested in why you needed to make them to be sure that we don't have more 
subtle problems somewhere.

Comment 3 Mickey Math CLA 2003-08-28 14:13:47 EDT
Thx for your feedback. I'll try to have a look this WE, and see whether a listener is fired, and if not, try to write an accurate explanation why I made those changes in the workbench.
Comment 4 Thomas Fletcher CLA 2003-10-09 08:55:05 EDT
I have seen several Eclipse users stumble when dealing with read-only
files, especially when working with external revision control systems.
Having some additional annotation in the editors as well as a label
decorator would definitely be worthwhile. 
Comment 5 Tod Creasey CLA 2003-10-10 14:01:46 EDT
Marking as help wanted as this interesting but not likely something we will 
have time for in the R3.0 timeframe.
Comment 6 Tod Creasey CLA 2006-04-07 10:24:09 EDT

*** This bug has been marked as a duplicate of 31299 ***