Search in sources :

Example 1 with ExporterProperty

use of org.hibernate.eclipse.console.model.impl.ExporterProperty in project jbosstools-hibernate by jbosstools.

the class ExporterTest method setUp.

@Before
public void setUp() throws Exception {
    map = new HashMap<String, ExporterProperty>();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    map.put("ejb3", new ExporterProperty("ejb3", "Use ejb3 syntax", "true", true));
    definition = new // $NON-NLS-1$
    ExporterDefinition(// $NON-NLS-1$
    "exporterClass", // $NON-NLS-1$
    "exporterDescription", // $NON-NLS-1$
    "exporterId", map, null);
    factory = new ExporterFactory(definition, definition.getId());
}
Also used : ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory) ExporterProperty(org.hibernate.eclipse.console.model.impl.ExporterProperty) Before(org.junit.Before)

Example 2 with ExporterProperty

use of org.hibernate.eclipse.console.model.impl.ExporterProperty in project jbosstools-hibernate by jbosstools.

the class AddPropertyDialog method initDefaultNames.

private void initDefaultNames(ExporterFactory ef2, ComboViewer viewer) {
    viewer.setContentProvider(new IStructuredContentProvider() {

        ExporterFactory localEf;

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            localEf = (ExporterFactory) newInput;
        }

        public void dispose() {
            localEf = null;
        }

        public Object[] getElements(Object inputElement) {
            Iterator<Map.Entry<String, ExporterProperty>> set = localEf.getDefaultExporterProperties().entrySet().iterator();
            List<ExporterProperty> values = new ArrayList<ExporterProperty>(4);
            while (set.hasNext()) {
                Map.Entry<String, ExporterProperty> element = set.next();
                // if(!localEf.hasLocalValueFor((String) element.getKey())) {
                ExporterProperty exporterProperty = localEf.getExporterProperty(element.getKey());
                if (exporterProperty != null) {
                    values.add(exporterProperty);
                }
            // }
            }
            return values.toArray(new ExporterProperty[values.size()]);
        }
    });
    viewer.setLabelProvider(new ILabelProvider() {

        public void removeListener(ILabelProviderListener listener) {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void dispose() {
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public String getText(Object element) {
            ExporterProperty exporterProperty = ((ExporterProperty) element);
            return exporterProperty.getDescriptionForLabel();
        }

        public Image getImage(Object element) {
            return null;
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        private SelectionListener getSelectionListener(ExporterProperty prop) {
            // $NON-NLS-1$//$NON-NLS-2$
            if (!("path".equals(prop.getType()) || "directory".equals(prop.getType())))
                return null;
            // $NON-NLS-1$
            final boolean isPath = "path".equals(prop.getType());
            return new SelectionListener() {

                public void widgetDefaultSelected(SelectionEvent e) {
                    widgetSelected(e);
                }

                public void widgetSelected(SelectionEvent e) {
                    String title = isPath ? HibernateConsoleMessages.ExporterSettingsTab_select_path : HibernateConsoleMessages.ExporterSettingsTab_select_dir;
                    String description = isPath ? HibernateConsoleMessages.ExporterSettingsTab_select_path2 : HibernateConsoleMessages.ExporterSettingsTab_select_dir2;
                    MessageDialog dialog = new MessageDialog(getShell(), title, null, description, MessageDialog.QUESTION, new String[] { HibernateConsoleMessages.CodeGenerationSettingsTab_filesystem, HibernateConsoleMessages.CodeGenerationSettingsTab_workspace, IDialogConstants.CANCEL_LABEL }, 1);
                    int answer = dialog.open();
                    String strPath = null;
                    if (answer == 0) {
                        // filesystem
                        DirectoryDialog dialog2 = new DirectoryDialog(getShell());
                        dialog2.setText(title);
                        dialog2.setMessage(description);
                        String dir = dialog2.open();
                        if (dir != null) {
                            strPath = dir;
                        }
                    } else if (answer == 1) {
                        // workspace
                        IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(), (IPath) null, new Path[0], title, description, new String[0], isPath, true, false);
                        if (paths != null && paths.length > 0) {
                            strPath = paths[0].toOSString();
                            if (isPath) {
                                for (int i = 1; i < paths.length; i++) {
                                    strPath += ';' + paths[i].toOSString();
                                }
                            }
                        }
                    } else
                        return;
                    String oldPath = ((Text) value).getText();
                    if (isPath && oldPath.trim().length() > 0 && strPath != null)
                        ((Text) value).setText(oldPath + ';' + strPath);
                    else {
                        if (strPath != null)
                            ((Text) value).setText(strPath);
                    }
                }
            };
        }

        public void selectionChanged(SelectionChangedEvent event) {
            if (value == null)
                return;
            IStructuredSelection iss = (IStructuredSelection) event.getSelection();
            if (!iss.isEmpty()) {
                ExporterProperty prop = (ExporterProperty) iss.getFirstElement();
                if ("boolean".equalsIgnoreCase(prop.getType())) {
                    // $NON-NLS-1$
                    disposeBrowseButton();
                    createComboValueComposite(new String[] { String.valueOf(true), String.valueOf(false) });
                    ((Combo) value).select(Boolean.valueOf(ef.getPropertyValue(prop.getName())).booleanValue() ? 0 : 1);
                } else if (// $NON-NLS-1$
                "directory".equalsIgnoreCase(prop.getType()) || "path".equalsIgnoreCase(prop.getType())) {
                    // $NON-NLS-1$
                    disposeBrowseButton();
                    createTextValueComposite(1);
                    ((Text) value).setText(ef.getPropertyValue(prop.getName()));
                    createBrowseButton(getSelectionListener(prop), prop);
                } else {
                    disposeBrowseButton();
                    createTextValueComposite(2);
                    ((Text) value).setText(ef.getPropertyValue(prop.getName()));
                }
            } else {
                createTextValueComposite(2);
            }
        }
    });
    viewer.setInput(ef);
    if (viewer.getCombo().getItemCount() > 0) {
        Object selected = null;
        if (selectedPropertyId != null) {
            selected = ef.getExporterProperty(selectedPropertyId);
        } else {
            selected = viewer.getElementAt(0);
        }
        viewer.setSelection(new StructuredSelection(selected));
        viewer.getCombo().select(viewer.getCombo().getSelectionIndex());
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) Iterator(java.util.Iterator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) IPath(org.eclipse.core.runtime.IPath) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) ExporterProperty(org.hibernate.eclipse.console.model.impl.ExporterProperty) ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Map(java.util.Map) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with ExporterProperty

use of org.hibernate.eclipse.console.model.impl.ExporterProperty in project jbosstools-hibernate by jbosstools.

the class AddPropertyDialog method getEnteredValues.

void getEnteredValues() {
    if (propertyCombo == null) {
        propertyName = null;
    } else {
        IStructuredSelection selection = (IStructuredSelection) propertyCombo.getSelection();
        if (selection.isEmpty()) {
            propertyName = propertyCombo.getCombo().getText();
        } else {
            ExporterProperty p = (ExporterProperty) selection.getFirstElement();
            propertyName = p.getName();
        }
    }
    if (value != null) {
        if (value instanceof Text) {
            propertyValue = ((Text) value).getText();
        } else if (value instanceof Combo) {
            propertyValue = ((Combo) value).getText();
        }
    } else {
        propertyValue = null;
    }
}
Also used : Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExporterProperty(org.hibernate.eclipse.console.model.impl.ExporterProperty)

Example 4 with ExporterProperty

use of org.hibernate.eclipse.console.model.impl.ExporterProperty in project jbosstools-hibernate by jbosstools.

the class ExporterFactoryPropertySource method getPropertyDescriptors.

public IPropertyDescriptor[] getPropertyDescriptors() {
    List<IPropertyDescriptor> descriptors = new ArrayList<IPropertyDescriptor>();
    Map<String, String> values = factory.getProperties();
    // get the values we explicitly have
    for (String key : values.keySet()) {
        ExporterProperty element = factory.getExporterProperty(key);
        if (element != null) {
            descriptors.add(new TextPropertyDescriptor(element.getName(), element.getDescription() == null ? element.getName() : element.getDescription()));
        } else {
            descriptors.add(new TextPropertyDescriptor(key, key));
        }
    }
    return descriptors.toArray(new IPropertyDescriptor[0]);
}
Also used : ArrayList(java.util.ArrayList) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) ExporterProperty(org.hibernate.eclipse.console.model.impl.ExporterProperty)

Aggregations

ExporterProperty (org.hibernate.eclipse.console.model.impl.ExporterProperty)4 ArrayList (java.util.ArrayList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Text (org.eclipse.swt.widgets.Text)2 ExporterFactory (org.hibernate.eclipse.console.model.impl.ExporterFactory)2 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 IPath (org.eclipse.core.runtime.IPath)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Viewer (org.eclipse.jface.viewers.Viewer)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1