use of com.intellij.struts2.facet.ui.StrutsFileSet in project intellij-plugins by JetBrains.
the class StrutsFacetConfiguration method writeExternal.
public void writeExternal(final Element element) throws WriteExternalException {
for (final StrutsFileSet fileSet : myFileSets) {
final Element setElement = new Element(FILESET);
setElement.setAttribute(SET_ID, fileSet.getId());
setElement.setAttribute(SET_NAME, fileSet.getName());
setElement.setAttribute(SET_REMOVED, Boolean.toString(fileSet.isRemoved()));
element.addContent(setElement);
for (final VirtualFilePointer fileName : fileSet.getFiles()) {
final Element fileElement = new Element(FILE);
fileElement.setText(fileName.getUrl());
setElement.addContent(fileElement);
}
}
final Element propertiesElement = new Element(PROPERTIES_KEYS);
propertiesElement.setAttribute(PROPERTIES_KEYS_DISABLED, Boolean.toString(myPropertiesKeysDisabled));
element.addContent(propertiesElement);
}
use of com.intellij.struts2.facet.ui.StrutsFileSet in project intellij-plugins by JetBrains.
the class StrutsFrameworkSupportProvider method onFacetCreated.
@Override
protected void onFacetCreated(final StrutsFacet strutsFacet, final ModifiableRootModel modifiableRootModel, final FrameworkVersion version) {
final Module module = strutsFacet.getModule();
StartupManager.getInstance(module.getProject()).runWhenProjectIsInitialized(() -> DumbService.getInstance(module.getProject()).runWhenSmart(() -> {
final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots();
if (sourceRoots.length <= 0) {
return;
}
final PsiDirectory directory = PsiManager.getInstance(module.getProject()).findDirectory(sourceRoots[0]);
if (directory == null || directory.findFile(StrutsConstants.STRUTS_XML_DEFAULT_FILENAME) != null) {
return;
}
final StrutsFileTemplateProvider templateProvider = new StrutsFileTemplateProvider(module);
final FileTemplate strutsXmlTemplate = templateProvider.determineFileTemplate(directory.getProject());
try {
final StrutsFacetConfiguration strutsFacetConfiguration = strutsFacet.getConfiguration();
// create empty struts.xml & fileset with all found struts-*.xml files (struts2.jar, plugins)
final PsiElement psiElement = FileTemplateUtil.createFromTemplate(strutsXmlTemplate, StrutsConstants.STRUTS_XML_DEFAULT_FILENAME, null, directory);
final Set<StrutsFileSet> empty = Collections.emptySet();
final StrutsFileSet fileSet = new StrutsFileSet(StrutsFileSet.getUniqueId(empty), StrutsFileSet.getUniqueName("Default File Set", empty), strutsFacetConfiguration);
fileSet.addFile(((XmlFile) psiElement).getVirtualFile());
final StrutsConfigsSearcher searcher = new StrutsConfigsSearcher(module);
DumbService.getInstance(module.getProject()).runWhenSmart(() -> searcher.search());
final MultiMap<VirtualFile, PsiFile> jarConfigFiles = searcher.getJars();
for (final VirtualFile virtualFile : jarConfigFiles.keySet()) {
final Collection<PsiFile> psiFiles = jarConfigFiles.get(virtualFile);
for (final PsiFile psiFile : psiFiles) {
fileSet.addFile(psiFile.getVirtualFile());
}
}
strutsFacetConfiguration.getFileSets().add(fileSet);
// create filter & mapping in web.xml (if present)
new WriteCommandAction.Simple(modifiableRootModel.getProject()) {
protected void run() throws Throwable {
final WebFacet webFacet = strutsFacet.getWebFacet();
final ConfigFile configFile = webFacet.getWebXmlDescriptor();
if (configFile == null)
return;
final XmlFile webXmlFile = configFile.getXmlFile();
final WebApp webApp = JamCommonUtil.getRootElement(webXmlFile, WebApp.class, null);
if (webApp == null)
return;
if (!FileModificationService.getInstance().prepareFileForWrite(webXmlFile))
return;
final Filter strutsFilter = webApp.addFilter();
strutsFilter.getFilterName().setStringValue("struts2");
@NonNls final String filterClass = templateProvider.is21orNewer() ? StrutsConstants.STRUTS_2_1_FILTER_CLASS : StrutsConstants.STRUTS_2_0_FILTER_CLASS;
strutsFilter.getFilterClass().setStringValue(filterClass);
final FilterMapping filterMapping = webApp.addFilterMapping();
filterMapping.getFilterName().setValue(strutsFilter);
filterMapping.addUrlPattern().setStringValue("/*");
}
}.execute();
final NotificationListener showFacetSettingsListener = new NotificationListener() {
public void hyperlinkUpdate(@NotNull final Notification notification, @NotNull final HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
notification.expire();
ModulesConfigurator.showFacetSettingsDialog(strutsFacet, null);
}
}
};
Notifications.Bus.notify(new Notification("Struts 2", "Struts 2 Setup", "Struts 2 Facet has been created, please check <a href=\"more\">created fileset</a>", NotificationType.INFORMATION, showFacetSettingsListener), module.getProject());
} catch (Exception e) {
LOG.error("error creating struts.xml from template", e);
}
}));
}
use of com.intellij.struts2.facet.ui.StrutsFileSet in project intellij-plugins by JetBrains.
the class Struts2GraphFileEditorProvider method accept.
public boolean accept(@NotNull final Project project, @NotNull final VirtualFile file) {
if (!file.isValid()) {
return false;
}
final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (!(psiFile instanceof XmlFile)) {
return false;
}
if (psiFile instanceof JspFile) {
return false;
}
if (!StrutsManager.getInstance(project).isStruts2ConfigFile((XmlFile) psiFile)) {
return false;
}
final Module module = ModuleUtilCore.findModuleForFile(file, project);
if (module == null) {
return false;
}
final Set<StrutsFileSet> fileSets = StrutsManager.getInstance(project).getAllConfigFileSets(module);
for (final StrutsFileSet fileSet : fileSets) {
if (fileSet.hasFile(file)) {
return true;
}
}
return false;
}
Aggregations