use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.
the class CustomJspDirListener method handleTypedEvent.
@Override
protected void handleTypedEvent(PropertyContentEvent event) {
Property prop = event.property();
Hook hook = prop.element().nearest(Hook.class);
if (hook != null) {
if (CustomJspDir.PROP_VALUE.equals(prop.definition())) {
// IDE-1132, Listen the change of Property CustomJspDir, and refresh the
// Property CustomJsps.
hook.property(Hook.PROP_CUSTOM_JSPS).refresh();
} else if (Hook.PROP_CUSTOM_JSP_DIR.equals(prop.definition())) {
// IDE-1251 listen for changes to custom_jsp_dir and if it is empty initialize
// initial content @InitialValue
CustomJspDir customJspDir = hook.getCustomJspDir().content(false);
if (customJspDir != null) {
Value<Path> value = customJspDir.getValue();
if (value != null) {
Path path = value.content(false);
if (path == null) {
customJspDir.initialize();
}
}
}
}
}
}
use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.
the class LocaleBundleValidationService method compute.
public Status compute() {
Element modelElement = context(Element.class);
if (!modelElement.disposed() && modelElement instanceof SupportedLocales) {
IProject project = modelElement.adapt(IProject.class);
Portlet portlet = modelElement.nearest(Portlet.class);
IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
if (cpEntries != null) {
String locale = modelElement.property(context(ValueProperty.class)).text(false);
Value<Path> resourceBundle = portlet.getResourceBundle();
if (locale == null) {
return Status.createErrorStatus(Resources.localeMustNotEmpty);
} else {
String bundleName = resourceBundle.text();
if ((resourceBundle != null) && (bundleName != null)) {
String localeString = PortletUtil.localeString(locale);
String ioFileName = PortletUtil.convertJavaToIoFileName(bundleName, RB_FILE_EXTENSION, localeString);
for (IClasspathEntry iClasspathEntry : cpEntries) {
if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
entryPath = entryPath.append(ioFileName);
IFile resourceBundleFile = wroot.getFileForLocation(entryPath);
if ((resourceBundleFile != null) && resourceBundleFile.exists()) {
return Status.createOkStatus();
} else {
return Status.createWarningStatus(Resources.bind(StringEscapeUtils.unescapeJava(Resources.noResourceBundle), new Object[] { locale, bundleName, localeString }));
}
}
}
}
}
}
}
return Status.createOkStatus();
}
use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.
the class PortletStyleValidationService method compute.
@Override
protected Status compute() {
Element modelElement = context(Element.class);
if (!modelElement.disposed() && modelElement instanceof PortletStyleElement) {
Path path = (Path) modelElement.property(context(ValueProperty.class)).content();
if (path != null) {
String name = path.lastSegment();
IProject project = modelElement.adapt(IProject.class);
boolean fileExisted = new FileCheckVisitor().checkFiles(project, name);
if (!fileExisted) {
return Status.createErrorStatus("File " + path.toPortableString() + " is not existed");
}
} else {
return Status.createErrorStatus("Can not set empty value");
}
}
return Status.createOkStatus();
}
use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.
the class PluginsSDKProjectProvider method createNewProject.
@Override
public IStatus createNewProject(NewLiferayPluginProjectOp op, IProgressMonitor monitor) throws CoreException {
ElementList<ProjectName> projectNames = op.getProjectNames();
PluginType pluginType = op.getPluginType().content(true);
String originalProjectName = op.getProjectName().content();
String pluginTypeSuffix = NewLiferayPluginProjectOpMethods.getPluginTypeSuffix(pluginType);
String fixedProjectName = originalProjectName;
if (originalProjectName.endsWith(pluginTypeSuffix)) {
fixedProjectName = originalProjectName.substring(0, originalProjectName.length() - pluginTypeSuffix.length());
}
String projectName = fixedProjectName;
String displayName = op.getDisplayName().content(true);
boolean separateJRE = true;
SDK sdk = _getSDK(op);
if (sdk == null) {
return ProjectCore.createErrorStatus("Can not get correct SDK for " + fixedProjectName + ", Please check SDK configuration setting.");
}
// workingDir should always be the directory of the type of plugin /sdk/portlets/ for a portlet, etc
String workingDir = null;
ArrayList<String> arguments = new ArrayList<>();
arguments.add(projectName);
arguments.add(displayName);
boolean hasGradleTools = SDKUtil.hasGradleTools(sdk.getLocation());
IPath newSDKProjectPath = null;
IPath path = null;
switch(pluginType) {
case servicebuilder:
op.setPortletFramework("mvc");
case portlet:
path = sdk.getLocation().append(ISDKConstants.PORTLET_PLUGIN_PROJECT_FOLDER);
String frameworkName = NewLiferayPluginProjectOpMethods.getFrameworkName(op);
workingDir = path.toOSString();
if (hasGradleTools) {
arguments.add(frameworkName);
sdk.createNewProject(projectName, arguments, "portlet", workingDir, monitor);
} else {
newSDKProjectPath = sdk.createNewPortletProject(projectName, displayName, frameworkName, separateJRE, workingDir, null, monitor);
}
break;
case hook:
path = sdk.getLocation().append(ISDKConstants.HOOK_PLUGIN_PROJECT_FOLDER);
workingDir = path.toOSString();
if (hasGradleTools) {
sdk.createNewProject(projectName, arguments, "hook", workingDir, monitor);
} else {
newSDKProjectPath = sdk.createNewHookProject(projectName, displayName, separateJRE, workingDir, null, monitor);
}
break;
case ext:
path = sdk.getLocation().append(ISDKConstants.EXT_PLUGIN_PROJECT_FOLDER);
workingDir = path.toOSString();
if (hasGradleTools) {
sdk.createNewProject(projectName, arguments, "ext", workingDir, monitor);
} else {
newSDKProjectPath = sdk.createNewExtProject(projectName, displayName, separateJRE, workingDir, null, monitor);
}
break;
case layouttpl:
path = sdk.getLocation().append(ISDKConstants.LAYOUTTPL_PLUGIN_PROJECT_FOLDER);
workingDir = path.toOSString();
if (hasGradleTools) {
sdk.createNewProject(projectName, arguments, "layouttpl", workingDir, monitor);
} else {
newSDKProjectPath = sdk.createNewLayoutTplProject(projectName, displayName, separateJRE, workingDir, null, monitor);
}
IProject layoutProject = ProjectUtil.getProject(projectName);
if (!LiferayDescriptorHelper.getDescriptorVersion(layoutProject).equals("6.2.0")) {
IPath projectPath = newSDKProjectPath.append(projectName + pluginTypeSuffix);
IPath fileWap = projectPath.append("docroot").append("blank_columns.wap.tpl");
if (FileUtil.exists(fileWap)) {
fileWap.toFile().delete();
}
}
break;
case theme:
path = sdk.getLocation().append(ISDKConstants.THEME_PLUGIN_PROJECT_FOLDER);
workingDir = path.toOSString();
if (hasGradleTools) {
sdk.createNewProject(projectName, arguments, "theme", workingDir, monitor);
} else {
newSDKProjectPath = sdk.createNewThemeProject(projectName, displayName, separateJRE, workingDir, null, monitor);
}
break;
case web:
path = sdk.getLocation().append(ISDKConstants.WEB_PLUGIN_PROJECT_FOLDER);
workingDir = path.toOSString();
if (hasGradleTools) {
sdk.createNewProject(projectName, arguments, "web", workingDir, monitor);
} else {
newSDKProjectPath = sdk.createNewWebProject(projectName, displayName, separateJRE, workingDir, null, monitor);
}
break;
}
NewLiferayPluginProjectOpMethods.updateLocation(op);
Path projectLocation = op.getLocation().content();
if (!hasGradleTools) {
File projectDir = projectLocation.toFile();
File projectParent = projectDir.getParentFile();
projectParent.mkdirs();
if (FileUtil.notExists(newSDKProjectPath)) {
return ProjectCore.createErrorStatus("Error create project due to '" + newSDKProjectPath + "' does not exist.");
}
File newSDKProjectDir = newSDKProjectPath.toFile();
try {
FileUtils.copyDirectory(newSDKProjectDir, projectParent);
FileUtils.deleteDirectory(newSDKProjectDir);
} catch (IOException ioe) {
throw new CoreException(ProjectCore.createErrorStatus(ioe));
}
}
ProjectRecord projectRecord = ProjectUtil.getProjectRecordForDir(projectLocation.toOSString());
IProject newProject = ProjectImportUtil.importProject(projectRecord.getProjectLocation(), monitor, op);
newProject.open(monitor);
// need to update project name incase the suffix was not correct
op.setFinalProjectName(newProject.getName());
projectNames.insert().setName(op.getFinalProjectName().content());
_projectCreated(newProject);
switch(op.getPluginType().content()) {
case portlet:
_portletProjectCreated(op, newProject, monitor);
break;
case servicebuilder:
PortalBundle bundle = ServerUtil.getPortalBundle(newProject);
_serviceBuilderProjectCreated(bundle.getVersion(), newProject, monitor);
break;
case theme:
_themeProjectCreated(newProject);
break;
default:
break;
}
return Status.OK_STATUS;
}
use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.
the class CreatePortletResourceBundleActionHandler method run.
/**
* (non-Javadoc)
*
* @see
* org.eclipse.sapphire.ui.SapphireActionHandler#run(org.eclipse.sapphire.ui.
* SapphireRenderingContext)
*/
@Override
protected Object run(Presentation context) {
ITextEditor editor = context.part().adapt(ITextEditor.class);
editor.doSave(new NullProgressMonitor());
List<IFile> missingRBFiles = new ArrayList<>();
Portlet portlet = (Portlet) getModelElement();
IProject project = portlet.adapt(IProject.class);
Value<Path> resourceBundle = portlet.getResourceBundle();
String text = resourceBundle.text();
String defaultRBFileName = PortletUtil.convertJavaToIoFileName(text, GenericResourceBundlePathService.RB_FILE_EXTENSION);
int index = text.lastIndexOf(".");
String packageName = "";
if (index == -1) {
index = text.length();
packageName = "";
} else {
packageName = text.substring(0, index);
}
IFolder rbSourceFolder = getResourceBundleFolderLocation(project, defaultRBFileName);
IPath entryPath = rbSourceFolder.getLocation();
PortletInfo portletInfo = portlet.getPortletInfo();
StringBuilder rbFileBuffer = _buildDefaultRBContent(portletInfo);
if (!getFileFromClasspath(project, defaultRBFileName)) {
IFile drbFile = wroot.getFileForLocation(entryPath.append(defaultRBFileName));
missingRBFiles.add(drbFile);
}
// Create bundles for each supported locale for which the resource bundle is
// missing
List<SupportedLocales> supportedLocales = portlet.getSupportedLocales();
for (SupportedLocales iSupportedLocale : supportedLocales) {
if (iSupportedLocale != null) {
String locale = PortletUtil.localeString(iSupportedLocale.getSupportedLocale().text());
String localizedIOFileName = PortletUtil.convertJavaToIoFileName(text, GenericResourceBundlePathService.RB_FILE_EXTENSION, locale);
if (!getFileFromClasspath(project, localizedIOFileName)) {
IFile rbFile = wroot.getFileForLocation(entryPath.append(localizedIOFileName));
missingRBFiles.add(rbFile);
}
}
}
createFiles(context, project, packageName, missingRBFiles, rbFileBuffer);
setEnabled(false);
Portlet p = getModelElement().nearest(Portlet.class);
for (SupportedLocales sl : p.getSupportedLocales()) {
Value<String> locale = sl.getSupportedLocale();
locale.service(LocaleBundleValidationService.class).forceRefresh();
}
return null;
}
Aggregations