diff options
author | Jean Michel-Lemieux | 2004-09-20 14:37:42 +0000 |
---|---|---|
committer | Jean Michel-Lemieux | 2004-09-20 14:37:42 +0000 |
commit | 0ebc78a7d25b1b85063d7bb87736b78099c11962 (patch) | |
tree | 78a5b0597f9b472ad17d641dcf402583923e979f /bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java | |
parent | ed4cebd9cdfa62394682c39dc475348620134e08 (diff) | |
download | eclipse.platform.team-0ebc78a7d25b1b85063d7bb87736b78099c11962.tar.gz eclipse.platform.team-0ebc78a7d25b1b85063d7bb87736b78099c11962.tar.xz eclipse.platform.team-0ebc78a7d25b1b85063d7bb87736b78099c11962.zip |
Font and label support in the decorators. Also, decorator preference page has been reworked.
Diffstat (limited to 'bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java')
-rw-r--r-- | bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java | 416 |
1 files changed, 118 insertions, 298 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java index dc4dcf99f..aaa1f49f0 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java @@ -13,16 +13,12 @@ package org.eclipse.team.internal.ccvs.ui; import java.text.SimpleDateFormat; import java.util.*; - import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.widgets.Display; import org.eclipse.team.core.RepositoryProvider; import org.eclipse.team.internal.ccvs.core.*; @@ -30,118 +26,68 @@ import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption; import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; -import org.eclipse.team.internal.ccvs.core.util.*; +import org.eclipse.team.internal.ccvs.core.util.KnownRepositories; +import org.eclipse.team.internal.ccvs.core.util.ResourceStateChangeListeners; import org.eclipse.team.internal.core.ExceptionCollector; -import org.eclipse.team.internal.ui.TeamUIPlugin; -import org.eclipse.team.ui.ISharedImages; import org.eclipse.team.ui.TeamUI; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.themes.ITheme; public class CVSLightweightDecorator extends LabelProvider implements ILightweightLabelDecorator, IResourceStateChangeListener, IPropertyChangeListener { // Decorator id as defined in the decorator extension point public final static String ID = "org.eclipse.team.cvs.ui.decorator"; //$NON-NLS-1$ - - // Images cached for better performance - private static ImageDescriptor dirty; - private static ImageDescriptor checkedIn; - private static ImageDescriptor noRemoteDir; - private static ImageDescriptor added; - private static ImageDescriptor merged; - private static ImageDescriptor newResource; - private static ImageDescriptor edited; private static ExceptionCollector exceptions = new ExceptionCollector(Policy.bind("CVSDecorator.exceptionMessage"), CVSUIPlugin.ID, IStatus.ERROR, CVSUIPlugin.getPlugin().getLog()); //$NON-NLS-1$; private static String DECORATOR_FORMAT = "yyyy/MM/dd HH:mm:ss"; //$NON-NLS-1$ private static SimpleDateFormat decorateFormatter = new SimpleDateFormat(DECORATOR_FORMAT, Locale.getDefault()); - - /* - * Define a cached image descriptor which only creates the image data once - */ - public static class CachedImageDescriptor extends ImageDescriptor { - ImageDescriptor descriptor; - ImageData data; - public CachedImageDescriptor(ImageDescriptor descriptor) { - Assert.isNotNull(descriptor); - this.descriptor = descriptor; - } - public ImageData getImageData() { - if (data == null) { - data = descriptor.getImageData(); - } - return data; - } - } - - /** - * TODO: We should not be implementing IDecoration as it is - * not speced to be implemented by clients (see bug 72677) - */ - public static class Decoration implements IDecoration { - public String prefix, suffix; - public ImageDescriptor overlay; - - /** - * @see org.eclipse.jface.viewers.IDecoration#addPrefix(java.lang.String) - */ - public void addPrefix(String prefix) { - this.prefix = prefix; - } - /** - * @see org.eclipse.jface.viewers.IDecoration#addSuffix(java.lang.String) - */ - public void addSuffix(String suffix) { - this.suffix = suffix; - } - /** - * @see org.eclipse.jface.viewers.IDecoration#addOverlay(org.eclipse.jface.resource.ImageDescriptor) - */ - public void addOverlay(ImageDescriptor overlay) { - this.overlay = overlay; - } - /** (non-Javadoc) - * @see org.eclipse.jface.viewers.IDecoration#addOverlay(org.eclipse.jface.resource.ImageDescriptor, int) - */ - public void addOverlay(ImageDescriptor overlay, int quadrant) { - } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IDecoration#setForegroundColor(org.eclipse.swt.graphics.Color) - */ - public void setForegroundColor(Color color) { - // Ignore for now - - } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IDecoration#setBackgroundColor(org.eclipse.swt.graphics.Color) - */ - public void setBackgroundColor(Color color) { - // Ignore for now - - } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IDecoration#setFont(org.eclipse.swt.graphics.Font) - */ - public void setFont(Font color) { - // Ignore for now - } - } - static { - dirty = new CachedImageDescriptor(TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_DIRTY_OVR)); - checkedIn = new CachedImageDescriptor(TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_CHECKEDIN_OVR)); - added = new CachedImageDescriptor(TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_CHECKEDIN_OVR)); - merged = new CachedImageDescriptor(CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_MERGED)); - newResource = new CachedImageDescriptor(CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_QUESTIONABLE)); - edited = new CachedImageDescriptor(CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_EDITED)); - noRemoteDir = new CachedImageDescriptor(CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_NO_REMOTEDIR)); - } + private static String[] fonts = new String[] { + CVSDecoratorConfiguration.IGNORED_FONT, + CVSDecoratorConfiguration.OUTGOING_CHANGE_FONT}; + + private static String[] colors = new String[] { + CVSDecoratorConfiguration.OUTGOING_CHANGE_BACKGROUND_COLOR, + CVSDecoratorConfiguration.OUTGOING_CHANGE_FOREGROUND_COLOR, + CVSDecoratorConfiguration.IGNORED_BACKGROUND_COLOR, + CVSDecoratorConfiguration.IGNORED_FOREGROUND_COLOR}; public CVSLightweightDecorator() { ResourceStateChangeListeners.getListener().addResourceStateChangeListener(this); TeamUI.addPropertyChangeListener(this); CVSUIPlugin.addPropertyChangeListener(this); + + // This is an optimization to ensure that while decorating our fonts and colors are + // pre-created and decoration can occur without having to syncExec. + ensureFontAndColorsCreated(fonts, colors); + + PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().addPropertyChangeListener(this); CVSProviderPlugin.broadcastDecoratorEnablementChanged(true /* enabled */); } + + /** + * This method will ensure that the fonts and colors used by the decorator + * are cached in the registries. This avoids having to syncExec when + * decorating since we ensure that the fonts and colors are pre-created. + * + * @param fonts fonts ids to cache + * @param colors color ids to cache + */ + private void ensureFontAndColorsCreated(final String[] fonts, final String[] colors) { + CVSUIPlugin.getStandardDisplay().syncExec(new Runnable() { + public void run() { + ITheme theme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme(); + for (int i = 0; i < colors.length; i++) { + theme.getColorRegistry().get(colors[i]); + + } + for (int i = 0; i < fonts.length; i++) { + theme.getFontRegistry().get(fonts[i]); + } + } + }); + } public static boolean isDirty(final ICVSResource cvsResource) throws CVSException { return !cvsResource.isIgnored() && cvsResource.isModified(null); @@ -199,138 +145,104 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig } return null; } + /** * This method should only be called by the decorator thread. * * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object, org.eclipse.jface.viewers.IDecoration) */ public void decorate(Object element, IDecoration decoration) { - IResource resource = getResource(element); if (resource == null || resource.getType() == IResource.ROOT) return; CVSTeamProvider cvsProvider = getCVSProviderFor(resource); if (cvsProvider == null) - return; - - - // if the resource is ignored return an empty decoration. This will - // force a decoration update event and clear the existing CVS decoration. - ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource); + return; + try { - if (cvsResource.isIgnored()) { - return; - } - } catch (CVSException e) { - // The was an exception in isIgnored. Don't decorate - //todo should log this error + CVSDecoration cvsDecoration = decorate(resource); + cvsDecoration.setWatchEditEnabled(cvsProvider.isWatchEditEnabled()); + cvsDecoration.apply(decoration); + } catch(CVSException e) { handleException(e); - return; - } - - // determine a if resource has outgoing changes (e.g. is dirty). - boolean isDirty = false; - boolean computeDeepDirtyCheck = isDeepDirtyCalculationEnabled(); - int type = resource.getType(); - if (type == IResource.FILE || computeDeepDirtyCheck) { - isDirty = CVSLightweightDecorator.isDirty(resource); - } - - decorateTextLabel(resource, decoration, isDirty, true, null); - - ImageDescriptor overlay = getOverlay(resource, isDirty, cvsProvider); - if(overlay != null) { //actually sending null arg would work but this makes logic clearer - decoration.addOverlay(overlay); } } - private boolean isDeepDirtyCalculationEnabled() { + public static CVSDecoration decorate(IResource resource) throws CVSException { IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore(); - return store.getBoolean(ICVSUIConstants.PREF_CALCULATE_DIRTY); - } - - //todo the showRevisions flag is temp, a better solution is DecoratorStrategy classes which have most the code below - public static void decorateTextLabel(IResource resource, IDecoration decoration, boolean isDirty, boolean showRevisions, String overrideRevision) { - try { - Map bindings = new HashMap(3); - String format = ""; //$NON-NLS-1$ - IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore(); - - // if the resource does not have a location then return. This can happen if the resource - // has been deleted after we where asked to decorate it. - if(!resource.isAccessible() || resource.getLocation() == null) { - return; - } - + ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource); + CVSDecoration cvsDecoration = new CVSDecoration(resource.getName()); + cvsDecoration.setResourceType(resource.getType()); + + if (cvsResource.isIgnored()) { + cvsDecoration.setIgnored(true); + } + if (!cvsDecoration.isIgnored()) { + // Dirty + boolean computeDeepDirtyCheck = store.getBoolean(ICVSUIConstants.PREF_CALCULATE_DIRTY); int type = resource.getType(); - - if (type == IResource.FOLDER) { - format = store.getString(ICVSUIConstants.PREF_FOLDERTEXT_DECORATION); - } else if (type == IResource.PROJECT) { - format = store.getString(ICVSUIConstants.PREF_PROJECTTEXT_DECORATION); - } else { - format = store.getString(ICVSUIConstants.PREF_FILETEXT_DECORATION); - } - - if (isDirty) { - bindings.put(CVSDecoratorConfiguration.DIRTY_FLAG, store.getString(ICVSUIConstants.PREF_DIRTY_FLAG)); + if (type == IResource.FILE || computeDeepDirtyCheck) { + cvsDecoration.setDirty(CVSLightweightDecorator.isDirty(resource)); } + // Tag CVSTag tag = getTagToShow(resource); if (tag != null) { String name = tag.getName(); - if(tag.getType() == CVSTag.DATE){ + if (tag.getType() == CVSTag.DATE) { Date date = tag.asDate(); - if(date != null){ + if (date != null) { name = decorateFormatter.format(date); } } - bindings.put(CVSDecoratorConfiguration.RESOURCE_TAG, name); + cvsDecoration.setTag(name); } - - if (type != IResource.FILE) { - ICVSFolder folder = CVSWorkspaceRoot.getCVSFolderFor((IContainer) resource); - FolderSyncInfo folderInfo = folder.getFolderSyncInfo(); - if (folderInfo != null) { - ICVSRepositoryLocation location = KnownRepositories.getInstance().getRepository(folderInfo.getRoot()); - bindings.put(CVSDecoratorConfiguration.REMOTELOCATION_HOST, location.getHost()); - bindings.put(CVSDecoratorConfiguration.REMOTELOCATION_METHOD, location.getMethod().getName()); - bindings.put(CVSDecoratorConfiguration.REMOTELOCATION_USER, location.getUsername()); - bindings.put(CVSDecoratorConfiguration.REMOTELOCATION_ROOT, location.getRootDirectory()); - bindings.put(CVSDecoratorConfiguration.REMOTELOCATION_REPOSITORY, folderInfo.getRepository()); - } - } else { - format = store.getString(ICVSUIConstants.PREF_FILETEXT_DECORATION); - ICVSFile file = CVSWorkspaceRoot.getCVSFileFor((IFile) resource); - ResourceSyncInfo fileInfo = file.getSyncInfo(); - if (fileInfo != null) { - if (fileInfo.isAdded()) { - bindings.put(CVSDecoratorConfiguration.ADDED_FLAG, store.getString(ICVSUIConstants.PREF_ADDED_FLAG)); - } else { - if(showRevisions) { - if(overrideRevision != null) - bindings.put(CVSDecoratorConfiguration.FILE_REVISION, overrideRevision); - else - bindings.put(CVSDecoratorConfiguration.FILE_REVISION, fileInfo.getRevision()); + // Has a remote + cvsDecoration.setHasRemote(CVSWorkspaceRoot.hasRemote(resource)); + // Is a new resource + if (store.getBoolean(ICVSUIConstants.PREF_SHOW_NEWRESOURCE_DECORATION)) { + if (cvsResource.exists()) { + if (cvsResource.isFolder()) { + if (!((ICVSFolder) cvsResource).isCVSFolder()) { + cvsDecoration.setNewResource(true); } + } else if (!cvsResource.isManaged()) { + cvsDecoration.setNewResource(true); } - KSubstOption option = fileInfo.getKeywordMode() != null ? - fileInfo.getKeywordMode() : - KSubstOption.fromFile((IFile) resource); - bindings.put(CVSDecoratorConfiguration.FILE_KEYWORD, option.getShortDisplayText()); - } else { - // only show the type that cvs will use when comitting the file - KSubstOption option = KSubstOption.fromFile((IFile) resource); - bindings.put(CVSDecoratorConfiguration.FILE_KEYWORD, option.getShortDisplayText()); } } - - CVSDecoratorConfiguration.decorate(decoration, format, bindings); - - } catch (CVSException e) { - handleException(e); - return; } + // Extract type specific properties + if (resource.getType() == IResource.FILE) { + extractFileProperties((IFile) resource, cvsDecoration); + } else { + extractContainerProperties((IContainer) resource, cvsDecoration); + } + return cvsDecoration; + } + + private static void extractContainerProperties(IContainer resource, CVSDecoration cvsDecoration) throws CVSException { + ICVSFolder folder = CVSWorkspaceRoot.getCVSFolderFor(resource); + FolderSyncInfo folderInfo = folder.getFolderSyncInfo(); + if (folderInfo != null) { + cvsDecoration.setLocation(KnownRepositories.getInstance().getRepository(folderInfo.getRoot())); + cvsDecoration.setRepository(folderInfo.getRepository()); + cvsDecoration.setVirtualFolder(folderInfo.isVirtualDirectory()); + } + } + + private static void extractFileProperties(IFile resource, CVSDecoration cvsDecoration) throws CVSException { + ICVSFile file = CVSWorkspaceRoot.getCVSFileFor(resource); + ResourceSyncInfo fileInfo = file.getSyncInfo(); + KSubstOption option = KSubstOption.fromFile((IFile) resource); + if (fileInfo != null) { + cvsDecoration.setAdded(fileInfo.isAdded()); + cvsDecoration.setRevision(fileInfo.getRevision()); + ICVSFile cvsFile = CVSWorkspaceRoot.getCVSFileFor((IFile) resource); + cvsDecoration.setNeedsMerge(fileInfo.isNeedsMerge(file.getTimeStamp())); + option = fileInfo.getKeywordMode(); + } + cvsDecoration.setKeywordSubstitution(option.getShortDisplayText()); } /** @@ -376,107 +288,6 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig } return tag; } - - /* Determine and return the overlay icon to use. - * We only get to use one, so if many are applicable at once we chose the - * one we think is the most important to show. - * Return null if no overlay is to be used. - */ - public static ImageDescriptor getOverlay(IResource resource, boolean isDirty, CVSTeamProvider provider) { - - // for efficiency don't look up a pref until its needed - IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore(); - boolean showNewResources = store.getBoolean(ICVSUIConstants.PREF_SHOW_NEWRESOURCE_DECORATION); - - // show newResource icon - if (showNewResources) { - ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource); - try { - if (cvsResource.exists()) { - boolean isNewResource = false; - if (cvsResource.isFolder()) { - if (!((ICVSFolder)cvsResource).isCVSFolder()) { - isNewResource = true; - } - } else if (!cvsResource.isManaged()) { - isNewResource = true; - } - if (isNewResource) { - return newResource; - } - } - } catch (CVSException e) { - handleException(e); - return null; - } - } - - boolean showDirty = store.getBoolean(ICVSUIConstants.PREF_SHOW_DIRTY_DECORATION); - - // show dirty icon - if(showDirty && isDirty) { - return dirty; - } - - boolean showAdded = store.getBoolean(ICVSUIConstants.PREF_SHOW_ADDED_DECORATION); - - if (showAdded && resource.getType() == IResource.FILE) { - try { - if (resource.getLocation() != null) { - ICVSFile cvsFile = CVSWorkspaceRoot.getCVSFileFor((IFile) resource); - ResourceSyncInfo info = cvsFile.getSyncInfo(); - // show merged icon if file has been merged but has not been edited (e.g. on commit it will be ignored) - if (info != null && info.isNeedsMerge(cvsFile.getTimeStamp())) { - return merged; - // show added icon if file has been added locally. - } else if (info != null && info.isAdded()) { - // todo - return added; - } - } - } catch (CVSException e) { - handleException(e); - return null; - } - } - - // if watch/edit is enabled, show non-read-only files as being edited - boolean decorateEdited; - try { - decorateEdited = provider.isWatchEditEnabled(); - } catch (CVSException e1) { - handleException(e1); - decorateEdited = false; - } - - if (decorateEdited && resource.getType() == IResource.FILE && !resource.isReadOnly() && CVSWorkspaceRoot.hasRemote(resource)) { - return edited; - } - - boolean showHasRemote = store.getBoolean(ICVSUIConstants.PREF_SHOW_HASREMOTE_DECORATION); - - // Simplest is that is has remote. - if (showHasRemote && CVSWorkspaceRoot.hasRemote(resource)) { - if (resource.getType() != IResource.FILE) { - // check if the folder is local diectory with no remote - ICVSFolder cvsFolder = CVSWorkspaceRoot.getCVSFolderFor((IContainer)resource); - try { - FolderSyncInfo folderSyncInfo = cvsFolder.getFolderSyncInfo(); - if (folderSyncInfo != null && folderSyncInfo.isVirtualDirectory()) { - return noRemoteDir; - } - } catch (CVSException e) { - // log the exception and show the shared overlay - handleException(e); - } - } - return checkedIn; - } - - //nothing matched - return null; - - } /* * Add resource and its parents to the List @@ -546,7 +357,8 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig //System.out.println(">> State Change Event"); Set resourcesToUpdate = new HashSet(); - boolean showingDeepDirtyIndicators = isDeepDirtyCalculationEnabled(); + IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore(); + boolean showingDeepDirtyIndicators = store.getBoolean(ICVSUIConstants.PREF_CALCULATE_DIRTY); for (int i = 0; i < changedResources.length; i++) { IResource resource = changedResources[i]; @@ -592,6 +404,7 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig */ public void dispose() { super.dispose(); + PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().removePropertyChangeListener(this); CVSProviderPlugin.broadcastDecoratorEnablementChanged(false /* disabled */); TeamUI.removePropertyChangeListener(this); CVSUIPlugin.removePropertyChangeListener(this); @@ -609,6 +422,7 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig */ public void propertyChange(PropertyChangeEvent event) { if (isEventOfInterest(event)) { + ensureFontAndColorsCreated(fonts, colors); refresh(); } } @@ -617,6 +431,12 @@ public class CVSLightweightDecorator extends LabelProvider implements ILightweig String prop = event.getProperty(); return prop.equals(TeamUI.GLOBAL_IGNORES_CHANGED) || prop.equals(TeamUI.GLOBAL_FILE_TYPES_CHANGED) - || prop.equals(CVSUIPlugin.P_DECORATORS_CHANGED); + || prop.equals(CVSUIPlugin.P_DECORATORS_CHANGED) + || prop.equals(CVSDecoratorConfiguration.OUTGOING_CHANGE_BACKGROUND_COLOR) + || prop.equals(CVSDecoratorConfiguration.OUTGOING_CHANGE_FOREGROUND_COLOR) + || prop.equals(CVSDecoratorConfiguration.OUTGOING_CHANGE_FONT) + || prop.equals(CVSDecoratorConfiguration.IGNORED_FOREGROUND_COLOR) + || prop.equals(CVSDecoratorConfiguration.IGNORED_BACKGROUND_COLOR) + || prop.equals(CVSDecoratorConfiguration.IGNORED_FONT); } } |