KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > schema > SchemaPropertySheet


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.schema;
12 import org.eclipse.core.runtime.IAdaptable;
13 import org.eclipse.jface.viewers.*;
14 import org.eclipse.ui.*;
15 import org.eclipse.jface.action.*;
16 import org.eclipse.ui.views.properties.*;
17 import org.eclipse.pde.internal.ui.*;
18
19
20 public class SchemaPropertySheet extends PropertySheetPage {
21     private Action cloneAction;
22     protected ISelection currentSelection;
23     private IWorkbenchPart part;
24     public SchemaPropertySheet() {
25         makeSchemaActions();
26     }
27     public void disableActions() {
28         cloneAction.setEnabled(false);
29     }
30     public void fillLocalToolBar(IToolBarManager toolBarManager) {
31         toolBarManager.add(new Separator());
32         toolBarManager.add(cloneAction);
33     }
34     public IPropertySheetEntry getSelectedEntry() {
35         if(!currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection)
36             return (IPropertySheetEntry) ((IStructuredSelection)currentSelection).getFirstElement();
37         return null;
38     }
39     protected void handleClone() {
40         Object JavaDoc input = null;
41         if (currentSelection instanceof IStructuredSelection) {
42             input = ((IStructuredSelection) currentSelection).getFirstElement();
43         }
44         IPropertySource source = null;
45         if (input instanceof IAdaptable) {
46             source = (IPropertySource) ((IAdaptable) input)
47                     .getAdapter(IPropertySource.class);
48         }
49         if (source instanceof ICloneablePropertySource) {
50             Object JavaDoc newInput = ((ICloneablePropertySource) source).doClone();
51             if (newInput != null) {
52                 selectionChanged(part, new StructuredSelection(newInput));
53             }
54         }
55     }
56     public void makeContributions(IMenuManager menuManager,
57             IToolBarManager toolBarManager, IStatusLineManager statusLineManager) {
58         super.makeContributions(menuManager, toolBarManager, statusLineManager);
59         fillLocalToolBar(toolBarManager);
60     }
61     protected void makeSchemaActions() {
62         cloneAction = new Action(PDEUIMessages.SchemaPropertySheet_clone_label) {
63             public void run() {
64                 handleClone();
65             }
66         };
67         cloneAction.setImageDescriptor(PDEPluginImages.DESC_CLONE_ATT);
68         cloneAction
69                 .setDisabledImageDescriptor(PDEPluginImages.DESC_CLONE_ATT_DISABLED);
70         cloneAction.setToolTipText(PDEUIMessages.SchemaPropertySheet_clone_tooltip);
71         cloneAction.setEnabled(false);
72     }
73     public void selectionChanged(IWorkbenchPart part, ISelection sel) {
74         super.selectionChanged(part, sel);
75         this.part = part;
76         currentSelection = sel;
77         updateActions();
78     }
79     protected void updateActions() {
80         Object JavaDoc input = null;
81         if (currentSelection instanceof IStructuredSelection) {
82             input = ((IStructuredSelection) currentSelection).getFirstElement();
83         }
84         IPropertySource source = null;
85         if (input instanceof IAdaptable) {
86             source = (IPropertySource) ((IAdaptable) input)
87                     .getAdapter(IPropertySource.class);
88         }
89         updateActions(source);
90     }
91     protected void updateActions(IPropertySource source) {
92         if (source instanceof ICloneablePropertySource) {
93             cloneAction.setEnabled(((ICloneablePropertySource) source)
94                     .isCloneable());
95         } else
96             cloneAction.setEnabled(false);
97     }
98 }
99
Popular Tags