use of com.twinsoft.convertigo.eclipse.views.mobile.NgxPickerContentProvider.TVObject in project convertigo by convertigo.
the class NgxPickerComposite method initTreeSelection.
private void initTreeSelection(TreeViewer treeViewer, Object object) {
if (treeViewer != null) {
if (object == null) {
TreeItem[] treeItems = treeViewer.getTree().getItems();
if (treeItems.length > 0) {
object = treeItems[0].getData();
}
}
StructuredSelection structuredSelection = null;
if (object != null) {
structuredSelection = new StructuredSelection(object);
}
MobileSmartSource cs = MobileSmartSource.valueOf(currentSource);
if (treeViewer.equals(checkboxTreeViewer)) {
checkboxTreeViewer.expandAll();
if (cs != null) {
checkedList.clear();
fillCheckedList(null, cs.getSources());
if (checkedList.size() > 0) {
structuredSelection = new StructuredSelection(checkedList.get(0));
}
}
if (checkedList.isEmpty() && structuredSelection != null) {
checkedList.add((TVObject) structuredSelection.getFirstElement());
}
checkboxTreeViewer.setSelection(structuredSelection);
updateGrayChecked();
} else if (treeViewer.equals(modelTreeViewer)) {
modelTreeViewer.refresh();
if (cs != null) {
String modelPath = cs.getModelPath();
if (!modelPath.isEmpty()) {
modelTreeViewer.expandAll();
TVObject tvo = findModelItem(null, modelPath.replaceAll("\\?\\.", "."));
if (tvo != null) {
modelTreeViewer.collapseAll();
modelTreeViewer.expandToLevel(tvo, 0);
modelTreeViewer.setSelection(new StructuredSelection(tvo));
} else {
modelTreeViewer.collapseAll();
modelTreeViewer.expandToLevel(1);
}
}
}
}
if (cs != null) {
if (treeViewer.equals(checkboxTreeViewer)) {
checkedList.clear();
fillCheckedList(null, cs.getSources());
updateGrayChecked();
updateTexts(cs);
} else {
if (lastSelected.equals(firstSelected)) {
updateTexts(cs);
} else {
updateTexts();
}
}
} else {
updateTexts();
}
}
}
use of com.twinsoft.convertigo.eclipse.views.mobile.NgxPickerContentProvider.TVObject in project convertigo by convertigo.
the class NgxPickerComposite method updateModel.
private void updateModel(TVObject tvObject) {
Object object = tvObject.getObject();
if (object != null) {
Thread t = new Thread(new Runnable() {
public void run() {
isUpdating = true;
Display.getDefault().asyncExec(new Runnable() {
public void run() {
setWidgetsEnabled(false);
updateMessage("generating model...");
}
});
try {
Map<String, Object> data = lookupModelData(tvObject);
JSONObject jsonModel = getJsonModel(data, null);
Display.getDefault().asyncExec(new Runnable() {
public void run() {
modelTreeViewer.setInput(jsonModel);
initTreeSelection(modelTreeViewer, null);
setWidgetsEnabled(true);
updateMessage();
}
});
} catch (Exception e) {
e.printStackTrace();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
setWidgetsEnabled(true);
updateMessage();
}
});
} finally {
isUpdating = false;
}
}
});
t.start();
} else {
modelTreeViewer.setInput(null);
}
}
use of com.twinsoft.convertigo.eclipse.views.mobile.NgxPickerContentProvider.TVObject in project convertigo by convertigo.
the class NgxPickerComposite method updateGrayChecked.
private void updateGrayChecked() {
checkboxTreeViewer.setCheckedElements(new Object[] {});
checkboxTreeViewer.setGrayedElements(new Object[] {});
for (TVObject tvo : checkedList) {
checkboxTreeViewer.setParentsGrayed(tvo, true);
}
for (Object ob : checkboxTreeViewer.getGrayedElements()) {
checkboxTreeViewer.setChecked(ob, true);
if (ob instanceof TVObject && !((TVObject) ob).getSource().isEmpty()) {
if (btnIteration.getSelection() || btnForm.getSelection() || btnGlobal.getSelection()) {
checkboxTreeViewer.setGrayed(ob, !ob.equals(lastSelected));
} else {
checkboxTreeViewer.setGrayed(ob, false);
}
}
}
}
use of com.twinsoft.convertigo.eclipse.views.mobile.NgxPickerContentProvider.TVObject in project convertigo by convertigo.
the class NgxPickerComposite method fillCheckedList.
private void fillCheckedList(TreeItem parent, List<String> csSourceList) {
if (csSourceList != null && !csSourceList.isEmpty()) {
TreeItem[] items = null;
if (parent == null) {
items = checkboxTreeViewer.getTree().getItems();
} else {
items = parent.getItems();
TVObject tvo = (TVObject) parent.getData();
String tvoSource = tvo.getSource();
if (csSourceList.contains(tvoSource)) {
int index = csSourceList.indexOf(tvoSource);
if (index == 0)
checkedList.add(0, tvo);
else
checkedList.add(tvo);
}
}
for (int i = 0; i < items.length; i++) {
fillCheckedList(items[i], csSourceList);
}
}
}
use of com.twinsoft.convertigo.eclipse.views.mobile.NgxPickerContentProvider.TVObject in project convertigo by convertigo.
the class NgxPickerComposite method findModelItem.
private TVObject findModelItem(TreeItem parent, String modelPath) {
if (modelPath != null && !modelPath.isEmpty()) {
TreeItem[] items = null;
items = parent == null ? modelTreeViewer.getTree().getItems() : parent.getItems();
for (int i = 0; i < items.length; i++) {
TreeItem treeItem = items[i];
TVObject tvo = (TVObject) treeItem.getData();
if (tvo != null) {
String tvoPath = tvo.getPath().replaceAll("\\?\\.", ".");
if (modelPath.startsWith(tvoPath.replaceFirst("root", ""))) {
if (modelPath.equals(tvoPath.replaceFirst("root", ""))) {
return tvo;
}
return findModelItem(items[i], modelPath);
}
}
}
}
return null;
}
Aggregations