001    /*
002     * file About.java
003     * 
004     * Licensed Materials - Property of IBM
005     * Restricted Materials of IBM - you are allowed to copy, modify and 
006     * redistribute this file as part of any program that interfaces with 
007     * IBM Rational CM API.
008     *
009     * com.ibm.rational.teamapi.scout.actions.About
010     *
011     * © Copyright IBM Corporation 2004, 2008.  All Rights Reserved.
012     * Note to U.S. Government Users Restricted Rights:  Use, duplication or 
013     * disclosure restricted by GSA ADP  Schedule Contract with IBM Corp.
014     */
015    package com.ibm.rational.teamapi.scout.actions;
016    
017    import java.util.ArrayList;
018    import java.util.Iterator;
019    import java.util.Map;
020    
021    import javax.wvcm.ProviderFactory;
022    
023    import org.eclipse.jface.action.IAction;
024    import org.eclipse.jface.dialogs.MessageDialog;
025    import org.eclipse.jface.viewers.ISelection;
026    import org.eclipse.ui.IWorkbenchWindow;
027    import org.eclipse.ui.IWorkbenchWindowActionDelegate;
028    
029    import com.ibm.rational.wvcm.stpex.StpExEnumerationBase;
030    import com.ibm.rational.wvcm.stp.StpException;
031    import com.ibm.rational.wvcm.stp.StpProvider;
032    
033    
034    /**
035     * An IWorkbenchWindowActionDelegate that tests the ability to instantiate a 
036     * CM API provider.
037     *
038     * @see  IWorkbenchWindowActionDelegate
039     */
040    public class About
041        implements IWorkbenchWindowActionDelegate
042    {
043        /** The handle on the About box handle */
044        private IWorkbenchWindow m_window;
045    
046        /**
047         * Attempt to instantiate a CM API provider and report the results in a
048         * dialog box.
049         *
050         * @see  IWorkbenchWindowActionDelegate#run
051         */
052        public void run(IAction action)
053        {
054            boolean   debug = false;
055            ArrayList<String> about = new ArrayList<String>();
056    
057            try {
058                String providerName = StpProvider.PROVIDER_CLASS;
059                StpProvider provider =
060                    (StpProvider)ProviderFactory.createProvider(
061                        providerName,
062                        null);
063    
064                about.add("Using " + provider.getClass().getName() + ", version "
065                    + provider.getClass().getPackage().getImplementationVersion());
066    
067                Package[] packages = Package.getPackages();
068    
069                if (packages != null) {
070                    for (int i = 0; i < packages.length; ++i) {
071                        Package myPackage = packages[i];
072    
073                        if (
074                            myPackage.getName().startsWith(
075                                    "com.ibm.rational.wvcm.stp")
076                                || myPackage.getName().startsWith("javax.wvcm")) {
077                            about.add(myPackage.getName());
078                            about.add("  " + myPackage.getSpecificationTitle()
079                                + ", " + myPackage.getSpecificationVersion() + ", "
080                                + myPackage.getSpecificationVendor());
081    
082                            about.add("");
083                        }
084                    }
085                }
086    
087                // Get the main interface package and display its name and version
088                Package stpPackage =
089                    Package.getPackage("com.ibm.rational.wvcm.stp");
090    
091                if (stpPackage != null)
092                    about.add(stpPackage.getSpecificationTitle() + ", "
093                        + stpPackage.getSpecificationVersion() + " for... ");
094    
095                // Identify which repository types have providers at this time
096                Iterator types =
097                    StpExEnumerationBase.enumerator(StpProvider.Domain.class);
098                Map      errors = provider.getInstantiationErrors();
099    
100                while (types.hasNext()) {
101                    StpProvider.Domain type = (StpProvider.Domain)types.next();
102    
103                    if (!type.equals(StpProvider.Domain.NONE)
104                            && !type.equals(StpProvider.Domain.INVALID)) {
105                        StpException error = (StpException)errors.get(type);
106    
107                        about.add(type.toString() + " -- "
108                            + (error == null ? "OK " : error.toString()));
109    
110                        if (debug && error != null)
111                            error.printStackTrace();
112                    }
113                }
114            } catch (Throwable ex) {
115                ex.printStackTrace();
116                about.add(ex.getClass().getName() + ": "
117                    + ex.getLocalizedMessage());
118            }
119    
120            StringBuffer msg = new StringBuffer();
121            Iterator     iter = about.iterator();
122    
123            while (iter.hasNext()) {
124                if (msg.length() > 0)
125                    msg.append("\n");
126    
127                msg.append(iter.next());
128            }
129    
130            MessageDialog.openInformation(m_window.getShell(),
131                "CM API Scout Plug-in",
132                msg.toString());
133        }
134    
135        /**
136         * @see  IWorkbenchWindowActionDelegate#selectionChanged
137         */
138        public void selectionChanged(
139            IAction    action,
140            ISelection selection) {}
141    
142        /**
143         * @see  IWorkbenchWindowActionDelegate#dispose
144         */
145        public void dispose() {}
146    
147        /**
148         * @see  IWorkbenchWindowActionDelegate#init
149         */
150        public void init(IWorkbenchWindow window)
151        {
152            this.m_window = window;
153        }
154    }