Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Apr 23, 2024
1 parent ab15cc2 commit 77caba9
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import java.util.List;

public class SynchronizationFile {
public class SyncFileItem {

private final FileItem item;

private final List<SynchronizationObject> objects;
private final List<SyncObjecItem> objects;

public SynchronizationFile(@NotNull FileItem item, List<SynchronizationObject> objects) {
public SyncFileItem(@NotNull FileItem item, List<SyncObjecItem> objects) {
this.item = item;
this.objects = objects != null ? objects : List.of();
}
Expand All @@ -19,7 +19,7 @@ public FileItem getItem() {
return item;
}

public List<SynchronizationObject> getObjects() {
public List<SyncObjecItem> getObjects() {
return objects;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.evolveum.midpoint.studio.client.MidPointObject;
import org.jetbrains.annotations.NotNull;

public class SynchronizationObject {
public class SyncObjecItem {

private final ObjectItem item;

Expand All @@ -14,7 +14,7 @@ public class SynchronizationObject {

private ModificationType modificationType;

public SynchronizationObject(@NotNull ObjectItem item) {
public SyncObjecItem(@NotNull ObjectItem item) {
this.item = item;

this.localObject = item.local() != null ? item.local().copy() : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SynchronizationManager {

// todo move this to some kind of SynchronizationSession object that will be simpler to manage in
// terms of threading (start/finish, cancel multiple ones)
private final List<SynchronizationFile> items = new ArrayList<>();
private final List<SyncFileItem> items = new ArrayList<>();

private boolean running = false;

Expand All @@ -48,15 +48,15 @@ public void synchronize(@NotNull List<VirtualFile> files, @NotNull Environment e
}

public void add(@NotNull List<FileItem> items) {
List<SynchronizationFile> files = new ArrayList<>();
List<SyncFileItem> files = new ArrayList<>();

for (FileItem fi : items) {
List<SynchronizationObject> objects = new ArrayList<>();
List<SyncObjecItem> objects = new ArrayList<>();
for (ObjectItem oi : fi.objects()) {
objects.add(new SynchronizationObject(oi));
objects.add(new SyncObjecItem(oi));
}

files.add(new SynchronizationFile(fi, objects));
files.add(new SyncFileItem(fi, objects));
}

this.items.addAll(files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ public SynchronizationTreeModel getModel() {
}

private void refreshPerformed() {
Object[] checked = tree.getCheckedNodes(Object.class, null);

// todo implement
}

private void savePerformed() {
Object[] checked = tree.getCheckedNodes(Object.class, null);

// todo implement
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ protected void onDoubleClick(CheckedTreeNode node) {

private void doubleClickPerformed(DefaultMutableTreeNode node) {
Object object = node.getUserObject();
if (object instanceof SynchronizationFile file) {
if (object instanceof SyncFileItem file) {
if (file.getObjects().size() == 1) {
openSynchronizationEditor(file.getObjects().get(0));
}
} else if (object instanceof SynchronizationObject obj) {
} else if (object instanceof SyncObjecItem obj) {
openSynchronizationEditor(obj);
}
}

private void openSynchronizationEditor(SynchronizationObject object) {
private void openSynchronizationEditor(SyncObjecItem object) {
MidPointObject leftObject = object.getItem().local();
MidPointObject rightObject = object.getItem().remote();

Expand All @@ -103,19 +103,7 @@ private void openSynchronizationEditor(SynchronizationObject object) {
protected void acceptPerformed() {
super.acceptPerformed();

try {
PrismObject<? extends ObjectType> result = getLeftObject();
// todo implement, this is bad
PrismObject<? extends ObjectType> leftInitial =
ClientUtils.createParser(
MidPointUtils.DEFAULT_PRISM_CONTEXT, object.getLocalObject().getContent()).parse();

if (!result.equivalent(leftInitial)) {
object.setModificationType(ModificationType.REPLACE);
}
} catch (Exception ex) {
ex.printStackTrace();
}
updateSynchronizationState(this, object);
}
};
processor.initialize();
Expand All @@ -124,6 +112,22 @@ protected void acceptPerformed() {
MidPointUtils.openFile(project, file);
}

private void updateSynchronizationState(DiffProcessor<?> processor, SyncObjecItem object) {
try {
PrismObject<? extends ObjectType> result = processor.getLeftObject();
// todo implement, this is bad
PrismObject<? extends ObjectType> leftInitial =
ClientUtils.createParser(
MidPointUtils.DEFAULT_PRISM_CONTEXT, object.getLocalObject().getContent()).parse();

if (!result.equivalent(leftInitial)) {
object.setModificationType(ModificationType.REPLACE);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}

@Override
public String convertValueToText(
Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Expand Down Expand Up @@ -167,9 +171,9 @@ public void customizeRenderer(

private Color computeColor(Object userObject) {
ModificationType modification = null;
if (userObject instanceof SynchronizationObject object) {
if (userObject instanceof SyncObjecItem object) {
modification = object.getModificationType();
} else if (userObject instanceof SynchronizationFile file) {
} else if (userObject instanceof SyncFileItem file) {
Set<ModificationType> set = file.getObjects().stream()
.map(o -> o.getModificationType())
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Comparator;
import java.util.List;

public class SynchronizationTreeModel extends DefaultTreeModel<List<SynchronizationFile>> {
public class SynchronizationTreeModel extends DefaultTreeModel<List<SyncFileItem>> {

private static final Object NODE_ROOT = "Root";

Expand All @@ -30,7 +30,7 @@ public void valueForPathChanged(TreePath path, Object newValue) {
}

@Override
public void setData(List<SynchronizationFile> data) {
public void setData(List<SyncFileItem> data) {
if (data == null) {
data = new ArrayList<>();
}
Expand All @@ -45,7 +45,7 @@ public void setData(List<SynchronizationFile> data) {
treeStructureChanged(TreePathUtil.toTreePath(root), new int[]{0}, new Object[]{root});
}

public void addData(@NotNull List<SynchronizationFile> data) {
public void addData(@NotNull List<SyncFileItem> data) {
CheckedTreeNode root = (CheckedTreeNode) getRoot();

List<CheckedTreeNode> nodes = addTreeNodes(root, data);
Expand All @@ -60,13 +60,13 @@ public void addData(@NotNull List<SynchronizationFile> data) {
treeStructureChanged(TreePathUtil.toTreePath(root), new int[]{0}, new Object[]{root});
}

private List<CheckedTreeNode> addTreeNodes(CheckedTreeNode root, List<SynchronizationFile> items) {
private List<CheckedTreeNode> addTreeNodes(CheckedTreeNode root, List<SyncFileItem> items) {
List<CheckedTreeNode> nodes = new ArrayList<>();

for (SynchronizationFile item : items) {
for (SyncFileItem item : items) {
getData().add(item);

List<SynchronizationObject> objects = item.getObjects();
List<SyncObjecItem> objects = item.getObjects();
if (objects.isEmpty()) {
continue;
}
Expand All @@ -76,7 +76,7 @@ private List<CheckedTreeNode> addTreeNodes(CheckedTreeNode root, List<Synchroniz
if (objects.size() > 1) {
List<CheckedTreeNode> children = new ArrayList<>();

for (SynchronizationObject object : objects) {
for (SyncObjecItem object : objects) {
children.add(new CheckedTreeNode(object));
}

Expand All @@ -95,9 +95,9 @@ private List<CheckedTreeNode> addTreeNodes(CheckedTreeNode root, List<Synchroniz

public String convertValueToText(Object userObject) {
String value = null;
if (userObject instanceof SynchronizationFile file) {
if (userObject instanceof SyncFileItem file) {
value = file.getItem().local().getName();
} else if (userObject instanceof SynchronizationObject object) {
} else if (userObject instanceof SyncObjecItem object) {
value = object.getItem().name();
}

Expand Down

0 comments on commit 77caba9

Please sign in to comment.