| | 257 | // ---------------------------------------------------------- |
| | 258 | /* |
| | 259 | * @see EditorPart#setInput(org.eclipse.ui.IEditorInput) |
| | 260 | */ |
| | 261 | @Override |
| | 262 | public final void setInput(IEditorInput input) |
| | 263 | { |
| | 264 | System.out.println("ComponentEditor.setInput(): " + input.getName()); |
| | 265 | setInputWithNotify(input); |
| | 266 | } |
| | 267 | |
| | 268 | |
| | 269 | // ---------------------------------------------------------- |
| | 270 | public void close() |
| | 271 | { |
| | 272 | close(isConnectedToFile() && isDirty()); |
| | 273 | } |
| | 274 | |
| | 275 | |
| | 276 | // ---------------------------------------------------------- |
| | 277 | public void close(final boolean save) |
| | 278 | { |
| | 279 | Display display= getSite().getShell().getDisplay(); |
| | 280 | display.asyncExec(new Runnable() |
| | 281 | { |
| | 282 | public void run() |
| | 283 | { |
| | 284 | getSite().getPage().closeEditor(ComponentEditor.this, save); |
| | 285 | } |
| | 286 | }); |
| | 287 | } |
| | 288 | |
| | 289 | |
| | 290 | //~ Protected Methods ..................................................... |
| | 291 | |
| | 292 | // ---------------------------------------------------------- |
| | 293 | protected IFile getFile() |
| | 294 | { |
| | 295 | IFileEditorInput input = getFileInput(); |
| | 296 | return input == null |
| | 297 | ? null |
| | 298 | : input.getFile(); |
| | 299 | } |
| | 300 | |
| | 301 | |
| | 302 | // ---------------------------------------------------------- |
| | 303 | /* |
| | 304 | * @see org.eclipse.ui.part.EditorPart#setInputWithNotify(org.eclipse.ui.IEditorInput) |
| | 305 | * @since 3.2 |
| | 306 | */ |
| | 307 | protected final void setInputWithNotify(IEditorInput input) |
| | 308 | { |
| | 309 | try |
| | 310 | { |
| | 311 | doSetInput(input); |
| | 312 | |
| | 313 | /* |
| | 314 | * The following bugs explain why we fire this property change: |
| | 315 | * https://bugs.eclipse.org/bugs/show_bug.cgi?id=90283 |
| | 316 | * https://bugs.eclipse.org/bugs/show_bug.cgi?id=92049 |
| | 317 | * https://bugs.eclipse.org/bugs/show_bug.cgi?id=92286 |
| | 318 | */ |
| | 319 | firePropertyChange(IEditorPart.PROP_INPUT); |
| | 320 | } |
| | 321 | catch (CoreException x) |
| | 322 | { |
| | 323 | String title= "Problem while opening"; |
| | 324 | String msg= "Cannot open input element:"; |
| | 325 | Shell shell= getSite().getShell(); |
| | 326 | ErrorDialog.openError(shell, title, msg, x.getStatus()); |
| | 327 | } |
| | 328 | } |
| | 329 | |
| | 330 | |
| | 331 | // ---------------------------------------------------------- |
| | 332 | /** |
| | 333 | * Called directly from <code>setInput</code> and from within a workspace |
| | 334 | * runnable from <code>init</code>, this method does the actual setting |
| | 335 | * of the editor input. Closes the editor if <code>input</code> is |
| | 336 | * <code>null</code>. Disconnects from any previous editor input and its |
| | 337 | * document provider and connects to the new one. |
| | 338 | * <p> |
| | 339 | * Subclasses may extend. |
| | 340 | * </p> |
| | 341 | * |
| | 342 | * @param input the input to be set |
| | 343 | * @exception CoreException if input cannot be connected to the document |
| | 344 | * provider |
| | 345 | */ |
| | 346 | protected void doSetInput(IEditorInput input) |
| | 347 | throws CoreException |
| | 348 | { |
| | 349 | if (input == null) |
| | 350 | { |
| | 351 | close(isConnectedToFile() && isSaveOnCloseNeeded()); |
| | 352 | } |
| | 353 | else |
| | 354 | { |
| | 355 | super.setInput(input); |
| | 356 | // need to load the project |
| | 357 | initializeTitle(input); |
| | 358 | |
| | 359 | // TODO: refresh controls |
| | 360 | } |
| | 361 | } |
| | 362 | |
| | 363 | |
| | 364 | //~ Private Methods ....................................................... |
| | 365 | |
| | 366 | // ---------------------------------------------------------- |
| | 367 | /** |
| | 368 | * Initializes the editor's title based on the given editor input. |
| | 369 | * |
| | 370 | * @param input |
| | 371 | * the editor input to be use |
| | 372 | */ |
| | 373 | private void initializeTitle(IEditorInput input) |
| | 374 | { |
| | 375 | Image oldImage = titleImage; |
| | 376 | titleImage = null; |
| | 377 | String title = ""; |
| | 378 | |
| | 379 | if (input != null) |
| | 380 | { |
| | 381 | IEditorRegistry editorRegistry = |
| | 382 | PlatformUI.getWorkbench().getEditorRegistry(); |
| | 383 | IEditorDescriptor editorDesc = |
| | 384 | editorRegistry.findEditor(getSite().getId()); |
| | 385 | ImageDescriptor imageDesc = editorDesc != null |
| | 386 | ? editorDesc.getImageDescriptor() |
| | 387 | : null; |
| | 388 | |
| | 389 | titleImage = imageDesc != null ? imageDesc.createImage() : null; |
| | 390 | title = input.getName(); |
| | 391 | } |
| | 392 | |
| | 393 | setTitleImage(titleImage); |
| | 394 | setPartName(title); |
| | 395 | |
| | 396 | firePropertyChange(PROP_DIRTY); |
| | 397 | |
| | 398 | if (oldImage != null && !oldImage.isDisposed()) |
| | 399 | { |
| | 400 | oldImage.dispose(); |
| | 401 | } |
| | 402 | } |
| | 403 | |
| | 404 | |
| | 405 | // ---------------------------------------------------------- |
| | 406 | public boolean isConnectedToFile() |
| | 407 | { |
| | 408 | return getEditorInput() instanceof IFileEditorInput; |
| | 409 | } |
| | 410 | |
| | 411 | |
| | 412 | // ---------------------------------------------------------- |
| | 413 | public IFileEditorInput getFileInput() |
| | 414 | { |
| | 415 | return isConnectedToFile() |
| | 416 | ? (IFileEditorInput)getEditorInput() |
| | 417 | : null; |
| | 418 | } |
| | 419 | |
| | 420 | |
| | 421 | // ---------------------------------------------------------- |
| | 422 | public ComponentEditorInput getComponentInput() |
| | 423 | { |
| | 424 | return isConnectedToFile() |
| | 425 | ? null |
| | 426 | : (ComponentEditorInput)getEditorInput(); |
| | 427 | } |
| | 428 | |
| | 429 | |