Search in sources :

Example 21 with TreePath

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;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) AnnotationOrderedListsDialog(com.amalto.workbench.dialogs.AnnotationOrderedListsDialog) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 22 with TreePath

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;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 23 with TreePath

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);
}
Also used : NavigatorContentService(org.eclipse.ui.internal.navigator.NavigatorContentService) TreePath(org.eclipse.jface.viewers.TreePath) CommonViewer(org.eclipse.ui.navigator.CommonViewer)

Example 24 with TreePath

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);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PartInitException(org.eclipse.ui.PartInitException) ObjectPluginAction(org.eclipse.ui.internal.ObjectPluginAction) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) PartInitException(org.eclipse.ui.PartInitException) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Example 25 with TreePath

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;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) HashSet(java.util.HashSet)

Aggregations

TreePath (org.eclipse.jface.viewers.TreePath)104 TreeSelection (org.eclipse.jface.viewers.TreeSelection)55 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 ArrayList (java.util.ArrayList)20 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)18 XSDComponent (org.eclipse.xsd.XSDComponent)14 Test (org.junit.Test)14 Iterator (java.util.Iterator)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 Element (org.w3c.dom.Element)13 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)12 HashSet (java.util.HashSet)10 Set (java.util.Set)10 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)10 List (java.util.List)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)6 IProject (org.eclipse.core.resources.IProject)5 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)5