Exemplo n.º 1
0
 /**
  * The constructor
  *
  * @param parent
  * @param theDomain
  * @param theCurrentResource
  * @param defaultName
  */
 public ControlResourceDialog(
     Shell parent, EditingDomain theDomain, Resource theCurrentResource, String defaultName) {
   super(parent, EMFEditUIPlugin.INSTANCE.getString("_UI_ControlDialog_title"), SWT.SAVE);
   this.domain = theDomain;
   this.currentResource = theCurrentResource;
   this.defaultName = defaultName;
 }
Exemplo n.º 2
0
 public LoadResourceDialog(Shell parent, EditingDomain domain) {
   super(
       parent,
       EMFEditUIPlugin.INSTANCE.getString("_UI_LoadResourceDialog_title"),
       SWT.OPEN | SWT.MULTI,
       getContextURI(domain));
   this.domain = domain;
 }
Exemplo n.º 3
0
 @Override
 protected boolean processResources() {
   if (domain != null) {
     for (URI uri : getURIs()) {
       try {
         if (!processResource(domain.getResourceSet().getResource(uri, true))) {
           return false;
         }
       } catch (RuntimeException exception) {
         EMFEditUIPlugin.INSTANCE.log(exception);
       }
     }
   }
   return true;
 }
Exemplo n.º 4
0
 public LoadResourceAction() {
   super(EMFEditUIPlugin.INSTANCE.getString("_UI_LoadResource_menu_item"));
   setDescription(EMFEditUIPlugin.INSTANCE.getString("_UI_LoadResource_menu_item_description"));
 }
Exemplo n.º 5
0
  /**
   * Creates and, if it already exists, loads the specified resource. This implementation verifies
   * that a resource can be opened for that URI, that the resource is not the object's current
   * container, and that it is not read-only in the editing domain. If there is an existing resource
   * with that URI, it prompts before overriding or adding to it.
   *
   * @see org.eclipse.emf.common.ui.dialogs.ResourceDialog#processResources()
   */
  protected boolean processResources() {
    URI uri = URI.createURI(getURIText());
    ResourceSet resourceSet = domain.getResourceSet();
    Resource resource = resourceSet.getResource(uri, false);
    boolean resourceInSet = resource != null;

    if (resource == currentResource) {
      MessageDialog.openError(
          getShell(),
          EMFEditUIPlugin.INSTANCE.getString("_UI_InvalidURI_label"),
          EMFEditUIPlugin.INSTANCE.getString("_WARN_AlreadyInResource"));
      return false;
    }
    if (domain.isReadOnly(resource)) {
      MessageDialog.openError(
          getShell(),
          EMFEditUIPlugin.INSTANCE.getString("_UI_InvalidURI_label"),
          EMFEditUIPlugin.INSTANCE.getString("_WARN_ReadOnlyResource"));
      return false;
    }

    boolean resourceExists = false;
    try {
      InputStream stream = resourceSet.getURIConverter().createInputStream(uri);
      if (stream != null) {
        resourceExists = true;
        stream.close();
      }
    } catch (IOException exception) {
      // Do nothing
    }

    boolean resourceBad = false;
    if (!resourceInSet) {
      resource = resourceSet.createResource(uri);
      if (resource == null) {
        MessageDialog.openError(
            getShell(),
            EMFEditUIPlugin.INSTANCE.getString("_UI_InvalidURI_label"),
            EMFEditUIPlugin.INSTANCE.getString("_WARN_CannotCreateResource"));
        return false;
      }

      if (resourceExists) {
        try {
          resource = resourceSet.getResource(uri, true);
        } catch (RuntimeException exception) {
          EMFEditUIPlugin.INSTANCE.log(exception);
          resourceBad = resource.getContents().isEmpty();
        }
      }
    }

    boolean result = true;
    if (resourceBad) {
      result =
          MessageDialog.openQuestion(
              getShell(),
              EMFEditUIPlugin.INSTANCE.getString("_UI_ExistingResource_label"),
              EMFEditUIPlugin.INSTANCE.getString("_WARN_ReplaceResource"));
    } else if (resourceExists) {
      result =
          MessageDialog.openQuestion(
              getShell(),
              EMFEditUIPlugin.INSTANCE.getString("_UI_ExistingResource_label"),
              EMFEditUIPlugin.INSTANCE.getString("_WARN_AddToResource"));
    }

    if (!result && !resourceInSet) {
      resource.unload();
      resourceSet.getResources().remove(resource);
    } else {
      this.controlResource = resource;
    }
    return result;
  }