-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IIP-13 / Feature Add inline actions for impex files #53
Changes from 2 commits
5ee3fe2
23fb49e
0967197
d2586c1
1f2a8a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. | ||
* Copyright (C) 2019 EPAM Systems <[email protected]> | ||
* | ||
* This program 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 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program 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. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.intellij.idea.plugin.hybris.actions; | ||
|
||
import com.intellij.execution.console.ConsoleExecutionEditor; | ||
import com.intellij.execution.console.LanguageConsoleImpl; | ||
import com.intellij.ide.projectView.ProjectView; | ||
import com.intellij.ide.projectView.impl.AbstractProjectViewPane; | ||
import com.intellij.idea.plugin.hybris.tools.remote.console.HybrisConsole; | ||
import com.intellij.idea.plugin.hybris.tools.remote.console.HybrisConsoleToolWindowFactory; | ||
import com.intellij.idea.plugin.hybris.tools.remote.console.view.HybrisConsolePanel; | ||
import com.intellij.idea.plugin.hybris.tools.remote.console.view.HybrisConsolePanelView; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.CommonDataKeys; | ||
import com.intellij.openapi.actionSystem.DataContext; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.wm.ToolWindow; | ||
import com.intellij.openapi.wm.ToolWindowManager; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.tree.TreePath; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public abstract class AbstractCopyFileToHybrisConsoleAction extends AnAction { | ||
|
||
public boolean isRequiredFileExtension( | ||
@NotNull final DataContext dataContext, | ||
final String fileExtension, | ||
final boolean oneFile | ||
) { | ||
boolean isImpex = false; | ||
final List<String> filesName = getFilesName(dataContext); | ||
if (oneFile) { | ||
return filesName.size() == 1 && filesName.get(0).contains(fileExtension); | ||
} else { | ||
for (String name : filesName) { | ||
if (name.contains(fileExtension)) { | ||
isImpex = true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
return isImpex; | ||
} | ||
|
||
private List<String> getFilesName(@NotNull final DataContext dataContext) { | ||
final Object[] files = getFiles(dataContext); | ||
final List<String> names = new ArrayList<>(); | ||
if (files != null) { | ||
for (final Object file : files) { | ||
final TreePath treePath = (TreePath) file; | ||
names.add(treePath.getLastPathComponent().toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't trust to *.toString() |
||
} | ||
} | ||
return names; | ||
} | ||
|
||
public Object[] getFiles(@NotNull final DataContext dataContext) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try not to return the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here we can return array or null ( |
||
final Project project = CommonDataKeys.PROJECT.getData(dataContext); | ||
if (project != null) { | ||
final AbstractProjectViewPane currentProjectViewPane = ProjectView.getInstance(project) | ||
.getCurrentProjectViewPane(); | ||
return currentProjectViewPane.getSelectionPaths(); | ||
} | ||
return new Object[0]; | ||
} | ||
|
||
public HybrisConsolePanel getHybrisConsolePanel(final Project project) { | ||
return HybrisConsolePanelView.Companion.getInstance(Objects.requireNonNull( | ||
project)).getConsolePanel(); | ||
} | ||
|
||
public String getTextFromHybrisConsole(final Project project, final HybrisConsole hybrisConsole) { | ||
final LanguageConsoleImpl.Helper helper = new LanguageConsoleImpl.Helper( | ||
project, | ||
hybrisConsole.getVirtualFile() | ||
); | ||
final ConsoleExecutionEditor consoleExecutionEditor = new ConsoleExecutionEditor(helper); | ||
return consoleExecutionEditor.getDocument().getText(); | ||
} | ||
|
||
public void copyToHybrisConsole( | ||
final Project project, | ||
final String consoleTitle, | ||
final String query | ||
) { | ||
final HybrisConsolePanel hybrisConsolePanel = getHybrisConsolePanel(project); | ||
final HybrisConsole hybrisConsole = hybrisConsolePanel.findConsole(consoleTitle); | ||
if (hybrisConsole != null) { | ||
hybrisConsole.clear(); | ||
hybrisConsole.setInputText(query); | ||
hybrisConsolePanel.setActiveConsole(hybrisConsole); | ||
final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow( | ||
HybrisConsoleToolWindowFactory.ID); | ||
if (toolWindow != null) { | ||
toolWindow.activate(null); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. | ||
* Copyright (C) 2019 EPAM Systems <[email protected]> | ||
* | ||
* This program 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 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program 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. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.intellij.idea.plugin.hybris.flexibleSearch.file.actions; | ||
|
||
import com.intellij.ide.projectView.impl.nodes.PsiFileNode; | ||
import com.intellij.idea.plugin.hybris.actions.AbstractCopyFileToHybrisConsoleAction; | ||
import com.intellij.idea.plugin.hybris.actions.ActionUtils; | ||
import com.intellij.idea.plugin.hybris.tools.remote.console.HybrisConsole; | ||
import com.intellij.idea.plugin.hybris.tools.remote.console.view.HybrisConsolePanel; | ||
import com.intellij.idea.plugin.hybris.toolwindow.CopyFileToHybrisConsoleDialog; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.DataContext; | ||
import com.intellij.openapi.project.Project; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.tree.DefaultMutableTreeNode; | ||
import javax.swing.tree.TreePath; | ||
|
||
public class CopyFlexibleSearchFileAction extends AbstractCopyFileToHybrisConsoleAction { | ||
|
||
private static final String FLEXIBLE_SEARCH_CONSOLE_TITLE = "Hybris FS Console"; | ||
|
||
@Override | ||
public void update(@NotNull final AnActionEvent e) { | ||
final DataContext dataContext = e.getDataContext(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to have |
||
e.getPresentation() | ||
.setEnabledAndVisible(ActionUtils.isHybrisContext(dataContext) && isRequiredFileExtension( | ||
dataContext, ".fxs", true)); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(@NotNull final AnActionEvent e) { | ||
final Project project = e.getProject(); | ||
final TreePath[] files = (TreePath[]) getFiles(e.getDataContext()); | ||
for (final TreePath treePath : files) { | ||
final DefaultMutableTreeNode lastPathNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); | ||
final PsiFileNode file = (PsiFileNode) lastPathNode.getUserObject(); | ||
final HybrisConsolePanel hybrisConsolePanel = getHybrisConsolePanel(project); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you want to check whether the project is not null - then it should be before this line |
||
final HybrisConsole hybrisConsole = hybrisConsolePanel.findConsole(FLEXIBLE_SEARCH_CONSOLE_TITLE); | ||
if (hybrisConsole != null && project != null) { | ||
if (!getTextFromHybrisConsole(project, hybrisConsole).isEmpty()) { | ||
final CopyFileToHybrisConsoleDialog copyFileToHybrisConsoleDialog = new CopyFileToHybrisConsoleDialog(project); | ||
copyFileToHybrisConsoleDialog.setTitle("Flexible Search Console"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. string label is a good candidate to be moved to the property file |
||
if (copyFileToHybrisConsoleDialog.showAndGet()) { | ||
copyToHybrisConsole(project, FLEXIBLE_SEARCH_CONSOLE_TITLE, file.getValue().getText()); | ||
} | ||
} else { | ||
copyToHybrisConsole(project, FLEXIBLE_SEARCH_CONSOLE_TITLE, file.getValue().getText()); | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.intellij.idea.plugin.hybris.impex.file.actions; | ||
|
||
import com.intellij.ide.projectView.impl.nodes.PsiFileNode; | ||
import com.intellij.idea.plugin.hybris.actions.AbstractCopyFileToHybrisConsoleAction; | ||
import com.intellij.idea.plugin.hybris.actions.ActionUtils; | ||
import com.intellij.idea.plugin.hybris.tools.remote.console.HybrisConsole; | ||
import com.intellij.idea.plugin.hybris.tools.remote.console.view.HybrisConsolePanel; | ||
import com.intellij.idea.plugin.hybris.toolwindow.CopyFileToHybrisConsoleDialog; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.DataContext; | ||
import com.intellij.openapi.project.Project; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.tree.DefaultMutableTreeNode; | ||
import javax.swing.tree.TreePath; | ||
|
||
public class CopyImpexFileAction extends AbstractCopyFileToHybrisConsoleAction { | ||
|
||
private static final String IMPEX_CONSOLE_TITLE = "Hybris Impex Console"; | ||
|
||
@Override | ||
public void update(@NotNull final AnActionEvent e) { | ||
final DataContext dataContext = e.getDataContext(); | ||
e.getPresentation() | ||
.setEnabledAndVisible(ActionUtils.isHybrisContext(dataContext) && isRequiredFileExtension( | ||
dataContext, ".impex", false)); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(@NotNull final AnActionEvent e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems that common code could be also moved to AbstractCopyFileToHybrisConsoleAction |
||
final Project project = e.getProject(); | ||
final TreePath[] files = (TreePath[]) getFiles(e.getDataContext()); | ||
final StringBuilder query = new StringBuilder(); | ||
for (final TreePath treePath : files) { | ||
final DefaultMutableTreeNode lastPathNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); | ||
final PsiFileNode file = (PsiFileNode) lastPathNode.getUserObject(); | ||
query.append(file.getValue().getText()).append('\n'); | ||
} | ||
final HybrisConsolePanel hybrisConsolePanel = getHybrisConsolePanel(project); | ||
final HybrisConsole hybrisConsole = hybrisConsolePanel.findConsole(IMPEX_CONSOLE_TITLE); | ||
if (hybrisConsole != null) { | ||
if (!getTextFromHybrisConsole(project, hybrisConsole).isEmpty()) { | ||
final CopyFileToHybrisConsoleDialog copyFileToHybrisConsoleDialog = new CopyFileToHybrisConsoleDialog( | ||
project); | ||
copyFileToHybrisConsoleDialog.setTitle("Impex Console"); | ||
if (copyFileToHybrisConsoleDialog.showAndGet()) { | ||
copyToHybrisConsole(project, IMPEX_CONSOLE_TITLE, query.toString()); | ||
} | ||
} else { | ||
copyToHybrisConsole(project, IMPEX_CONSOLE_TITLE, query.toString()); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.idea.plugin.hybris.toolwindow.CopyFileToHybrisConsoleDialog"> | ||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="10" left="10" bottom="10" right="10"/> | ||
<constraints> | ||
<xy x="241" y="54" width="641" height="94"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<vspacer id="c2d2f"> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
</vspacer> | ||
<component id="b35d6" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="The current request in the console will be replaced with the contents of the file. Save the current changes if necessary."/> | ||
</properties> | ||
</component> | ||
</children> | ||
</grid> | ||
</form> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. | ||
* Copyright (C) 2019 EPAM Systems <[email protected]> | ||
* | ||
* This program 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 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program 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. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.intellij.idea.plugin.hybris.toolwindow; | ||
|
||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.ui.DialogWrapper; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
|
||
import static com.intellij.openapi.ui.DialogWrapper.IdeModalityType.PROJECT; | ||
|
||
public class CopyFileToHybrisConsoleDialog extends DialogWrapper { | ||
|
||
private JPanel contentPane; | ||
|
||
public CopyFileToHybrisConsoleDialog( | ||
@Nullable final Project project | ||
) { | ||
super(project, false, PROJECT); | ||
init(); | ||
} | ||
|
||
@Override | ||
protected @Nullable JComponent createCenterPanel() { | ||
return contentPane; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to have an access to VirtualFile and then check its extension.
Smth like