天天看點

opentypeaction源代碼

/*******************************************************************************2 * Copyright (c) 2000, 2007 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 * [url]http://www.eclipse.org/legal/epl-v10.html[/url]

7 *

8 * Contributors:

9 * IBM Corporation - initial API and implementation

10 *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.actions;

12 

13 import org.eclipse.core.runtime.CoreException;

14 

15 import org.eclipse.swt.SWT;

16 import org.eclipse.swt.widgets.Event;

17 import org.eclipse.swt.widgets.Shell;

18 

19 import org.eclipse.jface.action.Action;

20 import org.eclipse.jface.action.IAction;

21 import org.eclipse.jface.dialogs.IDialogConstants;

22 import org.eclipse.jface.viewers.ISelection;

23 

24 import org.eclipse.ui.IActionDelegate2;

25 import org.eclipse.ui.IWorkbenchWindow;

26 import org.eclipse.ui.IWorkbenchWindowActionDelegate;

27 import org.eclipse.ui.PlatformUI;

28 import org.eclipse.ui.dialogs.SelectionDialog;

29 

30 import org.eclipse.jdt.core.IType;

31 import org.eclipse.jdt.core.search.IJavaSearchConstants;

32 

33 import org.eclipse.jdt.ui.JavaUI;

34 

35 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;

36 import org.eclipse.jdt.internal.ui.JavaPlugin;

37 import org.eclipse.jdt.internal.ui.JavaPluginImages;

38 import org.eclipse.jdt.internal.ui.JavaUIMessages;

39 import org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog;

40 import org.eclipse.jdt.internal.ui.util.ExceptionHandler;

41 

42 public class OpenTypeAction extends Action implements IWorkbenchWindowActionDelegate, IActionDelegate2 {

43 

44 public OpenTypeAction() {

45 super();

46 setText(JavaUIMessages.OpenTypeAction_label);

47 setDescription(JavaUIMessages.OpenTypeAction_description);

48 setToolTipText(JavaUIMessages.OpenTypeAction_tooltip);

49 setImageDescriptor(JavaPluginImages.DESC_TOOL_OPENTYPE);

50 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_TYPE_ACTION);

51 }

52 

53 public void run() {

54 runWithEvent(null);

55 }

56  

57 public void runWithEvent(Event e) {

58 Shell parent= JavaPlugin.getActiveWorkbenchShell();

59 SelectionDialog dialog;

60 if (e != null && e.stateMask == SWT.MOD1) {

61 // use old open type dialog when MOD1 (but no other modifier) is down:

62 dialog= createOpenTypeSelectionDialog2(parent);

63 } else {

64 dialog= new OpenTypeSelectionDialog(parent, true, PlatformUI.getWorkbench().getProgressService(), null, IJavaSearchConstants.TYPE);

65 }

66 dialog.setTitle(JavaUIMessages.OpenTypeAction_dialogTitle);

67 dialog.setMessage(JavaUIMessages.OpenTypeAction_dialogMessage);

68 

69 int result= dialog.open();

70 if (result != IDialogConstants.OK_ID)

71 return;

72 

73 Object [] types= dialog.getResult();

74 if (types != null && types.length > 0) {

75 IType type= null;

76 for (int i= 0; i < types.length; i++) {

77 type= (IType) types[i];

78 try {

79 JavaUI.openInEditor(type, true, true);

80 } catch (CoreException x) {

81 ExceptionHandler.handle(x, JavaUIMessages.OpenTypeAction_errorTitle, JavaUIMessages.OpenTypeAction_errorMessage);

82 }

83 }

84 }

85 }

86 

87 /**

88 * @deprecated

89 * @param parent

90 * @return the dialog

91 */

92 private SelectionDialog createOpenTypeSelectionDialog2(Shell parent) {

93 return new org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog2(parent, false, PlatformUI.getWorkbench().getProgressService(), null, IJavaSearchConstants.TYPE);

94 }

95 

96 // ---- IWorkbenchWindowActionDelegate

97 // ------------------------------------------------

98 

99 public void run(IAction action) {

100 run();

101 }

102 

103 public void dispose() {

104 // do nothing.

105 }

106 

107 public void init(IWorkbenchWindow window) {

108 // do nothing.

109 }

110 

111 public void selectionChanged(IAction action, ISelection selection) {

112 // do nothing. Action doesn't depend on selection.

113 }

114  

115 // ---- IActionDelegate2

116 // ------------------------------------------------

117 

118 public void runWithEvent(IAction action, Event event) {

119 runWithEvent(event);

120 }

121  

122 public void init(IAction action) {

123 // do nothing.

124 }

125 }

上一篇: Dispatch Source
下一篇: Web伺服器

繼續閱讀