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());
}
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());
}
}
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;
}
}
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]);
}
Aggregations