org.symbian.tools.wrttools.previewer/src/org/symbian/tools/tmw/previewer/internal/PreviewerUtil.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Thu, 19 Aug 2010 16:13:44 -0700
changeset 468 a05c6e5cc7d9
parent 308 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/PreviewerUtil.java@c521df56b15d
permissions -rw-r--r--
Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
304
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     1
/**
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     2
 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     3
 * All rights reserved.
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     8
 *
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     9
 * Initial Contributors:
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    10
 * Symbian Foundation - initial contribution.
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    11
 * Contributors:
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    12
 * Description:
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    13
 * Overview:
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    14
 * Details:
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    15
 * Platforms/Drives/Compatibility:
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    16
 * Assumptions/Requirement/Pre-requisites:
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    17
 * Failures and causes:
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    18
 */
468
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    19
package org.symbian.tools.tmw.previewer.internal;
304
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
import java.util.Collection;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
import java.util.HashMap;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
import java.util.HashSet;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    24
import java.util.Map;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
import org.eclipse.core.resources.IFile;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
import org.eclipse.core.resources.IProject;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
import org.eclipse.core.resources.IResource;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
import org.eclipse.core.resources.IResourceDelta;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
import org.eclipse.core.resources.IResourceDeltaVisitor;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
import org.eclipse.core.runtime.CoreException;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
import org.eclipse.core.runtime.IPath;
468
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    33
import org.symbian.tools.tmw.previewer.core.IApplicationLayoutProvider;
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    34
import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
304
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
public class PreviewerUtil {
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
    public static final class ChangedResourcesCollector implements IResourceDeltaVisitor {
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
        public final Collection<IFile> files = new HashSet<IFile>();
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
        public final Collection<IProject> deleted = new HashSet<IProject>();
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    40
        public final Map<IProject, IPath> renamed = new HashMap<IProject, IPath>();
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    41
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    42
        public boolean visit(IResourceDelta delta) throws CoreException {
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    43
            IResource resource = delta.getResource();
468
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    44
            switch (resource.getType()) {
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    45
            case IResource.PROJECT:
304
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    46
                if (delta.getKind() == IResourceDelta.REMOVED) {
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    47
                    if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    48
                        renamed.put(resource.getProject(), delta.getMovedToPath());
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    49
                    } else {
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    50
                        deleted.add((IProject) resource);
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    51
                    }
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    52
                    return false;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    53
                }
468
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    54
                break;
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    55
            case IResource.FILE:
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    56
                IApplicationLayoutProvider layoutProvider = PreviewerPlugin.getExtensionsManager().getLayoutProvider(
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    57
                        resource.getProject());
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    58
                if (layoutProvider != null) {
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    59
                    if (layoutProvider.getResourcePath((IFile) resource) != null) {
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    60
                        final boolean kind = delta.getKind() == IResourceDelta.ADDED
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    61
                                | delta.getKind() == IResourceDelta.REMOVED;
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    62
                        final boolean flag = (delta.getFlags() & (IResourceDelta.CONTENT | IResourceDelta.ENCODING
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    63
                                | IResourceDelta.LOCAL_CHANGED | IResourceDelta.REPLACED | IResourceDelta.SYNC)) != 0;
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    64
                        if (kind || flag) {
304
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    65
                            files.add((IFile) resource);
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    66
                        }
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    67
                    }
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    68
                }
468
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 308
diff changeset
    69
                break;
304
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    70
            }
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    71
            return true;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    72
        }
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    73
    }
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    74
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    75
    public static boolean isRelevantResource(IResource resource) {
308
c521df56b15d Bug 2514 - Allow the user to package applications even if there are errors
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 304
diff changeset
    76
        if (resource.exists() && resource.getType() == IResource.FILE) {
304
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    77
            return !resource.getFullPath().segment(1).equalsIgnoreCase("preview")
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    78
                    && !"wgz".equalsIgnoreCase(resource.getFileExtension())
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    79
                    && !(PreviewerPlugin.PLUGIN_ID + ".xml").equals(resource.getName());
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    80
        }
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    81
        return false;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    82
    }
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    83
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    84
    public static IFile[] getWebChanges(final IResourceDelta delta) {
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    85
        ChangedResourcesCollector visitor = collectResourceChanges(delta);
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    86
        final Collection<IFile> files = visitor.files;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    87
        return files.toArray(new IFile[files.size()]);
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    88
    }
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    89
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    90
    public static ChangedResourcesCollector collectResourceChanges(final IResourceDelta delta) {
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    91
        ChangedResourcesCollector visitor = new ChangedResourcesCollector();
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    92
        try {
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    93
            delta.accept(visitor);
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    94
        } catch (CoreException e) {
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    95
            PreviewerPlugin.log(e);
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    96
        }
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    97
        return visitor;
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    98
    }
d92630dec325 Refactoring server-side preview code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    99
}