forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReindexVersionedIndexesAction.java
75 lines (64 loc) · 2.35 KB
/
ReindexVersionedIndexesAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2uct.actions;
import com.intellij.icons.AllIcons;
import com.intellij.ide.IdeView;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.magento.idea.magento2plugin.project.Settings;
import com.magento.idea.magento2uct.ui.ReindexDialog;
import org.jetbrains.annotations.NotNull;
public class ReindexVersionedIndexesAction extends AnAction {
public static final String ACTION_NAME = "Reindex the UCT versioned indexes";
public static final String ACTION_DESCRIPTION =
"Action provides reindexing feature for the internal UCT framework";
/**
* Action constructor.
*/
public ReindexVersionedIndexesAction() {
super(ACTION_NAME, ACTION_DESCRIPTION, AllIcons.Actions.Execute);
}
@Override
public void update(final @NotNull AnActionEvent event) {
setIsAvailableForEvent(event, false);
final Project project = event.getProject();
if (project == null
|| !Settings.isEnabled(project)
|| !ApplicationManager.getApplication().isInternal()) {
return;
}
setIsAvailableForEvent(event, true);
}
@Override
public void actionPerformed(final @NotNull AnActionEvent event) {
final Project project = event.getProject();
final IdeView ideView = LangDataKeys.IDE_VIEW.getData(event.getDataContext());
if (project == null || ideView == null) {
return;
}
final PsiDirectory directory = ideView.getOrChooseDirectory();
if (directory == null) {
return;
}
ReindexDialog.open(project, directory);
}
/**
* Set is action available for event.
*
* @param event AnActionEvent
* @param isAvailable boolean
*/
private void setIsAvailableForEvent(
final @NotNull AnActionEvent event,
final boolean isAvailable
) {
event.getPresentation().setVisible(isAvailable);
event.getPresentation().setEnabled(isAvailable);
}
}