KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > NavigationAction


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.compare;
12
13 import java.util.ResourceBundle JavaDoc;
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.jface.dialogs.MessageDialog;
16 import org.eclipse.swt.widgets.Display;
17 import org.eclipse.swt.widgets.Shell;
18
19 import org.eclipse.compare.internal.CompareMessages;
20 import org.eclipse.compare.internal.CompareUIPlugin;
21 import org.eclipse.compare.internal.Utilities;
22
23
24 /**
25  * A <code>NavigationAction</code> is used to navigate through the individual
26  * differences of a <code>CompareEditorInput</code>.
27  * <p>
28  * Clients may instantiate this class; it is not intended to be subclassed.
29  * </p>
30  * @since 2.0
31  */

32 public class NavigationAction extends Action {
33     
34     private boolean fNext;
35     private CompareEditorInput fCompareEditorInput;
36     
37     
38     /**
39      * Creates a <code>NavigationAction</code>.
40      *
41      * @param next if <code>true</code> action goes to the next difference; otherwise to the previous difference.
42      */

43     public NavigationAction(boolean next) {
44         this(CompareUI.getResourceBundle(), next);
45     }
46
47     /**
48      * Creates a <code>NavigationAction</code> that initializes its attributes
49      * from the given <code>ResourceBundle</code>.
50      *
51      * @param bundle is used to initialize the action
52      * @param next if <code>true</code> action goes to the next difference; otherwise to the previous difference.
53      */

54     public NavigationAction(ResourceBundle JavaDoc bundle, boolean next) {
55         Utilities.initAction(this, bundle, next ? "action.Next." : "action.Previous."); //$NON-NLS-2$ //$NON-NLS-1$
56
fNext= next;
57     }
58
59     public void run() {
60         if (fCompareEditorInput != null) {
61             Object JavaDoc adapter= fCompareEditorInput.getAdapter(ICompareNavigator.class);
62             if (adapter instanceof ICompareNavigator) {
63                 boolean atEnd= ((ICompareNavigator)adapter).selectChange(fNext);
64                 Shell shell= CompareUIPlugin.getShell();
65                 if (atEnd && shell != null) {
66                     
67                     Display display= shell.getDisplay();
68                     if (display != null)
69                         display.beep();
70
71                     String JavaDoc title;
72                     String JavaDoc message;
73                     if (fNext) {
74                         title= CompareMessages.CompareNavigator_atEnd_title;
75                         message= CompareMessages.CompareNavigator_atEnd_message;
76                     } else {
77                         title= CompareMessages.CompareNavigator_atBeginning_title;
78                         message= CompareMessages.CompareNavigator_atBeginning_message;
79                     }
80                     MessageDialog.openInformation(shell, title, message);
81                 }
82             }
83         }
84     }
85     
86     /**
87      * Sets the <code>CompareEditorInput</code> on which this action operates.
88      *
89      * @param input the <code>CompareEditorInput</code> on which this action operates; if <code>null</code> action does nothing
90      */

91     public void setCompareEditorInput(CompareEditorInput input) {
92         fCompareEditorInput= input;
93     }
94 }
95
Popular Tags