Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 208830
Collapse All | Expand All

(-)src/org/eclipse/datatools/connectivity/internal/ui/ProfileUIManager.java (+118 lines)
Added Link Here
1
/*
2
 *************************************************************************
3
 * Copyright (c) 2007 Sybase, Inc.
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *  Sybase, Inc. - initial API and implementation
11
 *  Actuate Corporation - extracted implementation to this utility class
12
 *  
13
 *************************************************************************
14
 */
15
16
package org.eclipse.datatools.connectivity.internal.ui;
17
18
import java.util.Collection;
19
import java.util.Iterator;
20
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IAdaptable;
23
import org.eclipse.datatools.connectivity.IConnectionProfile;
24
import org.eclipse.datatools.connectivity.ui.wizards.ProfilePropertyPage;
25
import org.eclipse.jface.preference.PreferenceDialog;
26
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.ui.IWorkbenchPropertyPage;
29
import org.eclipse.ui.internal.dialogs.PropertyDialog;
30
import org.eclipse.ui.internal.dialogs.PropertyPageContributorManager;
31
import org.eclipse.ui.internal.dialogs.PropertyPageManager;
32
import org.eclipse.ui.internal.dialogs.RegistryPageContributor;
33
34
/**
35
 *  An utility class of the Connection Profile UI Manager.
36
 *  TODO: This currently uses internal Platform UI packages to get at property page details.
37
 *  It is pending resolution to Bugzilla 208830 for Platform UI to make
38
 *  some of the internal APIs public or offer alternatives that we can use.
39
 */
40
public class ProfileUIManager
41
{
42
    /**
43
     * Indicates whether the specified element has at least one property page contributor.
44
     * @param element   an adapter element of a property page
45
     * @return  true for having at least one contributor; false otherwise
46
     */
47
    public static boolean hasContributors( Object element ) 
48
    {
49
        if ( element == null || !(element instanceof IAdaptable) )
50
            return false;
51
        Collection contributors = PropertyPageContributorManager.getManager()
52
                .getApplicableContributors( element );
53
        return contributors != null && contributors.size() > 0;
54
    }
55
56
    /**
57
     * Creates a new preference dialog under the control of the element's 
58
     * property page manager.
59
     * @param parentShell   the parent shell
60
     * @param selection     the selection that will be used to determine target object
61
     * @param element       an adaptable element that owns the properties shown in a property page
62
     * @return  the preference dialog
63
     */
64
    public static PreferenceDialog createPreferenceDialog( Shell parentShell, 
65
            ISelection selection, Object element )
66
    {
67
        if ( element == null || !(element instanceof IAdaptable) )
68
            return null;
69
70
        // load pages for the selection
71
        // fill the manager with contributions from the matching contributors
72
        PropertyPageManager pageManager = new PropertyPageManager();
73
        PropertyPageContributorManager.getManager().contribute( pageManager, element );
74
75
        PropertyDialog propertyDialog = new PropertyDialog( parentShell, pageManager, selection );
76
        propertyDialog.create();
77
        return propertyDialog;
78
    }
79
    
80
    /**
81
     * Creates a new property page contribution of the specified connection profile.
82
     * @param profile   a connection profile
83
     * @return  the profile property page
84
     */
85
    public static ProfilePropertyPage createPropertyPage( IConnectionProfile profile )
86
    {
87
        Collection propertyPageContributions =
88
            PropertyPageContributorManager.getManager().getApplicableContributors( profile );
89
        
90
        Iterator iter = propertyPageContributions.iterator();
91
        while( iter.hasNext() )
92
        {
93
            RegistryPageContributor contributor = (RegistryPageContributor) iter.next();
94
            IWorkbenchPropertyPage profilePropPage = null;
95
            try
96
            {
97
                profilePropPage = contributor.createPage( profile );
98
            }
99
            catch( CoreException ex )
100
            {
101
                // ignore exception
102
                continue;   // try the next contribution
103
            }
104
105
            if( ! ( profilePropPage instanceof ProfilePropertyPage ))
106
            {
107
                if( profilePropPage != null )
108
                    profilePropPage.dispose();
109
                continue;   // try the next contribution
110
            }
111
            
112
            return (ProfilePropertyPage) profilePropPage;
113
        }
114
115
        return null;
116
    }
117
    
118
}

Return to bug 208830