/******************************************************************************* * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * *******************************************************************************/ package com.liferay.ide.project.core.model.internal; import com.liferay.ide.core.util.CoreUtil; import com.liferay.ide.project.core.ProjectCore; import com.liferay.ide.project.core.model.NewLiferayPluginProjectOp; import com.liferay.ide.project.core.model.NewLiferayPluginProjectOpMethods; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.sapphire.DefaultValueService; import org.eclipse.sapphire.FilteredListener; import org.eclipse.sapphire.Listener; import org.eclipse.sapphire.PropertyContentEvent; import org.eclipse.sapphire.modeling.Path; /** * @author Kuo Zhang */ public class GroupIdDefaultValueService extends DefaultValueService { @Override protected String compute() { String groupId = null; final Path location = op().getLocation().content(); if( location != null ) { final NewLiferayPluginProjectOp op = op(); final String parentProjectLocation = location.toOSString(); final IPath parentProjectOsPath = org.eclipse.core.runtime.Path.fromOSString( parentProjectLocation ); final String projectName = op().getProjectName().content(); groupId = NewLiferayPluginProjectOpMethods.getMavenParentPomGroupId( op, projectName, parentProjectOsPath ); } if( groupId == null ) { groupId = getDefaultMavenGroupId(); if( CoreUtil.isNullOrEmpty( groupId ) ) { groupId = "com.example.plugins"; } } return groupId; } private String getDefaultMavenGroupId() { final IScopeContext[] prefContexts = { DefaultScope.INSTANCE, InstanceScope.INSTANCE }; final String defaultMavenGroupId = Platform.getPreferencesService().getString( ProjectCore.PLUGIN_ID, ProjectCore.PREF_DEFAULT_PLUGIN_PROJECT_MAVEN_GROUPID, null, prefContexts ); return defaultMavenGroupId; } @Override protected void initDefaultValueService() { super.initDefaultValueService(); final Listener listener = new FilteredListener<PropertyContentEvent>() { @Override protected void handleTypedEvent( PropertyContentEvent event ) { refresh(); } }; op().getLocation().attach( listener ); op().getProjectName().attach( listener ); } private NewLiferayPluginProjectOp op() { return context( NewLiferayPluginProjectOp.class ); } }