KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > RestoreDefaultAction


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.debug.internal.ui.sourcelookup;
12
13 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
14 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
15 import org.eclipse.debug.core.sourcelookup.containers.DefaultSourceContainer;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17
18 /**
19  * The action for adding the default container to the list.
20  *
21  * @since 3.0
22  */

23 public class RestoreDefaultAction extends SourceContainerAction {
24     
25     private ISourceLookupDirector fDirector;
26
27     public RestoreDefaultAction() {
28         super(SourceLookupUIMessages.sourceTab_defaultButton);
29     }
30     /**
31      * @see IAction#run()
32      */

33     public void run() {
34         ISourceContainer[] containers = new ISourceContainer[1];
35         containers[0] = new DefaultSourceContainer();
36         containers[0].init(fDirector);
37         getViewer().setEntries(containers);
38         setEnabled(false);
39     }
40
41     public void setSourceLookupDirector(ISourceLookupDirector director) {
42         fDirector = director;
43     }
44
45     /**
46      * @see SelectionListenerAction#updateSelection(IStructuredSelection)
47      */

48     protected boolean updateSelection(IStructuredSelection selection) {
49         //disable if selection is empty, default already present, or non-root node selected
50
ISourceContainer[] containers = getViewer().getEntries();
51         if(containers != null && containers.length == 1) {
52             if(containers[0] instanceof DefaultSourceContainer) {
53                 return false;
54             }
55         }
56         return true;
57     }
58 }
59
Popular Tags