use of com.twinsoft.convertigo.eclipse.views.mobile.MobilePickerContentProvider.TVObject in project convertigo by convertigo.
the class MobilePickerComposite 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.MobilePickerContentProvider.TVObject in project convertigo by convertigo.
the class MobilePickerComposite method getModelData.
// private List<String> getSourceList() {
// TVObject tvoSelected = null;
// Object selected = checkboxTreeViewer.getStructuredSelection().getFirstElement();
// if (selected != null && selected instanceof TVObject) {
// tvoSelected = (TVObject)selected;
// }
//
// List<String> sourceList = new ArrayList<String>();
// List<TVObject> tvoList = GenericUtils.cast(Arrays.asList(checkboxTreeViewer.getCheckedElements()));
// for (TVObject tvo : tvoList) {
// if (tvo.equals(tvoSelected)) {
// sourceList.add(0, tvo.getSource());
// }
// else {
// sourceList.add(tvo.getSource());
// }
// }
// return sourceList;
// }
private List<SourceData> getModelData() {
TVObject tvoSelected = null;
Object selected = checkboxTreeViewer.getStructuredSelection().getFirstElement();
if (selected != null && selected instanceof TVObject) {
tvoSelected = (TVObject) selected;
}
List<SourceData> sourceList = new ArrayList<SourceData>();
List<TVObject> tvoList = GenericUtils.cast(Arrays.asList(checkboxTreeViewer.getCheckedElements()));
for (TVObject tvo : tvoList) {
SourceData sd = tvo.getSourceData();
if (sd != null) {
if (tvo.equals(tvoSelected)) {
sourceList.add(0, sd);
} else {
sourceList.add(sd);
}
}
}
return sourceList;
}
use of com.twinsoft.convertigo.eclipse.views.mobile.MobilePickerContentProvider.TVObject in project convertigo by convertigo.
the class MobilePickerComposite 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.MobilePickerContentProvider.TVObject in project convertigo by convertigo.
the class MobilePickerComposite 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.MobilePickerContentProvider.TVObject in project convertigo by convertigo.
the class MobilePickerComposite 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();
}
}
}
Aggregations