use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.
the class XSDSetAnnotationPrimaryKeyInfoAction method doAction.
public IStatus doAction() {
try {
IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
XSDComponent xSDCom = null;
if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation)
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
}
} else
xSDCom = (XSDComponent) selection.getFirstElement();
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
struc.setXSDSchema(schema);
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDSetAnnotationXX_ExceptionInfo1, xSDCom.getClass().getName()));
}
dlg = new AnnotationOrderedListsDialog(new ArrayList(struc.getPrimaryKeyInfos().values()), new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
dlg.close();
}
}, // $NON-NLS-1$
page.getSite().getShell(), // $NON-NLS-1$
Messages.XSDSetAnnotationXX_DialogTitle, // $NON-NLS-1$
"xPaths", // $NON-NLS-1$
page, AnnotationOrderedListsDialog.AnnotationPrimaKeyInfo_ActionType, null);
dlg.setBlockOnOpen(true);
int ret = dlg.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
struc.setAccessRole(dlg.getXPaths(), false, (IStructuredContentProvider) page.getTreeViewer().getContentProvider(), // $NON-NLS-1$
"X_PrimaryKeyInfo");
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(xSDCom, 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnotationXX_Msg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.
the class XSDSetAnnotationSourceSystemAction method doAction.
public IStatus doAction() {
try {
IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
XSDComponent xSDCom = null;
if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation)
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
}
} else
xSDCom = (XSDComponent) selection.getFirstElement();
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
// XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.ExceptionInfo, xSDCom.getClass().getName()));
}
InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDSetAnnoXX_DialogTitle1, Messages.XSDSetAnnoXX_DialogTip, struc.getSourceSystem(), new IInputValidator() {
public String isValid(String newText) {
return null;
}
});
id.setBlockOnOpen(true);
int ret = id.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
// $NON-NLS-1$
struc.setSourceSystem("".equals(id.getValue()) ? null : id.getValue());
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(xSDCom, 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnoXX_ErrorMsg1, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.jface.viewers.TreePath in project liferay-ide by liferay.
the class PortletResourcesContentProvider method refresh.
public void refresh() {
NavigatorContentService s = (NavigatorContentService) getConfig().getService();
Runnable runnable = new Runnable() {
public void run() {
try {
CommonViewer viewer = (CommonViewer) s.getViewer();
TreePath[] paths = viewer.getExpandedTreePaths();
viewer.refresh(true);
viewer.setExpandedTreePaths(paths);
} catch (Exception e) {
}
}
};
UIUtil.sync(runnable);
}
use of org.eclipse.jface.viewers.TreePath in project jbosstools-hibernate by jbosstools.
the class OpenDiagramActionDelegate method run.
public void run(IAction action) {
ObjectPluginAction objectPluginAction = (ObjectPluginAction) action;
Map<ConsoleConfiguration, Set<IPersistentClass>> mapCC_PCs = new HashMap<ConsoleConfiguration, Set<IPersistentClass>>();
TreePath[] paths = ((TreeSelection) objectPluginAction.getSelection()).getPaths();
for (int i = 0; i < paths.length; i++) {
final Object firstSegment = paths[i].getFirstSegment();
if (!(firstSegment instanceof ConsoleConfiguration)) {
continue;
}
final ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (firstSegment);
Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfig);
if (null == setPC) {
setPC = new HashSet<IPersistentClass>();
mapCC_PCs.put(consoleConfig, setPC);
}
Object last_el = paths[i].getLastSegment();
if (last_el instanceof IPersistentClass) {
IPersistentClass persClass = (IPersistentClass) last_el;
setPC.add(persClass);
} else if (last_el instanceof IConfiguration) {
IConfiguration config = (IConfiguration) last_el;
Iterator<IPersistentClass> it = config.getClassMappings();
while (it.hasNext()) {
setPC.add(it.next());
}
} else if (last_el instanceof ConsoleConfiguration) {
IConfiguration config = consoleConfig.getConfiguration();
if (config == null) {
try {
consoleConfig.build();
} catch (Exception he) {
HibernateConsolePlugin.getDefault().showError(HibernateConsolePlugin.getShell(), DiagramViewerMessages.OpenDiagramActionDelegate_could_not_load_configuration + ' ' + consoleConfig.getName(), he);
}
if (consoleConfig.hasConfiguration()) {
consoleConfig.buildMappings();
}
config = consoleConfig.getConfiguration();
}
if (config != null) {
Iterator<IPersistentClass> it = config.getClassMappings();
while (it.hasNext()) {
setPC.add(it.next());
}
}
}
}
for (Iterator<ConsoleConfiguration> it = mapCC_PCs.keySet().iterator(); it.hasNext(); ) {
ConsoleConfiguration consoleConfiguration = it.next();
Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfiguration);
try {
openEditor(setPC, consoleConfiguration);
} catch (PartInitException e) {
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("Can't open mapping view.", e);
}
}
}
use of org.eclipse.jface.viewers.TreePath in project jbosstools-hibernate by jbosstools.
the class OneParentConfigPropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof ITreeSelection)) {
return false;
}
ITreeSelection selection = (ITreeSelection) receiver;
Set<Object> consoleConfigs = new HashSet<Object>();
for (TreePath path : selection.getPaths()) {
consoleConfigs.add(path.getFirstSegment());
}
return consoleConfigs.size() == 1;
}
Aggregations