Package org.eclipse.ui

Examples of org.eclipse.ui.Saveable


    public final Image getImage(Object element) {
        if (element instanceof IWorkbenchPart) {
            return ((IWorkbenchPart) element).getTitleImage();
        }
        if (element instanceof Saveable) {
          Saveable model = (Saveable) element;
          ImageDescriptor imageDesc = model.getImageDescriptor();
          // convert from ImageDescriptor to Image
          if (imageDesc == null) {
        return null;
      }
          Image image = (Image) images.get(imageDesc);
View Full Code Here


                return part.getTitle();
            }
            return part.getTitle() + "  [" + path + "]"; //$NON-NLS-1$ //$NON-NLS-2$
        }
        if (element instanceof Saveable) {
          Saveable model = (Saveable) element;
            String path = model.getToolTipText();
            if (path == null || path.trim().length() == 0) {
                return model.getName();
            }
            return model.getName() + "  [" + path + "]"//$NON-NLS-1$ //$NON-NLS-2$
         
        }
        return null;
    }
View Full Code Here

   */
  private static boolean saveModels(ISaveablesSource modelSource, final IWorkbenchWindow window, final boolean confirm) {
    Saveable[] selectedModels = modelSource.getActiveSaveables();
    final ArrayList dirtyModels = new ArrayList();
    for (int i = 0; i < selectedModels.length; i++) {
      Saveable model = selectedModels[i];
      if (model.isDirty()) {
        dirtyModels.add(model);
      }
    }
    if (dirtyModels.isEmpty()) {
      return true;
    }
   
    // Create save block.
    IRunnableWithProgress progressOp = new IRunnableWithProgress() {
      public void run(IProgressMonitor monitor) {
        IProgressMonitor monitorWrap = new EventLoopProgressMonitor(monitor);
        monitorWrap.beginTask(WorkbenchMessages.Save, dirtyModels.size());
        for (Iterator i = dirtyModels.iterator(); i.hasNext();) {
          Saveable model = (Saveable) i.next();
          // handle case where this model got saved as a result of saving another
          if (!model.isDirty()) {
            monitor.worked(1);
            continue;
          }
          doSaveModel(model, new SubProgressMonitor(monitorWrap, 1),
              window, confirm);
View Full Code Here

   * @since 3.2
   */
  public static boolean needsSave(ISaveablesSource modelSource) {
    Saveable[] selectedModels = modelSource.getActiveSaveables();
    for (int i = 0; i < selectedModels.length; i++) {
      Saveable model = selectedModels[i];
      if (model.isDirty() && !((InternalSaveable)model).isSavingInBackground()) {
        return true;
      }
    }
    return false;
  }
View Full Code Here

    } catch (InterruptedException e) {
      return true;
    }
    // remove saveables that are no longer dirty from the list
    for (Iterator it = modelsToSave.iterator(); it.hasNext();) {
      Saveable model = (Saveable) it.next();
      if (!model.isDirty()) {
        it.remove();
      }
    }
    return false;
  }
View Full Code Here

      if (canceled) {
        return false;
      }
            // Use a simpler dialog if there's only one
            if (modelsToSave.size() == 1) {
              Saveable model = (Saveable) modelsToSave.get(0);
        String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, model.getName());
        // Show a dialog.
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
        MessageDialog d = new MessageDialog(
          shellProvider.getShell(), WorkbenchMessages.Save_Resource,
          null, message, MessageDialog.QUESTION, buttons, 0);
       
        int choice = SaveableHelper.testGetAutomatedResponse();
        if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) {
          choice = d.open();
        }

        // Branch on the user choice.
        // The choice id is based on the order of button labels
        // above.
        switch (choice) {
        case ISaveablePart2.YES: // yes
          break;
        case ISaveablePart2.NO: // no
          return true;
        default:
        case ISaveablePart2.CANCEL: // cancel
          return false;
        }
            }
            else {
              ListSelectionDialog dlg = new ListSelectionDialog(
                      shellProvider.getShell(), modelsToSave,
                      new ArrayContentProvider(),
                      new WorkbenchPartLabelProvider(), RESOURCES_TO_SAVE_MESSAGE);
              dlg.setInitialSelections(modelsToSave.toArray());
              dlg.setTitle(SAVE_RESOURCES_TITLE);
 
              // this "if" statement aids in testing.
              if (SaveableHelper.testGetAutomatedResponse()==SaveableHelper.USER_RESPONSE) {
                int result = dlg.open();
                  //Just return false to prevent the operation continuing
                  if (result == IDialogConstants.CANCEL_ID) {
            return false;
          }
 
                  modelsToSave = Arrays.asList(dlg.getResult());
              }
            }
        }
        else {
          modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources);
    }

        // If the editor list is empty return.
        if (modelsToSave.isEmpty()) {
      return true;
    }
   
    // Create save block.
        final List finalModels = modelsToSave;
    IRunnableWithProgress progressOp = new IRunnableWithProgress() {
      public void run(IProgressMonitor monitor) {
        IProgressMonitor monitorWrap = new EventLoopProgressMonitor(
            monitor);
        monitorWrap.beginTask("", finalModels.size()); //$NON-NLS-1$
        for (Iterator i = finalModels.iterator(); i.hasNext();) {
          Saveable model = (Saveable) i.next();
          // handle case where this model got saved as a result of saving another
          if (!model.isDirty()) {
            monitor.worked(1);
            continue;
          }
          SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), shellProvider, closing || confirm);
          if (monitorWrap.isCanceled()) {
View Full Code Here

    HashSet seen = new HashSet();
    for (Iterator i = parts.iterator(); i.hasNext();) {
      IWorkbenchPart part = (IWorkbenchPart) i.next();
      Saveable[] saveables = getSaveables(part);
      for (int j = 0; j < saveables.length; j++) {
        Saveable saveable = saveables[j];
        if (saveable.isDirty() && !seen.contains(saveable)) {
          seen.add(saveable);
          if (!closing
              || closingLastPartShowingModel(saveable, parts, part
                  .getSite().getPage())) {
            result.add(saveable);
          }
        }
      }
    }
    if (addNonPartSources) {
      SaveablesList saveablesList = (SaveablesList) PlatformUI
          .getWorkbench().getService(
              ISaveablesLifecycleListener.class);
      ISaveablesSource[] nonPartSources = saveablesList
          .getNonPartSources();
      for (int i = 0; i < nonPartSources.length; i++) {
        Saveable[] saveables = nonPartSources[i].getSaveables();
        for (int j = 0; j < saveables.length; j++) {
          Saveable saveable = saveables[j];
          if (saveable.isDirty() && !seen.contains(saveable)) {
            seen.add(saveable);
            result.add(saveable);
          }
        }
      }
View Full Code Here

   * @param modelArray
   */
  private void removeModels(Object source, Saveable[] modelArray) {
    List removed = new ArrayList();
    for (int i = 0; i < modelArray.length; i++) {
      Saveable model = modelArray[i];
      if (removeModel(source, model)) {
        removed.add(model);
      }
    }
    if (removed.size() > 0) {
View Full Code Here

   * @param modelArray
   */
  private void addModels(Object source, Saveable[] modelArray) {
    List added = new ArrayList();
    for (int i = 0; i < modelArray.length; i++) {
      Saveable model = modelArray[i];
      if (addModel(source, model)) {
        added.add(model);
      }
    }
    if (added.size() > 0) {
View Full Code Here

   */
  private boolean promptForSavingIfNecessary(final IWorkbenchWindow window,
      Set modelsClosing, Map modelsDecrementing, boolean canCancel) {
    List modelsToOptionallySave = new ArrayList();
    for (Iterator it = modelsDecrementing.keySet().iterator(); it.hasNext();) {
      Saveable modelDecrementing = (Saveable) it.next();
      if (modelDecrementing.isDirty() && !modelsClosing.contains(modelDecrementing)) {
        modelsToOptionallySave.add(modelDecrementing);
      }
    }
   
    boolean shouldCancel = modelsToOptionallySave.isEmpty() ? false : promptForSaving(modelsToOptionallySave,
        window, window, canCancel, true);
   
    if (shouldCancel) {
      return true;
    }

    List modelsToSave = new ArrayList();
    for (Iterator it = modelsClosing.iterator(); it.hasNext();) {
      Saveable modelClosing = (Saveable) it.next();
      if (modelClosing.isDirty()) {
        modelsToSave.add(modelClosing);
      }
    }
    return modelsToSave.isEmpty() ? false : promptForSaving(modelsToSave,
        window, window, canCancel, false);
View Full Code Here

TOP

Related Classes of org.eclipse.ui.Saveable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.