1 11 package org.eclipse.debug.ui.sourcelookup; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.debug.core.DebugPlugin; 16 import org.eclipse.debug.core.ILaunch; 17 import org.eclipse.debug.core.ILaunchesListener2; 18 import org.eclipse.debug.core.model.IDebugElement; 19 import org.eclipse.debug.core.model.ISourceLocator; 20 import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; 21 import org.eclipse.debug.internal.ui.DebugUIPlugin; 22 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 23 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupManager; 24 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIMessages; 25 import org.eclipse.debug.ui.DebugUITools; 26 import org.eclipse.jface.dialogs.Dialog; 27 import org.eclipse.jface.dialogs.IDialogConstants; 28 import org.eclipse.jface.dialogs.MessageDialog; 29 import org.eclipse.jface.resource.JFaceColors; 30 import org.eclipse.jface.window.Window; 31 import org.eclipse.swt.SWT; 32 import org.eclipse.swt.events.SelectionAdapter; 33 import org.eclipse.swt.events.SelectionEvent; 34 import org.eclipse.swt.layout.GridData; 35 import org.eclipse.swt.layout.GridLayout; 36 import org.eclipse.swt.widgets.Button; 37 import org.eclipse.swt.widgets.Composite; 38 import org.eclipse.swt.widgets.Text; 39 import org.eclipse.ui.IEditorInput; 40 import org.eclipse.ui.IEditorPart; 41 import org.eclipse.ui.IEditorSite; 42 import org.eclipse.ui.IReusableEditor; 43 import org.eclipse.ui.IWorkbenchPage; 44 import org.eclipse.ui.IWorkbenchWindow; 45 import org.eclipse.ui.PartInitException; 46 import org.eclipse.ui.PlatformUI; 47 import org.eclipse.ui.part.EditorPart; 48 49 63 public class CommonSourceNotFoundEditor extends EditorPart implements IReusableEditor { 64 65 68 private Text fText; 69 70 73 private ILaunchesListener2 fLaunchesListener; 74 75 78 public void doSave(IProgressMonitor monitor) { 79 } 80 81 84 public void doSaveAs() { 85 } 86 87 90 public void init(IEditorSite site, IEditorInput input) throws PartInitException { 91 setSite(site); 92 setInput(input); 93 initialize(); 94 } 95 96 99 public boolean isDirty() { 100 return false; 101 } 102 103 106 public boolean isSaveAsAllowed() { 107 return false; 108 } 109 110 113 public void createPartControl(Composite parent) { 114 GridLayout topLayout = new GridLayout(); 115 GridData data = new GridData(); 116 topLayout.numColumns = 1; 117 topLayout.verticalSpacing = 10; 118 parent.setLayout(topLayout); 119 parent.setLayoutData(data); 120 parent.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); 121 122 fText = new Text(parent,SWT.READ_ONLY|SWT.WRAP); 123 data = new GridData(GridData.FILL_HORIZONTAL); 124 data.grabExcessHorizontalSpace = true; 125 fText.setLayoutData(data); 126 fText.setForeground(JFaceColors.getErrorText(fText.getDisplay())); 127 fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); 128 if (getEditorInput() != null) { 129 setInput(getEditorInput()); 130 } 131 132 createButtons(parent); 133 134 Dialog.applyDialogFont(parent); 135 136 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IDebugHelpContextIds.NO_SOURCE_EDITOR); 137 } 138 139 144 protected void createButtons(Composite parent) { 145 GridData data; 146 Button button = new Button(parent, SWT.PUSH); 147 data = new GridData(); 148 data.grabExcessHorizontalSpace = false; 149 data.grabExcessVerticalSpace = false; 150 button.setLayoutData(data); 151 button.setText(SourceLookupUIMessages.addSourceLocation_addButton2); 152 button.addSelectionListener(new SelectionAdapter() { 153 public void widgetSelected(SelectionEvent evt) { 154 editSourceLookupPath(); 155 } 156 }); 157 } 158 159 164 protected void editSourceLookupPath(){ 165 ISourceLocator locator = null; 166 ILaunch launch = null; 167 IAdaptable selection = DebugUITools.getDebugContext(); 168 if(selection == null) { 169 new MessageDialog(getSite().getShell(), 170 SourceLookupUIMessages.CommonSourceNotFoundEditor_0, 171 null, 172 SourceLookupUIMessages.CommonSourceNotFoundEditor_1, 173 MessageDialog.INFORMATION, 174 new String [] {IDialogConstants.OK_LABEL}, 0).open(); 175 return; 176 } 177 if (selection.getAdapter(ILaunch.class) != null ) { 178 launch = (ILaunch) selection.getAdapter(ILaunch.class); 179 locator = launch.getSourceLocator(); 180 } 181 else if (selection.getAdapter(IDebugElement.class) != null ) { 182 launch = ((IDebugElement)selection.getAdapter(IDebugElement.class)).getLaunch(); 183 locator = launch.getSourceLocator(); 184 } 185 else { 186 return; } 188 if (locator == null || !(locator instanceof AbstractSourceLookupDirector)) { 189 return; 190 } 191 final SourceLookupDialog dialog = new SourceLookupDialog(DebugUIPlugin.getShell(),(AbstractSourceLookupDirector) locator); 192 if(dialog.open() == Window.OK) { 193 IWorkbenchPage page = getEditorSite().getPage(); 194 SourceLookupManager.getDefault().displaySource(getArtifact(), page, true); 195 closeEditor(); 196 } 197 } 198 199 202 public void setFocus() { 203 if (fText != null) { 204 fText.setFocus(); 205 } 206 } 207 208 211 public void setInput(IEditorInput input) { 212 super.setInput(input); 213 setPartName(input.getName()); 214 if (fText != null) { 215 fText.setText(getText()); 216 } 217 firePropertyChange(PROP_INPUT); 218 } 219 220 226 protected String getText() { 227 return getEditorInput().getToolTipText() + "\n"; } 229 230 233 protected void closeEditor() 234 { 235 final IEditorPart editor = this; 236 DebugUIPlugin.getStandardDisplay().syncExec(new Runnable () { 237 public void run() { 238 IWorkbenchWindow activeWorkbenchWindow = DebugUIPlugin.getActiveWorkbenchWindow(); 239 if (activeWorkbenchWindow != null) { 240 IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); 241 if (activePage != null) { 242 activePage.closeEditor(editor, false); 243 } 244 } 245 } 246 }); 247 } 248 249 250 255 public void dispose() { 256 if (fLaunchesListener != null) 257 DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(fLaunchesListener); 258 super.dispose(); 259 } 260 261 267 protected Object getArtifact() { 268 IEditorInput editorInput = getEditorInput(); 269 if (editorInput instanceof CommonSourceNotFoundEditorInput) { 270 CommonSourceNotFoundEditorInput input = (CommonSourceNotFoundEditorInput) editorInput; 271 return input.getArtifact(); 272 } 273 return null; 274 } 275 276 282 protected void initialize() 283 { 284 fLaunchesListener = new ILaunchesListener2() { 285 public void launchesTerminated(ILaunch[] launches) { 286 Object artifact = getArtifact(); 287 if (artifact instanceof IDebugElement) { 288 IDebugElement element = (IDebugElement)artifact; 289 for (int i = 0; i < launches.length; i++) { 290 ILaunch launch = launches[i]; 291 if (launch.equals(element.getLaunch())) { 292 closeEditor(); 293 return; 294 } 295 } 296 } 297 } 298 299 public void launchesRemoved(ILaunch[] launches) { 300 launchesTerminated(launches); 301 } 302 303 public void launchesAdded(ILaunch[] launches) { 304 } 305 306 public void launchesChanged(ILaunch[] launches) { 307 }}; 308 309 DebugPlugin.getDefault().getLaunchManager().addLaunchListener(fLaunchesListener); 310 } 311 } 312 313 314 | Popular Tags |