public Collection<ProjectVersion> getBranches(IModel<ProjectVersion> current) { if(current==null) return Collections.emptyList(); Project parent = current.getObject().getParent(); if(parent==null && current instanceof AttachableModel) { AttachableModel<ProjectVersion> model = (AttachableModel<ProjectVersion>)current; parent = (Project) model.getParent().getObject(); } if(parent==null) return Collections.emptyList(); return parent.getChildren(); }
public boolean isVisible() { ProjectVersion version = model.getObject(); TeamProvider provider = TeamProviderUtil.getTeamProvider(version.getParent().getTeamProvider()); if (provider == null) return false; File file = new File(version.absoluteFilePath().toFileString()); return (file.isDirectory()); }; };
public static void addNewLocale(ProjectLocale locale, ProjectVersion version) { ProjectLocale template = version.getTemplate(); version.getChildren().add(locale); if(template==null) { //we always need a template template = PropertiesFactory.eINSTANCE.createProjectLocale(); version.setTemplate(template); template.setName("template"); version.getChildren().add(template); } createMissingChildren(template, locale); }
@Override public ProjectVersion apply(ProjectVersion object) { object.partialScan(PreferencesUtil.getScanConfigForProject(object.getParent()), diff); return object; } });
private void createTerminologyProject(Project parent) throws IOException { ProjectVersion version = PropertiesFactory.eINSTANCE.createProjectVersion(); version.setName("master"); version.setParent(parent); URL url = new URL(MessageFormat.format(TERMINOLOGY_DOWNLOAD_URL, "de")); createMessageFile(url.openStream(), version.absoluteFilePath().appendSegment("messages.properties"),true); for (String language : TERMINOLOGY_LANGUAGES) { url = new URL(MessageFormat.format(TERMINOLOGY_DOWNLOAD_URL, language)); createMessageFile(url.openStream(),version.absoluteFilePath().appendSegment("messages_"+language+".properties"),false); } ScanConfiguration scanConfiguration = PreferencesUtil.getScanConfigForProject(parent); version.fullScan(scanConfiguration); }
private static boolean hasPermission(PropertyFileDescriptor model, Session session, String permission) { ProjectVersion version = model.getProjectLocale().getParent(); if (version.isReadOnly()) return false; if (session instanceof CDOAuthenticatedSession) { Project project = version.getParent(); CDOAuthenticatedSession authSession = (CDOAuthenticatedSession) session; return authSession.hasPermission(CommonPermissions.constructPermission(CommonPermissions.PROJECT, project.getName(), permission)); } return false; }
@Override public Project apply(Project object) { ProjectVersion child = PropertiesFactory.eINSTANCE.createProjectVersion(); ProjectLocale locale = PropertiesFactory.eINSTANCE.createProjectLocale(); child.getChildren().add(locale); child.setTemplate(locale); child.setName(uri.lastSegment()); object.getChildren().add(child); return object; } });
@Override protected void onAfterSubmit(AjaxRequestTarget target, Form<?> form) { ProjectVersion projectVersion = model.getObject(); CDOTransaction transaction = Activator.getDefault().getRepositoryConnector().openTransaction(); projectVersion = transaction.getObject(projectVersion); Preferences preferences = PreferencesUtil.scopeFor(projectVersion); try { PreferencesUtil.deleteNode(preferences); File directory = new File(projectVersion.absolutPath().toFileString()); FileUtil.delete(directory); projectVersion.getParent().getChildren().remove(projectVersion); transaction.commit(); setResponsePage(SettingsPage.class, getPage().getPageParameters()); } catch (CommitException e) { logger.error("Commit failed",e); getSession().error(e.getMessage()); } catch (BackingStoreException e) { logger.error("Failed to delete project preferences",e); getSession().error(e.getMessage()); } finally { transaction.close(); } }
public ProjectLocale getOrCreateProjectLocale(Locale locale) { ProjectLocale projectLocale = getProjectVersion().getProjectLocale(locale); if (projectLocale == null) { projectLocale = PropertiesFactory.eINSTANCE.createProjectLocale(); projectLocale.setLocale(locale); getProjectVersion().getChildren().add(projectLocale); } return projectLocale; }
public static void createMissingDescriptorEntries(ProjectVersion parent, IProgressMonitor monitor) { EList<ProjectLocale> children = parent.getChildren(); monitor.beginTask("Adding missing localized resources", children.size() - 1); ProjectLocale template = parent.getTemplate(); for (ProjectLocale locale : children) { if (locale == template) continue; if (locale != null && locale.getLocale() != null) monitor.subTask("Add missing entries for " + locale.getLocale().getDisplayName()); createMissingChildren(template, locale); monitor.worked(1); } monitor.subTask(""); monitor.done(); }
public static URI computeLocaleResourceLocation(Locale locale, ProjectVersion version, URI templateLocation) { PropertyScanner scanner = createScanner(version); URI parentPath = version.absoluteFilePath(); String childPath = templateLocation.path(); if (childPath != null && !childPath.startsWith("/")) childPath = "/" + childPath; File path = scanner.computeTranslationPath(new File(URI.decode(parentPath.path()) + URI.decode(childPath)), version.getTemplate().getLocale(), locale); /* * workaround for https://github.com/jutzig/jabylon/issues/238 certain * issues seem to trigger a bug in EMFs createFileURI */ URI location = URI.createURI(path.getAbsolutePath().replace('\\','/')); URI trimmedLocation = URI.createURI(location.segment(parentPath.segmentCount())); for (int i = parentPath.segmentCount() + 1; i < location.segmentCount(); i++) { // append the other segments trimmedLocation = trimmedLocation.appendSegment(location.segment(i)); } return trimmedLocation; }
@Override protected void populateItem(ListItem<ProjectVersion> item) { item.setOutputMarkupId(true); item.add(new Label("name", item.getModelObject().getName())); item.add(new Label("summary", new StringResourceModel("ProjectVersionsConfigSection.summary", item, null, item.getModel().getObject().getChildren().size()))); progressModel = new ProgressionModel(""); final ProgressPanel progressPanel = new ProgressPanel("progress", progressModel); item.add(progressPanel); ProjectVersion projectVersion = item.getModelObject(); item.add(new BookmarkablePageLink<Void>("edit",SettingsPage.class,WicketUtil.buildPageParametersFor(projectVersion))); item.add(createCheckoutAction(progressPanel, item.getModel())); item.add(createRescanAction(progressPanel, item.getModel())); item.add(createUpdateAction(progressPanel, item.getModel())); item.add(createResetAction(progressPanel, item.getModel())); item.add(createCommitAction(progressPanel, item.getModel())); item.add(createDeleteAction(progressPanel, item.getModel())); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ public boolean isMaster() { return getParent()!=null && getParent().getTemplate()==this; }
/** * Helper method. Create Map with K=Template Name, V=Descriptor.<br> * * This associates a property descriptor with the path of its respective template for faster lookups.<br> */ private Map<String, PropertyFileDescriptor> loadDescriptorsForLocale(Locale locale) { Map<String, PropertyFileDescriptor> ret = new LinkedHashMap<String, PropertyFileDescriptor>(); List<PropertyFileDescriptor> descriptors = null; /* * Load the List of descriptors available for this locale.<br> * Note that a null locale implies that either no source language was selected, or the * selected source language is the template language.<br> */ if (locale == null) { descriptors = projectVersion.getTemplate().getDescriptors(); } else { descriptors = projectVersion.getProjectLocale(locale).getDescriptors(); } for (PropertyFileDescriptor descriptor : descriptors) { ret.put(descriptor.isMaster() ? descriptor.getLocation().toString() : descriptor.getMaster().getLocation().toString(), descriptor); } return ret; }
/** * calculates a diff between existing locales and selected ones. * Deletes and adds ProjectLocales as needed * @param object * @param input */ protected void applyLocaleList(List<String> object, IModel<ProjectVersion> input) { Set<String> locales = new HashSet<String>(object); ProjectVersion version = input.getObject(); List<ProjectLocale> projectLocales = version.getChildren(); List<ProjectLocale> toDelete = new ArrayList<>(); for (Iterator<ProjectLocale> iterator = projectLocales.iterator(); iterator.hasNext();) { ProjectLocale projectLocale = iterator.next(); if(projectLocale.isMaster()) continue; if(!locales.remove(projectLocale.getName())) { toDelete.add(projectLocale); } } for (ProjectLocale projectLocale : toDelete) { LOGGER.info("Deleting ProjectLocale {} from {}",projectLocale.getName(), version.fullPath()); EcoreUtil.delete(projectLocale, true); } for (String locale : locales) { ProjectLocale projectLocale = PropertiesFactory.eINSTANCE.createProjectLocale(); projectLocale.setLocale((Locale) PropertiesFactory.eINSTANCE.createFromString(PropertiesPackage.Literals.LOCALE, locale)); LOGGER.info("Adding ProjectLocale {} to {}",projectLocale.getName(), version.fullPath()); PropertyResourceUtil.addNewLocale(projectLocale, input.getObject()); } }
/** * @return a populated list of {@link Language}s for the given {@link ProjectVersion}.<br> */ private static List<Language> loadLanguages(Resolvable<?, ?> object) { List<Language> meta = new ArrayList<Language>(); List<ProjectLocale> projectLocales = ((ProjectVersion) object).getChildren(); for (ProjectLocale projectLocale : projectLocales) { meta.add(new Language(projectLocale.getLocale())); } return meta; } }
public static URI computeTemplateResourceLocation(Locale locale, URI translationLocation, Locale masterLocale, ProjectVersion version) { PropertyScanner scanner = createScanner(version); URI parentPath = version.absoluteFilePath(); File path = scanner.findTemplate(new File(parentPath.path()+translationLocation.toString()), null); URI location = URI.createFileURI(path.getAbsolutePath()); URI trimmedLocation = URI.createURI(location.segment(parentPath.segmentCount())); for (int i = parentPath.segmentCount()+1; i < location.segmentCount(); i++) { //append the other segments trimmedLocation = trimmedLocation.appendSegment(location.segment(i)); } return trimmedLocation; }
private TermQuery createVersionQuery(ProjectVersion version) { return new TermQuery(new Term(FIELD_VERSION, version.getName())); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ public void fullScan(ScanConfiguration configuration) { for (ProjectVersion version : getChildren()) { version.fullScan(configuration, null); } }