use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.
the class XSDEditFacetAction method doAction.
@Override
public IStatus doAction() {
try {
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
XSDComponent xSDCom = null;
if (selection.getFirstElement() instanceof XSDSimpleTypeDefinition) {
std = (XSDSimpleTypeDefinition) selection.getFirstElement();
} else {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDSimpleTypeDefinition) {
std = (XSDSimpleTypeDefinition) (tPath.getSegment(i));
}
}
}
/**
* totalDigits, fractionDigits, maxInclusive, maxExclusive, minInclusive, minExclusive
*/
if (facetName.equals("pattern")) {
// $NON-NLS-1$
editPattern();
} else if (facetName.equals("enumeration")) {
// $NON-NLS-1$
editEnumeration();
} else if (facetName.equals("length")) {
// $NON-NLS-1$
editLength();
} else if (facetName.equals("minLength")) {
// $NON-NLS-1$
editMinLength();
} else if (facetName.equals("maxLength")) {
// $NON-NLS-1$
editMaxLength();
} else if (facetName.equals("totalDigits")) {
// $NON-NLS-1$
editTotalDigits();
} else if (facetName.equals("fractionDigits")) {
// $NON-NLS-1$
editFractionDigits();
} else if (facetName.equals("maxInclusive")) {
// $NON-NLS-1$
editMaxInclusive();
} else if (facetName.equals("maxExclusive")) {
// $NON-NLS-1$
editMaxExclusive();
} else if (facetName.equals("minInclusive")) {
// $NON-NLS-1$
editMinInclusive();
} else if (facetName.equals("minExclusive")) {
// $NON-NLS-1$
editMinExclusive();
} else if (facetName.equals("whiteSpace")) {
// $NON-NLS-1$
editWhiteSpace();
} else {
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditFacetAction_ErrorMsg1, facetName));
return Status.CANCEL_STATUS;
}
std.updateElement();
page.getTreeViewer().refresh(true);
page.markDirty();
page.refresh();
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditFacetAction_ErrorMsg2, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.jface.viewers.TreePath in project jbosstools-hibernate by jbosstools.
the class HibernateSearchEnabledPropertyTester 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<ConsoleConfiguration> consoleConfigs = new HashSet<ConsoleConfiguration>();
for (TreePath path : selection.getPaths()) {
if (path.getFirstSegment() instanceof ConsoleConfiguration) {
consoleConfigs.add((ConsoleConfiguration) path.getFirstSegment());
} else {
return false;
}
}
for (ConsoleConfiguration consoleConfig : consoleConfigs) {
boolean isHibernateSearch = false;
URL[] classPathURLs = PreferencesClassPathUtils.getCustomClassPathURLs(consoleConfig.getPreferences());
for (URL url : classPathURLs) {
if (url.getFile().contains("hibernate-search")) {
isHibernateSearch = true;
break;
}
}
if (!isHibernateSearch) {
return false;
}
}
return true;
}
use of org.eclipse.jface.viewers.TreePath in project jbosstools-hibernate by jbosstools.
the class HibernateSearchEnabledPropertyTesterTest method allMustContainHibernateSearchLib.
@Test
public void allMustContainHibernateSearchLib() throws MalformedURLException {
ConsoleConfiguration consoleConfiguration1 = mock(ConsoleConfiguration.class);
ConsoleConfiguration consoleConfiguration2 = mock(ConsoleConfiguration.class);
ConsoleConfigurationPreferences prefs1 = mock(ConsoleConfigurationPreferences.class);
ConsoleConfigurationPreferences prefs2 = mock(ConsoleConfigurationPreferences.class);
when(consoleConfiguration1.getPreferences()).thenReturn(prefs1);
when(consoleConfiguration2.getPreferences()).thenReturn(prefs2);
when(prefs1.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "hibernate-search-orm-version") });
when(prefs1.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "something"), new URL("file", "", "dont-we-need") });
TreePath treePath = new TreePath(new Object[] { consoleConfiguration1, consoleConfiguration2 });
ITreeSelection receiver = new TreeSelection(treePath);
HibernateSearchEnabledPropertyTester tester = new HibernateSearchEnabledPropertyTester();
assertFalse(tester.test(receiver, "doesn't matter", null, null));
}
use of org.eclipse.jface.viewers.TreePath in project jbosstools-hibernate by jbosstools.
the class OneParentConfigPropertyTesterTest method testDifferentConfigs.
@Test
public void testDifferentConfigs() {
ConsoleConfiguration consoleConfiguration1 = mock(ConsoleConfiguration.class);
ConsoleConfiguration consoleConfiguration2 = mock(ConsoleConfiguration.class);
TreePath treePath1 = new TreePath(new Object[] { consoleConfiguration1 });
TreePath treePath2 = new TreePath(new Object[] { consoleConfiguration2 });
ITreeSelection receiver = new TreeSelection(new TreePath[] { treePath1, treePath2 });
OneParentConfigPropertyTester propertyTester = new OneParentConfigPropertyTester();
assertFalse(propertyTester.test(receiver, "doesn't matter", null, null));
}
use of org.eclipse.jface.viewers.TreePath in project jbosstools-hibernate by jbosstools.
the class KnownConfigurationsView method makeActions.
/**
*/
private void makeActions() {
this.actionGroup = new ConfigurationsViewActionGroup(this, viewer);
this.doubleAction = new Action() {
public void run() {
// TODO: make action dependent on having a connected console configuration!
ISelection selection = viewer.getSelection();
if (selection == null || selection.isEmpty()) {
return;
}
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
if (firstElement instanceof ConsoleConfiguration) {
new EditConsoleConfiguration((ConsoleConfiguration) firstElement).run();
} else if (firstElement instanceof BaseNode) {
BaseNode node = (BaseNode) firstElement;
ConsoleConfiguration consoleConfiguration = node.getConsoleConfiguration();
if (consoleConfiguration.isSessionFactoryCreated()) {
String hql = node.getHQL();
// open HQL Editor
HibernateConsolePlugin.getDefault().openScratchHQLEditor(consoleConfiguration.getName(), hql);
/**
* /
* // execute query and show results in
* // Hibernate Query result view - commented cause old version
* if(StringHelper.isNotEmpty( hql )) {
* try {
* if (getSite() != null && getSite().getPage() != null) {
* getSite().getPage().showView(QueryPageTabView.ID);
* }
* } catch (PartInitException e) {
* HibernateConsolePlugin.getDefault().logErrorMessage("Can't show QueryPageTabView.", e); //$NON-NLS-1$
* }
* consoleConfiguration.executeHQLQuery( hql );
* }
* /*
*/
}
} else if (selection instanceof TreeSelection) {
TreePath[] paths = ((TreeSelection) selection).getPaths();
TreePath path = paths[0];
Object last = path.getLastSegment();
ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (path.getSegment(0));
if (last instanceof IPersistentClass || (last instanceof IProperty && ((IProperty) last).classIsPropertyClass())) {
try {
OpenMappingAction.run(consoleConfig, path);
} catch (PartInitException e) {
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping file.", e);
} catch (JavaModelException e) {
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping file.", e);
} catch (FileNotFoundException e) {
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping file.", e);
}
} else {
for (int i = 0; i < paths.length; i++) {
if (viewer.getExpandedState(paths[i])) {
viewer.collapseToLevel(paths[i], 1);
} else {
viewer.expandToLevel(paths[i], 1);
}
}
}
}
}
};
}
Aggregations