Skip to content

Commit

Permalink
created two sync actions (for both to project and to midpoint directi…
Browse files Browse the repository at this point in the history
…ons)
  • Loading branch information
1azyman committed Apr 23, 2024
1 parent 77a6c11 commit e91e0d2
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.evolveum.midpoint.studio.action.transfer;

import com.evolveum.midpoint.studio.impl.Environment;
import com.evolveum.midpoint.studio.impl.EnvironmentService;
import com.evolveum.midpoint.studio.ui.diff.SynchronizationDirection;
import com.evolveum.midpoint.studio.ui.diff.SynchronizationManager;
import com.evolveum.midpoint.studio.util.MidPointUtils;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.util.List;

public class SynchronizeObjectsAction extends AnAction implements DumbAware {

private final String actionName;

private final SynchronizationDirection direction;

public SynchronizeObjectsAction(
@NotNull String actionName, @NotNull Icon icon, @NotNull SynchronizationDirection direction) {

super(actionName, null, icon);

this.actionName = actionName;
this.direction = direction;
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}

@Override
public void update(@NotNull AnActionEvent evt) {
super.update(evt);

boolean enabled = MidPointUtils.shouldEnableAction(evt);
evt.getPresentation().setEnabled(enabled);

evt.getPresentation().setVisible(MidPointUtils.isDevelopmentMode(true));
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project == null) {
return;
}

VirtualFile[] selectedFiles = UIUtil.invokeAndWaitIfNeeded(() -> e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY));

List<VirtualFile> toProcess = MidPointUtils.filterXmlFiles(selectedFiles);

if (toProcess.isEmpty()) {
MidPointUtils.publishNotification(project, actionName, actionName,
"No files matched for " + actionName + " (xml)", NotificationType.WARNING);
return;
}

EnvironmentService em = EnvironmentService.getInstance(e.getProject());
Environment env = em.getSelected();

if (env == null) {
MidPointUtils.publishNotification(project, actionName, actionName,
"No environment selected", NotificationType.ERROR);
return;
}

SynchronizationManager.get(project).synchronize(toProcess, env, direction);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.evolveum.midpoint.studio.action.transfer;

import com.evolveum.midpoint.studio.ui.diff.SynchronizationDirection;
import com.intellij.icons.AllIcons;

public class SynchronizeToMidPointAction extends SynchronizeObjectsAction {

public static final String ACTION_NAME = "Synchronize to MidPoint";

public SynchronizeToMidPointAction() {
super(ACTION_NAME, AllIcons.Actions.Upload, SynchronizationDirection.TO_MIDPOINT);
}
}
Original file line number Diff line number Diff line change
@@ -1,74 +1,13 @@
package com.evolveum.midpoint.studio.action.transfer;

import com.evolveum.midpoint.studio.impl.Environment;
import com.evolveum.midpoint.studio.impl.EnvironmentService;
import com.evolveum.midpoint.studio.ui.diff.SynchronizationManager;
import com.evolveum.midpoint.studio.util.MidPointUtils;
import com.evolveum.midpoint.studio.ui.diff.SynchronizationDirection;
import com.intellij.icons.AllIcons;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class SynchronizeToProjectAction extends AnAction implements DumbAware {
public class SynchronizeToProjectAction extends SynchronizeObjectsAction {

public static final String ACTION_NAME = "Synchronize to project";

public static final String NOTIFICATION_TITLE = ACTION_NAME;

public static final String NOTIFICATION_KEY = ACTION_NAME;

public SynchronizeToProjectAction() {
super(ACTION_NAME, null, AllIcons.Actions.Refresh);
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}

@Override
public void update(@NotNull AnActionEvent evt) {
super.update(evt);

boolean enabled = MidPointUtils.shouldEnableAction(evt);
evt.getPresentation().setEnabled(enabled);
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project == null) {
return;
}

VirtualFile[] selectedFiles = UIUtil.invokeAndWaitIfNeeded(() -> e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY));

List<VirtualFile> toProcess = MidPointUtils.filterXmlFiles(selectedFiles);

if (toProcess.isEmpty()) {
MidPointUtils.publishNotification(project, NOTIFICATION_KEY, NOTIFICATION_TITLE,
"No files matched for " + ACTION_NAME + " (xml)", NotificationType.WARNING);
return;
}

EnvironmentService em = EnvironmentService.getInstance(e.getProject());
Environment env = em.getSelected();

if (env == null) {
MidPointUtils.publishNotification(project, NOTIFICATION_KEY, NOTIFICATION_TITLE,
"No environment selected", NotificationType.ERROR);
return;
}

SynchronizationManager.get(project).synchronize(toProcess, env);
super(ACTION_NAME, AllIcons.Actions.Download, SynchronizationDirection.TO_PROJECT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.evolveum.midpoint.studio.ui.diff;

public enum SynchronizationDirection {

TO_PROJECT,

TO_MIDPOINT
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public void attachToolWindow(@NotNull ToolWindow toolWindow) {
// todo implement
}

public void synchronize(@NotNull List<VirtualFile> files, @NotNull Environment environment) {
public void synchronize(
@NotNull List<VirtualFile> files,
@NotNull Environment environment,
@NotNull SynchronizationDirection direction) {

SynchronizeObjectsTask task = new SynchronizeObjectsTask(project, files);
task.setEnvironment(environment);

Expand Down
9 changes: 8 additions & 1 deletion studio-idea-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,11 @@
<action id="MidPoint.Action.SynchronizeToProject"
class="com.evolveum.midpoint.studio.action.transfer.SynchronizeToProjectAction"
text="Synchronize To Project"
icon="AllIcons.Actions.Refresh"/>
icon="AllIcons.Actions.Download"/>
<action id="MidPoint.Action.SynchronizeToMidPoint"
class="com.evolveum.midpoint.studio.action.transfer.SynchronizeToMidPointAction"
text="Synchronize To Project"
icon="AllIcons.Actions.Upload"/>

<!-- SERVER SIDE -->

Expand Down Expand Up @@ -477,6 +481,7 @@
<reference ref="MidPoint.Action.DiffLocal"/>
<reference ref="MidPoint.Action.DiffRemote"/>
<reference ref="MidPoint.Action.SynchronizeToProject"/>
<reference ref="MidPoint.Action.SynchronizeToMidPoint"/>
<reference ref="MidPoint.Action.CleanupFile"/>
<reference ref="MidPoint.Action.VerifyAction"/>
<reference ref="MidPoint.Action.UpgradeTask"/>
Expand Down Expand Up @@ -543,6 +548,7 @@
<reference ref="MidPoint.Action.Refresh"/>
<reference ref="MidPoint.Action.DiffRemote"/>
<reference ref="MidPoint.Action.SynchronizeToProject"/>
<reference ref="MidPoint.Action.SynchronizeToMidPoint"/>

<separator/>

Expand Down Expand Up @@ -611,6 +617,7 @@
<reference ref="MidPoint.Action.Refresh"/>
<reference ref="MidPoint.Action.DiffRemote"/>
<reference ref="MidPoint.Action.SynchronizeToProject"/>
<reference ref="MidPoint.Action.SynchronizeToMidPoint"/>

<separator/>

Expand Down

0 comments on commit e91e0d2

Please sign in to comment.