Пример #1
0
 /**
  * Add a FileFilter to list of file filters to be accepted
  *
  * @param filter FileFilter to be added
  */
 public void add(AbstractFilePersister filter) {
   filters.add(filter);
   String extension = filter.getExtension();
   if (!extensions.contains(extension)) {
     extensions.add(filter.getExtension());
     desc = ((desc == null) ? "" : desc + ", ") + "*." + extension;
   }
 }
Пример #2
0
 /**
  * Find the base name of the given filename.
  *
  * <p>This is the name minus any valid file extension. Invalid extensions are left alone.
  *
  * @param n the given file name
  * @return the name (a String) without extension
  */
 public String getBaseName(String n) {
   AbstractFilePersister p = getPersisterFromFileName(n);
   if (p == null) {
     return n;
   }
   int extLength = p.getExtension().length() + 1;
   return n.substring(0, n.length() - extLength);
 }
Пример #3
0
 /**
  * Load an icon for a supported project file.
  *
  * @param f the file to check
  * @return a nice icon if the file is known as a project file, otherwise a default one
  */
 public Icon getIcon(File f) {
   AbstractFilePersister persister =
       PersistenceManager.getInstance().getPersisterFromFileName(f.getName());
   if (persister != null && persister.hasAnIcon()) {
     return Argo.lookupIconResource("UmlNotation");
   } else {
     return null;
   }
 }
Пример #4
0
 /**
  * @param name the filename
  * @return the persister
  */
 public AbstractFilePersister getPersisterFromFileName(String name) {
   if (defaultPersister.isFileExtensionApplicable(name)) {
     return defaultPersister;
   }
   for (AbstractFilePersister persister : otherPersisters) {
     if (persister.isFileExtensionApplicable(name)) {
       return persister;
     }
   }
   return null;
 }
Пример #5
0
 /** @param chooser the filechooser of which the filters will be set */
 public void setOpenFileChooserFilter(JFileChooser chooser) {
   MultitypeFileFilter mf = new MultitypeFileFilter();
   mf.add(defaultPersister);
   chooser.addChoosableFileFilter(mf);
   chooser.addChoosableFileFilter(defaultPersister);
   Iterator iter = otherPersisters.iterator();
   while (iter.hasNext()) {
     AbstractFilePersister ff = (AbstractFilePersister) iter.next();
     if (ff.isLoadEnabled()) {
       mf.add(ff);
       chooser.addChoosableFileFilter(ff);
     }
   }
   chooser.setFileFilter(mf);
 }
Пример #6
0
  /**
   * @param chooser the filechooser of which the filters will be set
   * @param fileName the filename of the file to be saved (optional)
   */
  public void setSaveFileChooserFilters(JFileChooser chooser, String fileName) {

    chooser.addChoosableFileFilter(defaultPersister);
    AbstractFilePersister defaultFileFilter = defaultPersister;

    for (AbstractFilePersister fp : otherPersisters) {
      if (fp.isSaveEnabled() && !fp.equals(xmiPersister) && !fp.equals(xmlPersister)) {
        chooser.addChoosableFileFilter(fp);
        if (fileName != null && fp.isFileExtensionApplicable(fileName)) {
          defaultFileFilter = fp;
        }
      }
    }
    chooser.setFileFilter(defaultFileFilter);
  }
Пример #7
0
  /**
   * Test remove() function. This is called when a new project is created to remove the old project.
   * We confirm here that the users model has been emptied and that no none 'Model' model elements
   * are at root.
   *
   * @throws InterruptedException if there the project load was interrupted
   * @throws OpenException if there was an error during project load
   * @throws URISyntaxException when the URI can not be formed
   */
  public void testRemove() throws OpenException, InterruptedException, URISyntaxException {
    String name = "/testmodels/uml14/Alittlebitofeverything.zargo";
    URL url = TestProject.class.getResource(name);
    AbstractFilePersister persister =
        PersistenceManager.getInstance().getPersisterFromFileName(name);

    URI uri = url.toURI();
    Project p = persister.doLoad(new File(uri));

    p.remove();

    for (Object root : Model.getFacade().getRootElements()) {
      assertTrue(
          "All roots should be a Model - but found a " + Model.getMetaTypes().getName(root),
          Model.getFacade().isAModel(root));
      System.out.println(
          Model.getFacade().getName(root) + " " + Model.getFacade().getOwnedElements(root).size());
      if ("untitledModel".equals(Model.getFacade().getName(root))) {
        assertEquals(
            "All root models should be empty", 0, Model.getFacade().getOwnedElements(root).size());
      }
    }
  }
Пример #8
0
 /** @return the extension of the default persister (just the text, not the ".") */
 public String getDefaultExtension() {
   return defaultPersister.getExtension();
 }