/
ArtifactFragment.java
122 lines (113 loc) · 3.95 KB
/
ArtifactFragment.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package org.flowgrid.android;
import org.flowgrid.R;
import org.flowgrid.model.Artifact;
import org.flowgrid.model.Callback;
import org.flowgrid.android.widget.ContextMenu;
import org.flowgrid.android.widget.ContextMenu.Item;
import org.flowgrid.android.widget.ContextMenu.ItemClickListener;
import org.flowgrid.model.CustomOperation;
import org.flowgrid.model.DisplayType;
import org.flowgrid.model.Module;
import android.support.v4.widget.DrawerLayout;
import android.text.SpannableString;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
public abstract class ArtifactFragment<V extends View> extends PlatformFragment<V> implements ItemClickListener{
protected Artifact artifact;
protected ArtifactFragment(Class<V> rootViewClass) {
super(rootViewClass);
}
public void setArtifact(Artifact artifact) {
this.artifact = artifact;
if (artifact.owner() == null) {
setTitle("FlowGrid", null);
setTitleIcon(R.drawable.ic_menu_white_24dp);
} else {
String path = artifact.qualifiedName();
int cut = path.lastIndexOf('/');
if (cut > 0) {
path = path.substring(0, cut + 1);
} else {
path = null;
}
String title = artifact.toString(DisplayType.TITLE);
SpannableString spannable = new SpannableString(title);
int nameStart = title.indexOf('\'') + 1;
if (artifact instanceof CustomOperation && ((CustomOperation) artifact).asyncInput()) {
spannable.setSpan(new UnderlineSpan(), nameStart, title.length() - 1, 0);
}
if (artifact.isPublic() && !(artifact instanceof Module)) {
spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), nameStart, title.length() - 1, 0);
}
setTitle(spannable, path);
}
}
@Override
public ContextMenu.Item addMenuItem(String label) {
ContextMenu.Item item = super.addMenuItem(label);
if (label.equals(MENU_ITEM_PUBLIC)) {
item.setCheckable(true).setChecked(artifact.isPublic());
}
return item;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (super.onOptionsItemSelected(item)) {
return true;
}
if (item.getItemId() == android.R.id.home) {
if (artifact.owner() != null) {
platform.openArtifact(artifact.owner());
return true;
}
DrawerLayout drawer = (DrawerLayout) platform.findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(Gravity.START)) {
drawer.closeDrawers();
} else {
drawer.openDrawer(Gravity.START);
}
return true;
}
return false;
}
public boolean onContextMenuItemClick(Item item) {
String title = item.getTitle().toString();
if (MENU_ITEM_DELETE.equals(title)) {
Dialogs.confirm(platform, "Confirmation", "Delete '" + artifact.qualifiedName() +
"' and all contained content? This cannot be undone.", new Runnable() {
@Override
public void run() {
artifact.rename(null, null, null);
platform.finishFragment(ArtifactFragment.this);
}
});
return true;
}
if (MENU_ITEM_DOCUMENTATION.equals(title) || MENU_ITEM_ADD_DOCUMENTATION.equals(title)) {
HelpDialog.show(platform, artifact == artifact.model().rootModule ? "Flowgrid" : artifact.toString(DisplayType.TITLE), artifact.documentation(), new Callback<String>() {
@Override
public void run(String value) {
if (artifact.setDocumentation(value)) {
artifact.save();
}
}
});
return true;
}
if (MENU_ITEM_PUBLIC.equals(title)) {
artifact.setPublic(!artifact.isPublic());
item.setChecked(artifact.isPublic());
artifact.save();
return true;
}
if (MENU_ITEM_RENAME_MOVE.equals(title) ||
MENU_ITEM_RENAME.equals(title)) {
MoveDialog.show(this, artifact);
return true;
}
return false;
}
}