use of com.liferay.ide.hook.core.model.CustomJspDir in project liferay-ide by liferay.
the class HookXmlEditor method _copyCustomJspsToProject.
private void _copyCustomJspsToProject(IPath portalDir, ElementList<CustomJsp> customJsps) {
try {
Hook hook = getModelElement().nearest(Hook.class);
ElementHandle<CustomJspDir> element = hook.getCustomJspDir();
CustomJspDir customJspDirElement = element.content();
if ((customJspDirElement != null) && customJspDirElement.validation().ok()) {
Path customJspDir = customJspDirElement.getValue().content();
IWebProject webproject = LiferayCore.create(IWebProject.class, getProject());
if (webproject != null) {
IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
IFolder customJspFolder = defaultDocroot.getFolder(customJspDir.toPortableString());
for (CustomJsp customJsp : customJsps) {
String content = customJsp.getValue().content();
if (!empty(content)) {
IFile customJspFile = customJspFolder.getFile(content);
if (!customJspFile.exists()) {
IPath portalJsp = portalDir.append(content);
try {
CoreUtil.makeFolders((IFolder) customJspFile.getParent());
if (portalJsp.toFile().exists()) {
customJspFile.create(Files.newInputStream(portalJsp.toFile().toPath()), true, null);
} else {
CoreUtil.createEmptyFile(customJspFile);
}
} catch (Exception e) {
HookUI.logError(e);
}
}
}
}
}
}
} catch (Exception e) {
HookUI.logError(e);
}
}
use of com.liferay.ide.hook.core.model.CustomJspDir in project liferay-ide by liferay.
the class HookXmlEditor method doSave.
@Override
public void doSave(IProgressMonitor monitor) {
if (customModelDirty) {
Hook hook = getModelElement().nearest(Hook.class);
ElementList<CustomJsp> customJsps = hook.getCustomJsps();
ILiferayProject liferayProject = LiferayCore.create(getProject());
ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
if (portal != null) {
IPath portalDir = portal.getAppServerPortalDir();
if (portalDir != null) {
_copyCustomJspsToProject(portalDir, customJsps);
}
}
customModelDirty = false;
super.doSave(monitor);
firePropertyChange(IEditorPart.PROP_DIRTY);
ElementHandle<CustomJspDir> customJspDir = hook.getCustomJspDir();
if ((customJspDir != null) && !customJspDir.empty()) {
Value<Path> customJspPath = customJspDir.content().getValue();
Path path = customJspPath.content().makeRelative();
String customeJspValue = path.toPortableString();
_configureCustomJspValidation(getProject(), customeJspValue);
}
} else {
super.doSave(monitor);
}
}
use of com.liferay.ide.hook.core.model.CustomJspDir in project liferay-ide by liferay.
the class CustomJspsEnablementService method compute.
@Override
protected Boolean compute() {
boolean enablement = true;
ElementHandle<CustomJspDir> elementHandle = _hook().getCustomJspDir();
CustomJspDir customJspDir = elementHandle.content();
if (customJspDir != null) {
IProject project = _hook().adapt(IProject.class);
Path customJspDirPath = customJspDir.getValue().content(true);
if ((project != null) && (customJspDirPath != null)) {
IWebProject lrproject = LiferayCore.create(IWebProject.class, project);
if (lrproject != null) {
IFolder defaultWebappDir = lrproject.getDefaultDocrootFolder();
if (FileUtil.exists(defaultWebappDir)) {
IFolder customJspFolder = defaultWebappDir.getFolder(PathBridge.create(customJspDirPath));
enablement = FileUtil.exists(customJspFolder);
}
}
}
}
return enablement;
}
use of com.liferay.ide.hook.core.model.CustomJspDir 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 com.liferay.ide.hook.core.model.CustomJspDir in project liferay-ide by liferay.
the class CreateDirectoryActionHandler method run.
@Override
protected Object run(Presentation context) {
try {
Element element = getModelElement();
IProject project = element.adapt(IProject.class);
CustomJspDir customJspDir = (CustomJspDir) element;
Path customJspDirValue = customJspDir.getValue().content(false);
if (customJspDirValue == null) {
customJspDirValue = customJspDir.getValue().content(true);
customJspDir.setValue(customJspDirValue);
}
customJspDir.setValue(customJspDirValue);
RelativePathService service = property().service(RelativePathService.class);
Path absolutePath = service.convertToAbsolute(customJspDirValue);
if (FileUtil.notExists(absolutePath)) {
IWebProject webproject = LiferayCore.create(IWebProject.class, project);
if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
IFolder customJspFolder = defaultDocroot.getFolder(new org.eclipse.core.runtime.Path(customJspDirValue.toPortableString()));
CoreUtil.makeFolders(customJspFolder);
// force a refresh of validation
customJspDir.setValue((Path) null);
customJspDir.setValue(customJspDirValue);
refreshEnablementState();
}
}
} catch (Exception e) {
HookUI.logError(e);
}
return null;
}
Aggregations