@Test public void testInitialFilenameAbsoluteSuccess() throws Exception { IProject project = DOFactory.createDefaultTestProject(parentDir); Assert.assertFalse(project.getMedia().isEmpty()); HashMap<IMedia, String> absolutePathMap = new HashMap<IMedia, String>(); final String basePath = dataFile.getParentFile().getAbsolutePath(); // System.out.println(String.format("BasePath: %s", basePath)); for (IMedia medium : project.getMedia()) { // System.out.println("Media: " + medium.getFilename()); Assert.assertTrue(new File(medium.getAbsoluteFilename()).exists()); absolutePathMap.put(medium, medium.getAbsoluteFilename()); UoW.getCurrent().registerDirty(medium); } UoW.getCurrent().commit(); UoW.newCurrent(); Request request = new Request(); request.set("id", project.getId()); Response response = new Response(); new AdjustToAbsolutePathsCommand(request, response).execute(); Collection<IMedia> actualMedia = (Collection<IMedia>) response.get("media"); for (IMedia medium : actualMedia) { String absolutePath = absolutePathMap.get(medium); Assert.assertEquals(absolutePath, medium.getFilename()); } }
public static void doCreateSnuFromMedia(IMedia media) throws Exception { Application app = Application.getInstance(); // try and find an open editor for a Snu with this media. // if we find one, focus it and abort Collection<ResourceEditor> openEditors = app.getOpenEditors(); for (ResourceEditor editor : openEditors) { IResource editingResource = app.getResourceForEditor(editor); if (editingResource == null) { // i suppose its reasonable that some other code might create an unattached resource editor // but in that case it shouldnt be in the openEditors list Logger.getLogger(CreateSnuAction.class) .info( "no resource for editor: " + editor.getResourceView().getResourceId(), new Exception("just-for-stacktrace")); continue; } if (editingResource instanceof ISnu) { IMedia editingMedia = ((ISnu) editingResource).getMainMedia(); if (editingMedia != null && editingMedia.getId().equals(media.getId())) { editor.toFront(); return; } } if (editingResource instanceof IMedia) { if (editor.getResourceView() instanceof SnuResourceView) { editor.toFront(); return; } } } ResourceEditor editor = app.editNew(ResourceType.SNU, media.getId()); SnuResourceView view = (SnuResourceView) editor.getResourceView(); SnuHelper.initView(view, FileUtil.getFilenameWithoutExtension(media.getName()), media); }