/** * Returns the new name to be given to the target resource. * * @param resource the resource to query status on * @return the new name */ protected String queryNewResourceName(final File resource) { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IPath prefix = new Path(resource.getAbsolutePath()).removeLastSegments(1); IInputValidator validator = new IInputValidator() { /* * (non-Javadoc) * * @see * org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String * ) */ public String isValid(String string) { if (new Path(resource.getName()) .removeFileExtension() .toFile() .getName() .equals(string)) { return Messages.getString("RenameResourceAction.nameExists"); // $NON-NLS-1$ } IPath newPath = new Path(string); IStatus status = workspace.validateName( newPath.toFile().getName(), resource.isFile() ? IResource.FILE : IResource.FOLDER); if (!status.isOK()) { return status.getMessage(); } IPath fullPath = prefix.append(string); if (fullPath.toFile().exists()) { return Messages.getString("RenameResourceAction.nameExists"); // $NON-NLS-1$ } return null; } }; InputDialog dialog = new InputDialog( getShell(), Messages.getString("RenameResourceAction.inputDialogTitle"), // $NON-NLS-1$ Messages.getString("RenameResourceAction.inputDialogMessage"), // $NON-NLS-1$ new Path(resource.getName()).toFile().getName(), validator); dialog.setBlockOnOpen(true); int result = dialog.open(); if (result == Window.OK) { IPath newPath = new Path(dialog.getValue()); return newPath.toFile().getName(); } return null; }
/** * Creates a new data set wizard page * * @param useTransaction the style of page */ public DataSetBasePage(boolean useTransaction) { super("DataSet Base Page"); // $NON-NLS-1$ setTitle(Messages.getString("dataset.new")); // $NON-NLS-1$ this.setMessage(Messages.getString("AbstractDataSetWizard.ModelTrans.Create")); // $NON-NLS-1$ this.useTransaction = useTransaction; setImage(); }
private void createInfomation(Composite parent) { Font font = parent.getFont(); Composite continer = createComposite(parent, font, 2, 2, GridData.FILL_BOTH, 0, 0); continer.setBackground(fBackgroundColor); IReportDocument document = null; try { document = engine.openReportDocument(getFileName()); createScriptgLabel(continer, Messages.getString("ReportDocumentEditor.3")); // $NON-NLS-1$ createScriptgLabel(continer, document.getName()); createScriptgLabel(continer, Messages.getString("ReportDocumentEditor.4")); // $NON-NLS-1$ createScriptgLabel(continer, document.getVersion()); createScriptgLabel(continer, Messages.getString("ReportDocumentEditor.5")); // $NON-NLS-1$ createScriptgLabel(continer, "" + document.getPageCount()); // $NON-NLS-1$ } catch (EngineException e) { this.e = e; createErrorControl(continer); } finally { if (document != null) { document.close(); } } }
@Override public void createPartControl(Composite parent) { if (engine == null) { init(); } Display display = parent.getDisplay(); fBackgroundColor = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND); fForegroundColor = display.getSystemColor(SWT.COLOR_LIST_FOREGROUND); fSeparatorColor = ColorManager.getColor(152, 170, 203); fComposite = createComposite(parent); fComposite.setLayout(new GridLayout()); createTitleLabel(fComposite, Messages.getString("ReportDocumentEditor.1")); // $NON-NLS-1$ createLabel(fComposite, null); createLabel(fComposite, null); createHeadingLabel(fComposite, Messages.getString("ReportDocumentEditor.2")); // $NON-NLS-1$ Composite separator = createCompositeSeparator(fComposite); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = 2; separator.setLayoutData(data); createInfomation(fComposite); }
/* * (non-Javadoc) * * @see * org.eclipse.birt.report.designer.internal.ui.views.DefaultNodeProvider * #createElement(java.lang.String) */ protected DesignElementHandle createElement(String type) throws Exception { DesignElementHandle handle = super.createElement(type); BaseTitleAreaDialog dialog = null; if (ReportDesignConstants.PARAMETER_GROUP_ELEMENT.equals(type)) { dialog = new ParameterGroupDialog( Display.getCurrent().getActiveShell(), Messages.getString("ParametersNodeProvider.dialogue.title.group")); // $NON-NLS-1$ ((ParameterGroupDialog) dialog).setInput(handle); } else if (ReportDesignConstants.SCALAR_PARAMETER_ELEMENT.equals(type)) { dialog = new ParameterDialog( PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.getString("ParametersNodeProvider.dialogue.title.parameter")); // $NON-NLS-1$ // required default value ((ParameterDialog) dialog).setInput(handle); } if (dialog == null) return null; if (dialog.open() == Dialog.CANCEL) { return null; } return (DesignElementHandle) dialog.getResult(); }
/* * (non-Javadoc) * * @see * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets * .Composite) */ protected Control createDialogArea(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); tableViewer = new TableViewer(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); GridData data = new GridData(GridData.FILL_BOTH); data.heightHint = 250; data.widthHint = 300; table = tableViewer.getTable(); table.setLayoutData(data); table.setHeaderVisible(true); final TableColumn column = new TableColumn(table, SWT.NONE); column.setText(Messages.getString("SelectValueDialog.selectValue")); // $NON-NLS-1$ column.setWidth(data.widthHint); TableItem item = new TableItem(table, SWT.NONE); item.setText(0, Messages.getString("SelectValueDialog.retrieving")); // $NON-NLS-1$ column.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { sortDir = sortDir == SWT.UP ? SWT.DOWN : SWT.UP; table.setSortDirection(sortDir); tableViewer.setSorter(new TableSorter(sortDir)); } }); table.addMouseListener( new MouseAdapter() { public void mouseDoubleClick(MouseEvent e) { if (table.getSelectionCount() > 0) { okPressed(); } } }); PlatformUI.getWorkbench() .getDisplay() .asyncExec( new Runnable() { public void run() { populateList(); } }); UIUtil.bindHelp(parent, IHelpContextIds.SELECT_PARAMETER_DEFAULT_VALUE_DIALOG_ID); return composite; }
private void createDispalyRowLimitGroup(Composite cmpTop) { Group dispalyRowLimitGroup = new Group(cmpTop, SWT.NONE); dispalyRowLimitGroup.setText( Messages.getString( "designer.preview.preference.resultset.groupTitle.DispalyRowLimitsSetting")); GridLayout layout = new GridLayout(); layout.makeColumnsEqualWidth = true; layout.marginWidth = layout.marginHeight = 6; dispalyRowLimitGroup.setLayout(layout); GridData groupData = new GridData(GridData.FILL_HORIZONTAL); groupData.horizontalSpan = 2; dispalyRowLimitGroup.setLayoutData(groupData); Composite container = new Composite(dispalyRowLimitGroup, SWT.NONE); container.setLayoutData(new GridData(GridData.FILL_BOTH)); noLimitBtn = new Button(container, SWT.CHECK); GridData noLimitBtnData = new GridData(GridData.FILL_HORIZONTAL); noLimitBtnData.horizontalSpan = 2; noLimitBtn.setText( Messages.getString("designer.preview.preference.resultset.NoLimitOfDispalyRow")); noLimitBtn.setLayoutData(noLimitBtnData); noLimitBtn.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { txtMaxDataSetRow.setEnabled(!noLimitBtn.getSelection(), noLimitBtn.getParent()); if (!noLimitBtn.getSelection()) { txtMaxDataSetRow.setFocus(); } if (txtMaxDataSetRow.checkState()) {} } }); txtMaxDataSetRow = new DisplayNumberFieldEditor( PREVIEW_MAXROW, Messages.getString( "designer.preview.preference.resultset.maxrow.description"), //$NON-NLS-1$ container); txtMaxDataSetRow.setPage(this); txtMaxDataSetRow.setValidRange(1, Integer.MAX_VALUE); txtMaxDataSetRow.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE); txtMaxDataSetRow.setEmptyStringAllowed(false); txtMaxDataSetRow.setPropertyChangeListener( new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(FieldEditor.IS_VALID)) setValid(txtMaxDataSetRow.isValid()); } }); }
/** Global redo action for views */ public class GlobalRedoAction extends GlobalStackAction { private static String REDO_LABEL = Messages.getString("label.redo"); // $NON-NLS-1$ protected GlobalRedoAction(CommandStack stack) { super(GlobalActionFactory.REDO, stack); } public void run() { stack.redo(); } /* * (non-Javadoc) * * @see org.eclipse.birt.report.designer.internal.ui.views.actions.GlobalStackAction#calculateEnabled() */ protected boolean calculateEnabled() { return stack.canRedo(); } /* * (non-Javadoc) * * @see org.eclipse.birt.report.designer.internal.ui.views.actions.GlobalStackAction#getDisplayLabel() */ protected String getDisplayLabel() { String displayLabel = REDO_LABEL; if (!StringUtil.isBlank(stack.getRedoLabel())) { displayLabel += " " + stack.getRedoLabel(); // $NON-NLS-1$ } return displayLabel; } }
/** * Create the data set type viewer * * @param composite */ private void createDataSetTypeViewer(Composite composite) { // create the data set type chooser combo new Label(composite, SWT.RIGHT) .setText(Messages.getString("dataset.wizard.label.datasetType")); // $NON-NLS-1$ dataSetTypeChooser = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY); dataSetTypeChooser.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); DataSetTypesProvider dataSetTypes = new DataSetTypesProvider(); dataSetTypeChooser.setContentProvider(dataSetTypes); dataSetTypeChooser.setLabelProvider(dataSetTypes); dataSetTypeChooser.getCombo().setEnabled(false); }
private boolean saveFile(String filePath, LinkedProperties properties, String fileName) { File f = new File(filePath); if (!(f.exists() && f.isFile())) { MessageDialog.openError( getShell(), Messages.getString("ResourceEditDialog.NotFile.Title"), // $NON-NLS-1$ Messages.getFormattedString( "ResourceEditDialog.NotFile.Message", //$NON-NLS-1$ new Object[] {propFileName})); return false; } else if (!f.canWrite()) { MessageDialog.openError( getShell(), Messages.getString("ResourceEditDialog.ReadOnlyEncounter.Title"), // $NON-NLS-1$ Messages.getFormattedString( "ResourceEditDialog.ReadOnlyEncounter.Message", //$NON-NLS-1$ new Object[] {propFileName})); return false; } FileOutputStream fos = null; try { if (f.canWrite()) { fos = new FileOutputStream(f); properties.store(fos, ""); // $NON-NLS-1$ } return true; } catch (Exception e) { ExceptionHandler.handle(e); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { ExceptionHandler.handle(e); } } } return false; }
protected void addSelection() { String key = keyText.getText(); String val = valueText.getText(); if (key != null && key.trim().length() > 0) { boolean isContained = false; for (int i = 0; i < globalLinkedProperties.size(); i++) { GlobalProperty property = (GlobalProperty) globalLinkedProperties.get(i); if (key.equals(property.key) && !property.isDeleted) { property.value = val; isContained = true; break; } } if (!isContained) { // if the file is read-only then change is not allowed. if (propFileName[0] == null) { return; } else { File f = new File(propFileName[0]); if (!(f.exists() && f.isFile())) { MessageDialog.openError( getShell(), Messages.getString("ResourceEditDialog.NotFile.Title"), // $NON-NLS-1$ Messages.getFormattedString( "ResourceEditDialog.NotFile.Message", //$NON-NLS-1$ new Object[] {propFileName})); return; } else if (!f.canWrite()) { MessageDialog.openError( getShell(), Messages.getString("ResourceEditDialog.ReadOnlyEncounter.Title"), // $NON-NLS-1$ Messages.getFormattedString( "ResourceEditDialog.ReadOnlyEncounter.Message", //$NON-NLS-1$ new Object[] {propFileName})); return; } GlobalProperty property = new GlobalProperty(); property.key = key; property.value = val; property.holder = contents[0]; property.isDeleted = false; property.holderFile = propFileName[0]; globalLinkedProperties.add(property); } } viewer.refresh(); listChanged = true; updateSelection(); } else { MessageDialog.openWarning( getShell(), Messages.getString("ResourceEditDialog.text.AddWarningTitle"), // $NON-NLS-1$ Messages.getString("ResourceEditDialog.text.AddWarningMsg")); // $NON-NLS-1$ } }
private void deleteSelection() { if (viewer.getTable().getSelectionIndex() == -1) { return; } StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (selection.getFirstElement() instanceof GlobalProperty) { GlobalProperty property = (GlobalProperty) selection.getFirstElement(); String file = property.holderFile; if (file != null) { File f = new File(file); if (!(f.exists() && f.isFile())) { MessageDialog.openError( getShell(), Messages.getString("ResourceEditDialog.NotFile.Title"), // $NON-NLS-1$ Messages.getFormattedString( "ResourceEditDialog.NotFile.Message", //$NON-NLS-1$ new Object[] {file})); return; } else if (!f.canWrite()) { MessageDialog.openError( getShell(), Messages.getString("ResourceEditDialog.ReadOnlyEncounter.Title"), // $NON-NLS-1$ Messages.getFormattedString( "ResourceEditDialog.ReadOnlyEncounter.Message", //$NON-NLS-1$ new Object[] {file})); return; } } // if the file is read-only then change is not allowed. listChanged = true; if (property.holderFile != null) property.isDeleted = true; else globalLinkedProperties.remove(property); viewer.refresh(); updateSelection(); } }
/** populate all available value in selectValueList */ private void populateList() { try { if (this.getShell() == null || this.getShell().isDisposed()) return; if (this.getOkButton() != null && !this.getOkButton().isDisposed()) getOkButton().setEnabled(false); table.removeAll(); table.deselectAll(); tableViewer.setContentProvider(new ContentProvider()); tableViewer.setLabelProvider(new TableLabelProvider()); if (columnValueList != null) { tableViewer.setInput(columnValueList); } else { ExceptionHandler.openErrorMessageBox( Messages.getString("SelectValueDialog.errorRetrievinglist"), Messages.getString("SelectValueDialog.noExpressionSet")); // $NON-NLS-1$ //$NON-NLS-2$ } if (table.getItemCount() > 0) { table.select(0); getOkButton().setEnabled(true); } for (int i = 0; i < table.getItemCount(); i++) { table.getItem(i).setData(columnValueList.get(i)); } table.setSortColumn(table.getColumn(0)); table.setSortDirection(sortDir); tableViewer.setSorter(new TableSorter(sortDir)); table.setSelection(0); } catch (Exception e) { ExceptionHandler.handle(e); } }
@Override protected boolean doAction() throws Exception { isDone = false; ReportDesignHandle designHandle = (ReportDesignHandle) SessionHandleAdapter.getInstance().getReportDesignHandle(); VariableElementHandle variable = (VariableElementHandle) ElementProcessorFactory.createProcessor(ReportDesignConstants.VARIABLE_ELEMENT) .createElement(null); VariableDialog dialog = new VariableDialog( Messages.getString("VariablesNodeProvider.Dialog.Title"), // $NON-NLS-1$ designHandle, variable); if (dialog.open() == Dialog.OK) designHandle.getPropertyHandle(IReportDesignModel.PAGE_VARIABLES_PROP).add(variable); isDone = true; createElement = variable; return true; }
private Composite buildUIForSpecific(Composite parent) { Composite container = new Composite(parent, SWT.NONE); container.setLayoutData(new GridData(GridData.FILL_BOTH)); GridLayout layout = new GridLayout(3, false); container.setLayout(layout); ReportEngine engine = new ReportEngine(new EngineConfig()); String[] typeInfo = engine.getSupportedFormats(); specCheckButtons = new HashMap(); specExpressions = new HashMap(); for (int i = 0; i < typeInfo.length; i++) { Button btn = FormWidgetFactory.getInstance().createButton(container, SWT.CHECK, isFormStyle()); btn.setText(typeInfo[i]); btn.setSelection(false); Label label = FormWidgetFactory.getInstance().createLabel(container, isFormStyle()); label.setText(Messages.getString("VisibilityPage.Label.Expression")); // $NON-NLS-1$ ExpressionComposite expression = new ExpressionComposite(container, isFormStyle()); GridData data = new GridData(); data.grabExcessHorizontalSpace = true; data.horizontalAlignment = GridData.FILL; expression.setLayoutData(data); specCheckButtons.put(typeInfo[i], btn); specExpressions.put(typeInfo[i], expression); btn.addSelectionListener(listener); expression.addListener( SWT.Modify, new Listener() { public void handleEvent(Event event) { saveHideInfo(); } }); } return container; }
private Composite buildUIForAlloutput(Composite parent) { Composite container = new Composite(parent, SWT.NONE); container.setLayoutData(new GridData(GridData.FILL_BOTH)); GridLayout layout = new GridLayout(2, false); container.setLayout(layout); Label label = FormWidgetFactory.getInstance().createLabel(container, isFormStyle()); label.setText(Messages.getString("VisibilityPage.Label.Expression")); // $NON-NLS-1$ allExpression = new ExpressionComposite(container, isFormStyle()); allExpression.addListener( SWT.Modify, new Listener() { public void handleEvent(Event event) { saveHideInfo(); } }); GridData data = new GridData(); data.grabExcessHorizontalSpace = true; data.horizontalAlignment = GridData.FILL; allExpression.setLayoutData(data); return container; }
/** Base information page for dataset wizards */ public class DataSetBasePage extends WizardPage { private transient Text nameEditor = null; private transient ComboViewer dataSetTypeChooser = null; private transient boolean useTransaction = true; private static final String EMPTY_NAME = Messages.getString("error.DataSet.emptyName"); // $NON-NLS-1$ private static final String DUPLICATE_NAME = Messages.getString("error.duplicateName"); // $NON-NLS-1$ private static final String CREATE_PROMPT = Messages.getString("dataset.message.create"); // $NON-NLS-1$ private transient DataSourceHandle newDataSource = null; private Hashtable htDataSetWizards = new Hashtable(10); // store latest selection data source private ISelection dateSetTypeSelection = null; private transient DataSetDesignSession m_designSession = null; private boolean useODAV3 = false; private WizardFilter wizardFilter = null; private FilteredTree dataSourceFilteredTree; private DataSetBasePageHelper helper; private IWizardPage nextPage; private static final String SCRIPT_DATASET_NAME = Messages.getString("DataSetBasePage.ScriptedDataSet.name"); // $NON-NLS-1$ private static final String SCRIPT_DATASOURCE_NAME = Messages.getString("DataSetBasePage.ScriptedDataSource.name"); // $NON-NLS-1$ private static final String CASSANDRA_DATASET_NAME = Messages.getString("DataSetBasePage.CassandraScriptedDataSet.name"); // $NON-NLS-1$ private static final String CASSANDRA_DATASOURCE_NAME = Messages.getString("DataSetBasePage.CassandraScriptedDataSource.name"); // $NON-NLS-1$ /** * Creates a new data set wizard page * * @param useTransaction the style of page */ public DataSetBasePage(boolean useTransaction) { super("DataSet Base Page"); // $NON-NLS-1$ setTitle(Messages.getString("dataset.new")); // $NON-NLS-1$ this.setMessage(Messages.getString("AbstractDataSetWizard.ModelTrans.Create")); // $NON-NLS-1$ this.useTransaction = useTransaction; setImage(); } /** Sets the Image for the page */ private void setImage() { URL url = null; try { url = new URL( ReportPlugin.getDefault().getBundle().getEntry("/"), // $NON-NLS-1$ "icons/wizban/dataset_wizard.gif"); //$NON-NLS-1$ } catch (MalformedURLException e) { ExceptionHandler.handle(e); } ImageDescriptor desc = ImageDescriptor.createFromURL(url); this.setImageDescriptor(desc); } /** * Creates the top level control for this dialog page under the given parent composite. * * <p>Implementors are responsible for ensuring that the created control can be accessed via * <code>getControl</code> * * @param parent the parent composite */ public void createControl(Composite parent) { helper = new DataSetBasePageHelper(); // initialize the dialog layout Composite composite = new Composite(parent, SWT.NULL); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout layout = new GridLayout(); composite.setLayout(layout); final Group group = new Group(composite, SWT.NONE); group.setLayout(new GridLayout()); group.setText(Messages.getString("DataSetBasePage.Group.DataSourceSelection")); // $NON-NLS-1$ group.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, true, 1, 8)); // GridData.FILL_BOTH)); wizardFilter = new WizardFilter(); dataSourceFilteredTree = new FilteredTree( group, SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL, this.wizardFilter, true); GridData treeData = new GridData(GridData.FILL_BOTH); treeData.grabExcessHorizontalSpace = true; treeData.grabExcessVerticalSpace = true; treeData.heightHint = 300; treeData.widthHint = 600; dataSourceFilteredTree.setLayoutData(treeData); SelectionListener listener = new SelectionListener() { TreeItem parent = null; public void widgetDefaultSelected(SelectionEvent arg0) {} public void widgetSelected(SelectionEvent event) { if (event.item.getData() instanceof DataSourceHandle) { dataSetTypeChooser.getCombo().setEnabled(true); if (parent == null || parent != ((TreeItem) event.item).getParentItem()) { parent = ((TreeItem) event.item).getParentItem(); doDataSourceSelectionChanged(parent.getData()); } setPageComplete(!hasWizard() && (getMessageType() != ERROR)); } else { dataSetTypeChooser.getCombo().clearSelection(); dataSetTypeChooser.getCombo().setEnabled(false); setPageComplete(false); } dataSourceFilteredTree.getViewer().getTree().setFocus(); } }; dataSourceFilteredTree.getViewer().getTree().addSelectionListener(listener); createDataSetTypeViewer(composite); setDataSourceTreeViewer(); setPageStatus(); // initialize name editor new Label(composite, SWT.RIGHT) .setText(Messages.getString("dataset.wizard.label.datasetName")); // $NON-NLS-1$ nameEditor = new Text(composite, SWT.BORDER); String name = ReportPlugin.getDefault().getCustomName(ReportDesignConstants.DATA_SET_ELEMENT); if (name != null) { nameEditor.setText(Utility.getUniqueDataSetName(name)); } else // can't get defaut name { nameEditor.setText( Utility.getUniqueDataSetName( Messages.getString("dataset.new.defaultName"))); // $NON-NLS-1$ } nameEditor.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); nameEditor.setToolTipText(Messages.getString("DataSetBasePage.tooltip")); // $NON-NLS-1$ nameEditor.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { if (StringUtil.isBlank(nameEditor.getText().trim())) { setMessage(EMPTY_NAME, ERROR); } else if (isDuplicateName()) { // name is duplicated setMessage(DUPLICATE_NAME, ERROR); } else if (containInvalidCharactor( nameEditor.getText())) { // name contains invalid ".", "/", "\", "!", ";", "," // character String msg = Messages.getFormattedString( "error.invalidName", //$NON-NLS-1$ new Object[] {nameEditor.getText()}); setMessage(msg, ERROR); } else { // everything is OK setMessage(CREATE_PROMPT); } setPageComplete( !hasWizard() && (getMessageType() != ERROR) && getSelectedDataSource() != null); nameEditor.setFocus(); } }); setControl(composite); Utility.setSystemHelp(getControl(), IHelpConstants.CONEXT_ID_DATASET_NEW); } private void setDataSourceTreeViewer() { dataSourceFilteredTree .getViewer() .setContentProvider( new ITreeContentProvider() { DataSourceType[] types = null; public void dispose() {} public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} public Object[] getElements(Object inputElement) { types = new DataSourceType[((Collection) inputElement).size()]; Iterator iter = ((Collection) inputElement).iterator(); int i = 0; while (iter.hasNext()) { types[i] = (DataSourceType) iter.next(); i++; } return types; } public Object[] getChildren(Object parentElement) { if (parentElement instanceof DataSourceType) { return ((DataSourceType) parentElement).getDataSourceList().toArray(); } else { return new Object[0]; } } public Object getParent(Object element) { if (types != null) { for (int i = 0; i < types.length; i++) { if (types[i].getDataSourceList().contains(element)) return types[i]; } } return null; } public boolean hasChildren(Object element) { if (element instanceof DataSourceType) { return true; } else if (element instanceof DataSourceHandle) { return false; } return false; } }); dataSourceFilteredTree .getViewer() .setLabelProvider( new ILabelProvider() { public Image getImage(Object element) { return null; } public String getText(Object element) { if (element instanceof DataSourceType) { return ((DataSourceType) element).getDataSourceDisplayName(); } else if (element instanceof DataSourceHandle) { return ((DataSourceHandle) element).getName(); } return element.toString(); } public void addListener(ILabelProviderListener listener) {} public void dispose() {} public boolean isLabelProperty(Object element, String property) { return false; } public void removeListener(ILabelProviderListener listener) {} }); dataSourceFilteredTree .getViewer() .addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { setPageStatus(); } }); dataSourceFilteredTree .getViewer() .setComparator( new ViewerComparator( new Comparator() { public int compare(Object o1, Object o2) { return o1.toString().compareTo(o2.toString()); } })); Map sourceMap = getDataSourceMap(); dataSourceFilteredTree.getViewer().setInput(sourceMap.values()); dataSourceFilteredTree.getViewer().expandAll(); if (dataSourceFilteredTree.getViewer().getTree().getItems().length > 0) { dataSourceFilteredTree .getViewer() .getTree() .select(dataSourceFilteredTree.getViewer().getTree().getItem(0).getItem(0)); doDataSourceSelectionChanged( dataSourceFilteredTree.getViewer().getTree().getItem(0).getData()); dataSetTypeChooser.getCombo().setEnabled(true); } setPageComplete(!hasWizard() && (getMessageType() != ERROR)); } private void setPageStatus() { if (dataSourceFilteredTree == null || dataSourceFilteredTree.getViewer().getTree().getSelectionCount() <= 0) setPageComplete(false); } private Map getDataSourceMap() { List dataSources = Utility.getDataSources(); Map sourceTypeMap = new HashMap(); for (int i = 0; i < dataSources.size(); i++) { DataSourceHandle handle = (DataSourceHandle) dataSources.get(i); if (handle instanceof OdaDataSourceHandle) { String type = ((OdaDataSourceHandle) handle).getExtensionID(); if (!sourceTypeMap.containsKey(type)) { try { // Find the data source ExtensionManifest extMF = ManifestExplorer.getInstance().getExtensionManifest(type); if (extMF != null) { // Find the data sets for this data source. DataSetType[] dataSetTypes = extMF.getDataSetTypes(); OdaDataSetTypeElement[] element = new OdaDataSetTypeElement[dataSetTypes.length]; for (int n = 0; n < dataSetTypes.length; n++) { if (!dataSetTypes[n].isDeprecated()) { element[n] = new OdaDataSetTypeElement( dataSetTypes[n], DataSetProvider.findDataSetElement(dataSetTypes[n].getID(), type)); } } DataSourceType dataSourceType = new DataSourceType(type, extMF.getDataSourceDisplayName(), element); sourceTypeMap.put(type, dataSourceType); dataSourceType.addDataSource(handle); } } catch (Exception ex) { ExceptionHandler.handle(ex); } } else { DataSourceType sourceType = (DataSourceType) sourceTypeMap.get(type); sourceType.addDataSource(handle); } } else if (handle instanceof ScriptDataSourceHandle) { useODAV3 = false; getScriptDataSourceMap( handle, sourceTypeMap, getScriptDataSetName(handle), getScriptDataSourceName(handle)); } else { useODAV3 = false; helper.addExternalDataSource(sourceTypeMap, handle); } } return sourceTypeMap; } private void getScriptDataSourceMap( DataSourceHandle handle, Map sourceTypeMap, String DataSetName, String DataSourceName) { if (!sourceTypeMap.containsKey(DataSourceName)) { DataSetTypeElement[] element = new DataSetTypeElement[1]; element[0] = new DataSetTypeElement(DataSetName); DataSourceType dataSourceType = new DataSourceType(DataSourceName, DataSourceName, element); sourceTypeMap.put(DataSourceName, dataSourceType); dataSourceType.addDataSource(handle); } else { DataSourceType sourceType = (DataSourceType) sourceTypeMap.get(DataSourceName); sourceType.addDataSource(handle); } } /** * Create the data set type viewer * * @param composite */ private void createDataSetTypeViewer(Composite composite) { // create the data set type chooser combo new Label(composite, SWT.RIGHT) .setText(Messages.getString("dataset.wizard.label.datasetType")); // $NON-NLS-1$ dataSetTypeChooser = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY); dataSetTypeChooser.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); DataSetTypesProvider dataSetTypes = new DataSetTypesProvider(); dataSetTypeChooser.setContentProvider(dataSetTypes); dataSetTypeChooser.setLabelProvider(dataSetTypes); dataSetTypeChooser.getCombo().setEnabled(false); } /** * checks if the name is duplicate * * @return Returns true if the name is duplicate,and false if it is duplicate */ private boolean isDuplicateName() { String name = nameEditor.getText().trim(); return Utility.checkDataSetName(name); } private String getDataSetName() { return (nameEditor.getText()); } /** * whether name contains ".", "/", "\", "!", ";", "," charactors * * @param name * @return */ private boolean containInvalidCharactor(String name) { if (name == null) return false; else if (name.indexOf(".") > -1 || //$NON-NLS-1$ name.indexOf("\\") > -1 || name.indexOf("/") > -1 || //$NON-NLS-1$ //$NON-NLS-2$ name.indexOf("!") > -1 || name.indexOf(";") > -1 || //$NON-NLS-1$ //$NON-NLS-2$ name.indexOf(",") > -1) // $NON-NLS-1$ return true; else return false; } protected final DataSourceHandle getSelectedDataSource() { if (((IStructuredSelection) dataSourceFilteredTree.getViewer().getSelection()).getFirstElement() instanceof DataSourceHandle) return (DataSourceHandle) ((IStructuredSelection) dataSourceFilteredTree.getViewer().getSelection()) .getFirstElement(); else return null; } /** @return Returns the newDataSource. */ final DataSourceHandle getNewDataSource() { return newDataSource; } /** @param newDataSourceHandle The newDataSource to set. */ final void setNewDataSource(DataSourceHandle newDataSourceHandle) { this.newDataSource = newDataSourceHandle; } /* * (non-Javadoc) * * @see org.eclipse.jface.wizard.IWizardPage#getNextPage() */ public IWizardPage getNextPage() { setPageComplete(true); if (((IStructuredSelection) dataSetTypeChooser.getSelection()).getFirstElement() instanceof DataSetTypeElement) { if (useODAV3) { nextPage = getNextPageODAV3(); return nextPage; } else { nextPage = getNextPageODAV2(); return nextPage; } } // switch to script data set page return super.getNextPage(); } /** * @param dataSourceDesign * @return */ private IWizardPage getNextPageODAV3() { DataSourceDesign dataSourceDesign = new ModelOdaAdapter().createDataSourceDesign((OdaDataSourceHandle) getSelectedDataSource()); OdaDataSetTypeElement dataSetElement = (OdaDataSetTypeElement) getSelectedDataSet(); String dataSetID = dataSetElement.getDataSetType().getID(); try { DTPUtil.getInstance().supplementDesignAttributes(dataSourceDesign); if (m_designSession == null) m_designSession = DataSetDesignSession.startNewDesign( nameEditor.getText().trim(), dataSetID, dataSourceDesign); else m_designSession.restartNewDesign(nameEditor.getText().trim(), dataSetID, dataSourceDesign); return m_designSession.getWizardStartingPage(); } catch (OdaException e) { // TODO Auto-generated catch block return null; } catch (URISyntaxException e) { ExceptionHandler.handle(e); return null; } } public void setPageFocus() { if (nameEditor != null && !nameEditor.isDisposed()) { nameEditor.setFocus(); } } public boolean canFinish() { if (!validStatus()) return false; try { if (m_designSession != null) return m_designSession.getNewWizard().canFinish(); else { if (this.nextPage != null) { return nextPage.isPageComplete(); } return isPageComplete(); } } catch (OdaException e) { return false; } } /** @return */ private IWizardPage getNextPageODAV2() { // Get the currently selected Data Set type and invoke its wizard // class DataSetTypeElement dataSetElement = (DataSetTypeElement) ((IStructuredSelection) dataSetTypeChooser.getSelection()).getFirstElement(); if (m_designSession != null) m_designSession = null; if (dataSetElement instanceof OdaDataSetTypeElement) { OdaDataSetTypeElement dElement = (OdaDataSetTypeElement) dataSetElement; IConfigurationElement element = dElement.getIConfigurationElement(); AbstractDataSetWizard newWizard = null; if (element != null) { newWizard = (AbstractDataSetWizard) htDataSetWizards.get(element.getAttribute("id")); // $NON-NLS-1$ } if (newWizard == null && element != null) { // Get the new wizard from this element IConfigurationElement[] elements = element.getChildren("newDataSetWizard"); // $NON-NLS-1$ if (elements.length > 0) { // Use only the first one. // There can only be one data set wizard for a data set try { Object wizard = elements[0].createExecutableExtension("class"); // $NON-NLS-1$ if (wizard instanceof AbstractDataSetWizard) { newWizard = (AbstractDataSetWizard) wizard; newWizard.setConfigurationElement(element); // Allow the wizard to create its pages newWizard.addPages(); newWizard.setUseTransaction(useTransaction); htDataSetWizards.put( element.getAttribute("id"), // $NON-NLS-1$ newWizard); } } catch (CoreException e) { ExceptionHandler.handle(e); } } } if (newWizard != null) { newWizard.setDataSource(getSelectedDataSource()); newWizard.setDataSetName(nameEditor.getText().trim()); // if the data set has been created // update it in the data set as well if (newWizard.getDataSet() != null) { try { newWizard.getDataSet().setDataSource(newWizard.getDataSource().getName()); newWizard.getDataSet().setName(newWizard.getDataSetName()); } catch (SemanticException e) { ExceptionHandler.handle(e); } } return newWizard.getStartingPage(); } } else { IWizardPage page = helper.getNextPage(getSelectedDataSource(), dataSetElement); if (page == null) return super.getNextPage(); else return page; } return super.getNextPage(); } /* * (non-Javadoc) * * @see org.eclipse.jface.wizard.IWizardPage#canFlipToNextPage() */ public boolean canFlipToNextPage() { return validStatus(); } public boolean validStatus() { return this.getMessageType() != ERROR && !StringUtil.isBlank(nameEditor.getText()) && getSelectedDataSource() != null && getSelectedDataSet() != null; } /** The action after data source is selected */ private void doDataSourceSelectionChanged(Object data) { if (data instanceof DataSourceType) { DataSetTypeElement[] types = ((DataSourceType) data).getDataSetTypes(); dataSetTypeChooser.setInput(types); dateSetTypeSelection = new StructuredSelection(types[0]); dataSetTypeChooser.setSelection(dateSetTypeSelection); String dataSourceID = ((DataSourceType) data).getDataSourceID(); if (isScriptDataSet(dataSourceID)) { useODAV3 = false; } else { useODAV3 = DesignSessionUtil.hasValidOdaDesignUIExtension(dataSourceID); } } } private Object getSelectedDataSet() { return ((IStructuredSelection) dataSetTypeChooser.getSelection()).getFirstElement(); } private boolean hasWizard() { DataSetTypeElement dTypeElement = (DataSetTypeElement) getSelectedDataSet(); if (dTypeElement == null) { return false; } if (dTypeElement instanceof OdaDataSetTypeElement) { // Get the currently selected Data Set type and invoke its wizard // class IConfigurationElement element = ((OdaDataSetTypeElement) dTypeElement).getIConfigurationElement(); if (element != null) { AbstractDataSetWizard newWizard = (AbstractDataSetWizard) htDataSetWizards.get(element.getAttribute("id")); // $NON-NLS-1$ if (newWizard != null) { return true; } // Get the new wizard from this element IConfigurationElement[] v3elements = element.getChildren("dataSetWizard"); // $NON-NLS-1$ IConfigurationElement[] v2elements = element.getChildren("newDataSetWizard"); // $NON-NLS-1$ if (v3elements.length > 0 || v2elements.length > 0) { return true; } } } else if (isScriptDataSet(dTypeElement.getDataSetTypeName())) { return true; } else return helper.hasWizard(getSelectedDataSource()); return false; } DataSetHandle createSelectedDataSet() { DataSetHandle dataSetHandle = null; try { if (useODAV3) { dataSetHandle = createDataSetODAV3(); } else { dataSetHandle = createDataSetODAV2(); } if (nameEditor != null && !nameEditor.isDisposed()) dataSetHandle.setName(nameEditor.getText()); return dataSetHandle; } catch (SemanticException e) { ExceptionHandler.handle(e); return null; } catch (IllegalStateException e) { ExceptionHandler.handle(e); return null; } catch (OdaException e) { ExceptionHandler.handle(e); return null; } } /** * @return * @throws OdaException * @throws SemanticException * @throws IllegalStateException */ private DataSetHandle createDataSetODAV3() throws OdaException, SemanticException, IllegalStateException { DesignElementHandle parentHandle = Utility.getReportModuleHandle(); DataSetHandle dataSetHandle = DTPUtil.getInstance() .createOdaDataSetHandle( m_designSession.finish().getResponse(), (ModuleHandle) parentHandle); m_designSession = null; // reset return dataSetHandle; } /** * @return * @throws SemanticException */ private DataSetHandle createDataSetODAV2() throws SemanticException { String dataSetTypeName = null; if (getSelectedDataSet() instanceof Object[]) { DataSetType dataSetElement = (DataSetType) ((Object[]) getSelectedDataSet())[0]; dataSetTypeName = dataSetElement.getID(); } else if (getSelectedDataSet() instanceof OdaDataSetTypeElement) { dataSetTypeName = ((OdaDataSetTypeElement) getSelectedDataSet()).getDataSetType().getID(); } else if (getSelectedDataSet() instanceof DataSetTypeElement) { dataSetTypeName = ((DataSetTypeElement) getSelectedDataSet()).getDataSetTypeName(); } return createDataSet(dataSetTypeName); } private DataSetHandle createDataSet(String dataSetType) throws SemanticException { DataSourceHandle source = getSelectedDataSource(); if (source instanceof OdaDataSourceHandle) { OdaDataSetHandle dsHandle = Utility.newOdaDataSet(getDataSetName().trim(), dataSetType); dsHandle.setDataSource(source.getQualifiedName()); dsHandle.setQueryText(""); // $NON-NLS-1$ //Need a empty query in the dataset. return dsHandle; } else if (source instanceof ScriptDataSourceHandle) { ScriptDataSetHandle dsHandle = Utility.newScriptDataSet(getDataSetName()); dsHandle.setDataSource(source.getName()); return dsHandle; } else return helper.createDataSet(getDataSetName().trim(), dataSetType); } public String getScriptDataSetName(DataSourceHandle dataSourceHandle) { if (dataSourceHandle instanceof ScriptDataSourceHandle) { if (dataSourceHandle.getProperty(DataUIConstants.SCRIPT_TYPE) != null && dataSourceHandle .getProperty(DataUIConstants.SCRIPT_TYPE) .equals(DataUIConstants.CASSANDRA_DATA_SOURCE_VALUE)) { return CASSANDRA_DATASET_NAME; } else return SCRIPT_DATASET_NAME; } return null; } public String getScriptDataSourceName(DataSourceHandle dataSourceHandle) { if (dataSourceHandle instanceof ScriptDataSourceHandle) { if (dataSourceHandle.getProperty(DataUIConstants.SCRIPT_TYPE) != null && dataSourceHandle .getProperty(DataUIConstants.SCRIPT_TYPE) .equals(DataUIConstants.CASSANDRA_DATA_SOURCE_VALUE)) { return CASSANDRA_DATASOURCE_NAME; } else return SCRIPT_DATASOURCE_NAME; } return null; } public boolean isScriptDataSet(String dataSourceID) { if (SCRIPT_DATASOURCE_NAME.equals(dataSourceID) || CASSANDRA_DATASOURCE_NAME.equals(dataSourceID)) { return true; } return false; } }
/** * Constructs a new instance of block preference page. * * @param model the preference store( model ) for the following field editors. */ public BlockPreferencePage(Object model) { super(model); setTitle(Messages.getString("BlockPreferencePage.displayname.Title")); // $NON-NLS-1$ this.model = model; }
public class ColorControl extends Composite { protected Combo combo; protected ColorSelector colorSelector; private IChoiceSet choiceSet; private RGB oldRgb; private String predefinedColor; private static final String NONE_CHOICE = Messages.getString("ColorBuilder.text.Auto"); // $NON-NLS-1$ /** * The constructor. * * @param parent a widget which will be the parent of the new instance (cannot be null) * @param style the style of widget to construct */ public ColorControl(Composite parent, int style) { super(parent, style); setLayout(WidgetUtil.createSpaceGridLayout(2, 0)); ((GridLayout) getLayout()).horizontalSpacing = 2; colorSelector = new ColorSelector(this); { GridData data = new GridData(); data.widthHint = 50; data.grabExcessHorizontalSpace = false; colorSelector.getButton().setLayoutData(data); } colorSelector.addListener( new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { predefinedColor = null; processAction(colorSelector.getColorValue()); } }); combo = new Combo(this, SWT.DROP_DOWN); { GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; // data.widthHint = 80; combo.setLayoutData(data); } combo.add(NONE_CHOICE); combo.addFocusListener( new FocusListener() { public void focusGained(org.eclipse.swt.events.FocusEvent e) {} public void focusLost(org.eclipse.swt.events.FocusEvent e) { combo.notifyListeners(SWT.DefaultSelection, null); } }); combo.addSelectionListener( new SelectionListener() { public void widgetSelected(SelectionEvent e) { predefinedColor = combo.getText(); if (NONE_CHOICE.equals(predefinedColor)) { predefinedColor = null; processAction(null); return; } String colorName = predefinedColor; if (choiceSet != null) { if (choiceSet.findChoiceByDisplayName(colorName) != null) colorName = choiceSet.findChoiceByDisplayName(colorName).getName(); } int[] intRgb = ColorUtil.getRGBs(colorName); RGB rgb = null; if (intRgb != null) { rgb = new RGB(intRgb[0], intRgb[1], intRgb[2]); } processAction(rgb); } public void widgetDefaultSelected(SelectionEvent e) { predefinedColor = null; String string = combo.getText(); int index = -1; String[] items = combo.getItems(); for (int i = 0; i < items.length; i++) { if (items[i].equalsIgnoreCase(string)) { index = i; combo.setText(items[i]); break; } } if (index != -1) { widgetSelected(null); return; } RGB rgb = parseString(string); if (rgb == null) { combo.deselectAll(); notifyListeners(SWT.Modify, null); } else processAction(rgb); } }); initAccessible(); } Label getAssociatedLabel() { Control[] siblings = getParent().getChildren(); for (int i = 0; i < siblings.length; i++) { if (siblings[i] == this) { if (i > 0 && siblings[i - 1] instanceof Label) { return (Label) siblings[i - 1]; } } } return null; } String stripMnemonic(String string) { int index = 0; int length = string.length(); do { while ((index < length) && (string.charAt(index) != '&')) index++; if (++index >= length) return string; if (string.charAt(index) != '&') { return string.substring(0, index - 1) + string.substring(index, length); } index++; } while (index < length); return string; } char _findMnemonic(String string) { if (string == null) return '\0'; int index = 0; int length = string.length(); do { while (index < length && string.charAt(index) != '&') index++; if (++index >= length) return '\0'; if (string.charAt(index) != '&') return Character.toLowerCase(string.charAt(index)); index++; } while (index < length); return '\0'; } void initAccessible() { AccessibleAdapter accessibleAdapter = new AccessibleAdapter() { public void getName(AccessibleEvent e) { String name = null; Label label = getAssociatedLabel(); if (label != null) { name = stripMnemonic(label.getText()); } e.result = name; } public void getKeyboardShortcut(AccessibleEvent e) { String shortcut = null; Label label = getAssociatedLabel(); if (label != null) { String text = label.getText(); if (text != null) { char mnemonic = _findMnemonic(text); if (mnemonic != '\0') { shortcut = "Alt+" + mnemonic; // $NON-NLS-1$ } } } e.result = shortcut; } public void getHelp(AccessibleEvent e) { e.result = getToolTipText(); } }; getAccessible().addAccessibleListener(accessibleAdapter); combo .getAccessible() .addAccessibleListener( new AccessibleAdapter() { public void getName(AccessibleEvent e) { String name = null; Label label = getAssociatedLabel(); if (label != null) { name = stripMnemonic(label.getText()); } e.result = name; } public void getKeyboardShortcut(AccessibleEvent e) { e.result = "Alt+Down Arrow"; // $NON-NLS-1$ } public void getHelp(AccessibleEvent e) { e.result = getToolTipText(); } }); getAccessible() .addAccessibleControlListener( new AccessibleControlAdapter() { public void getChildAtPoint(AccessibleControlEvent e) { Point testPoint = toControl(e.x, e.y); if (getBounds().contains(testPoint)) { e.childID = ACC.CHILDID_SELF; } } public void getLocation(AccessibleControlEvent e) { Rectangle location = getBounds(); Point pt = toDisplay(location.x, location.y); e.x = pt.x; e.y = pt.y; e.width = location.width; e.height = location.height; } public void getChildCount(AccessibleControlEvent e) { e.detail = 0; } public void getRole(AccessibleControlEvent e) { e.detail = ACC.ROLE_COMBOBOX; } public void getState(AccessibleControlEvent e) { e.detail = ACC.STATE_NORMAL; } public void getValue(AccessibleControlEvent e) { e.result = combo.getText(); } }); combo .getAccessible() .addAccessibleControlListener( new AccessibleControlAdapter() { public void getRole(AccessibleControlEvent e) { e.detail = ACC.ROLE_COMBOBOX; ; } public void getValue(AccessibleControlEvent e) { e.result = combo.getText(); } }); } /** * Sets the color choiceSet from DE model. * * @param choiceSet The color ChoiceSet. */ public void setChoiceSet(IChoiceSet choiceSet) { this.choiceSet = choiceSet; String[] colors = ChoiceSetFactory.getDisplayNamefromChoiceSet(choiceSet); Arrays.sort(colors); combo.removeAll(); combo.add(NONE_CHOICE); if (colors != null) for (int i = 0; i < colors.length; i++) combo.add(colors[i]); } /** * Parses the input string to a GRB object. * * @param string The input string. * @return The RGB object represented the string. */ protected RGB parseString(String string) { int colors[] = ColorUtil.getRGBs(string); if (colors != null) return new RGB(colors[0], colors[1], colors[2]); StringTokenizer st = new StringTokenizer(string, " ,()"); // $NON-NLS-1$ if (!st.hasMoreTokens()) return null; int[] rgb = new int[] {0, 0, 0}; int index = 0; while (st.hasMoreTokens()) { try { rgb[index] = Integer.decode(st.nextToken()).intValue(); if (rgb[index] < 0 || rgb[index] > 255) return null; index++; } catch (Exception e) { return null; } } return new RGB(rgb[0], rgb[1], rgb[2]); } /** * Processes the save action. * * @param rgb The new RGB value. */ protected void processAction(RGB rgb) { String newComboText = predefinedColor; if (newComboText == null) newComboText = formatRGB(rgb); if (!combo.getText().equals(newComboText)) combo.setText(newComboText); if (oldRgb == null && rgb == null) return; if (rgb != null && rgb.equals(oldRgb)) return; oldRgb = rgb; if (rgb == null || !rgb.equals(colorSelector.getColorValue())) colorSelector.setColorValue(rgb); notifyListeners(SWT.Modify, null); } /* * (non-Javadoc) * * @see org.eclipse.swt.widgets.Control#setEnabled(boolean) */ public void setEnabled(boolean enabled) { combo.setEnabled(enabled); colorSelector.setEnabled(enabled); super.setEnabled(enabled); } /** * Gets the current RGB value * * @return The current RGB value. */ public RGB getRGB() { return oldRgb; } public void setColorValue(String value) { predefinedColor = null; if (choiceSet != null) { IChoice choice = choiceSet.findChoice(value); if (choice != null) { predefinedColor = choice.getDisplayName(); } } int[] rgbValues = ColorUtil.getRGBs(value); if (rgbValues == null) { setRGB(null); } else { setRGB(new RGB(rgbValues[0], rgbValues[1], rgbValues[2])); } } public void setRGB(RGB rgb) { oldRgb = rgb; if (combo.isDisposed()) { return; } colorSelector.setColorValue(rgb); String newComboText = predefinedColor; if (predefinedColor == null) { if (rgb == null) { newComboText = NONE_CHOICE; } else { newComboText = formatRGB(rgb); } } if (!combo.getText().equals(newComboText)) { combo.setText(newComboText); } } private String formatRGB(RGB rgb) { if (rgb == null) { return NONE_CHOICE; } String value = ColorUtil.getPredefinedColor(DEUtil.getRGBInt(rgb)); if (value != null && combo != null) { String items[] = combo.getItems(); for (int i = 0; i < items.length; i++) { if (items[i].equalsIgnoreCase(value)) { return items[i]; } } } return ColorUtil.format( ColorUtil.formRGB(rgb.red, rgb.green, rgb.blue), ColorUtil.CSS_ABSOLUTE_FORMAT); } public Point computeSize(int wHint, int hHint, boolean changed) { checkWidget(); int width = 0, height = 0; GC gc = new GC(combo); Point labelExtent = gc.textExtent("RGB(255,255,255)"); // $NON-NLS-1$ gc.dispose(); Point labelSize = combo.computeSize(labelExtent.x, labelExtent.y, changed); Point tableSize = colorSelector.getButton().computeSize(wHint, SWT.DEFAULT, changed); int borderWidth = getBorderWidth(); height = Math.max(hHint, Math.max(labelSize.y, tableSize.y) + 2 * borderWidth); width = Math.max(wHint, labelSize.x + tableSize.x + 2 * borderWidth); return new Point(width, height); } /** * Returns the color in predefined format by model. * * @return Returns the predefinedColor. */ public String getPredefinedColor() { return predefinedColor; } }
/* * (non-Javadoc) * * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors() */ protected void createFieldEditors() { // super.createFieldEditors( ); lineHeight = new ComboBoxMeasureFieldEditor( StyleHandle.LINE_HEIGHT_PROP, Messages.getString( ((StyleHandle) model) .getPropertyHandle(StyleHandle.LINE_HEIGHT_PROP) .getDefn() .getDisplayNameID()), getChoiceArray( ChoiceSetFactory.getElementChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.LINE_HEIGHT_PROP)), getChoiceArray( ChoiceSetFactory.getDimensionChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.LINE_HEIGHT_PROP)), getFieldEditorParent()); lineHeight.setDefaultUnit( ((StyleHandle) model).getPropertyHandle(StyleHandle.LINE_HEIGHT_PROP).getDefaultUnit()); charSpacing = new ComboBoxMeasureFieldEditor( StyleHandle.LETTER_SPACING_PROP, Messages.getString( ((StyleHandle) model) .getPropertyHandle(StyleHandle.LETTER_SPACING_PROP) .getDefn() .getDisplayNameID()), getChoiceArray( ChoiceSetFactory.getElementChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.LETTER_SPACING_PROP)), getChoiceArray( ChoiceSetFactory.getDimensionChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.LETTER_SPACING_PROP)), getFieldEditorParent()); charSpacing.setDefaultUnit( ((StyleHandle) model).getPropertyHandle(StyleHandle.LETTER_SPACING_PROP).getDefaultUnit()); wordSpacing = new ComboBoxMeasureFieldEditor( StyleHandle.WORD_SPACING_PROP, Messages.getString( ((StyleHandle) model) .getPropertyHandle(StyleHandle.WORD_SPACING_PROP) .getDefn() .getDisplayNameID()), getChoiceArray( ChoiceSetFactory.getElementChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.WORD_SPACING_PROP)), getChoiceArray( ChoiceSetFactory.getDimensionChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.WORD_SPACING_PROP)), getFieldEditorParent()); wordSpacing.setDefaultUnit( ((StyleHandle) model).getPropertyHandle(StyleHandle.WORD_SPACING_PROP).getDefaultUnit()); verticalAlign = new ComboBoxFieldEditor( StyleHandle.VERTICAL_ALIGN_PROP, Messages.getString( ((StyleHandle) model) .getPropertyHandle(StyleHandle.VERTICAL_ALIGN_PROP) .getDefn() .getDisplayNameID()), getChoiceArray( ChoiceSetFactory.getElementChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.VERTICAL_ALIGN_PROP), true), getFieldEditorParent()); textAlign = new ComboBoxFieldEditor( StyleHandle.TEXT_ALIGN_PROP, Messages.getString( ((StyleHandle) model) .getPropertyHandle(StyleHandle.TEXT_ALIGN_PROP) .getDefn() .getDisplayNameID()), getChoiceArray( ChoiceSetFactory.getElementChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.TEXT_ALIGN_PROP), true), getFieldEditorParent()); textIndent = new ComboBoxMeasureFieldEditor( StyleHandle.TEXT_INDENT_PROP, Messages.getString( ((StyleHandle) model) .getPropertyHandle(StyleHandle.TEXT_INDENT_PROP) .getDefn() .getDisplayNameID()), getChoiceArray( ChoiceSetFactory.getDimensionChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.TEXT_INDENT_PROP)), getFieldEditorParent()); textIndent.setDefaultUnit( ((StyleHandle) model).getPropertyHandle(StyleHandle.TEXT_INDENT_PROP).getDefaultUnit()); textTrans = new ComboBoxFieldEditor( StyleHandle.TEXT_TRANSFORM_PROP, Messages.getString( ((StyleHandle) model) .getPropertyHandle(StyleHandle.TEXT_TRANSFORM_PROP) .getDefn() .getDisplayNameID()), getChoiceArray( ChoiceSetFactory.getElementChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.TEXT_TRANSFORM_PROP)), getFieldEditorParent()); whiteSpace = new ComboBoxFieldEditor( StyleHandle.WHITE_SPACE_PROP, Messages.getString( ((StyleHandle) model) .getPropertyHandle(StyleHandle.WHITE_SPACE_PROP) .getDefn() .getDisplayNameID()), getChoiceArray( ChoiceSetFactory.getElementChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.WHITE_SPACE_PROP)), getFieldEditorParent()); display = new ComboBoxFieldEditor( StyleHandle.DISPLAY_PROP, Messages.getString( ((StyleHandle) model) .getPropertyHandle(StyleHandle.DISPLAY_PROP) .getDefn() .getDisplayNameID()), getChoiceArray( ChoiceSetFactory.getElementChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.DISPLAY_PROP)), getFieldEditorParent()); addField(lineHeight); addField(charSpacing); addField(wordSpacing); addField(verticalAlign); addField(textAlign); addField(textIndent); addField(textTrans); addField(whiteSpace); addField(display); // bidi_hcg start direction = new ComboBoxFieldEditor( StyleHandle.TEXT_DIRECTION_PROP, Messages.getString( ((StyleHandle) model) .getPropertyHandle(StyleHandle.TEXT_DIRECTION_PROP) .getDefn() .getDisplayNameID()), getChoiceArray( ChoiceSetFactory.getElementChoiceSet( ReportDesignConstants.STYLE_ELEMENT, StyleHandle.TEXT_DIRECTION_PROP), true), getFieldEditorParent()); addField(direction); // bidi_hcg end UIUtil.bindHelp(getFieldEditorParent().getParent(), IHelpContextIds.STYLE_BUILDER_TEXTBLOCK_ID); }
public AddVariableAction(Object selectedObject) { super( selectedObject, Messages.getString("VariablesNodeProvider.NewActionName")); // $NON-NLS-1$ }
private void createErrorControl(Composite parent) { Color bgColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); Color fgColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND); parent.setBackground(bgColor); parent.setForeground(fgColor); GridLayout layout = new GridLayout(); layout.numColumns = 3; int spacing = 8; int margins = 8; layout.marginBottom = margins; layout.marginTop = margins; layout.marginLeft = margins; layout.marginRight = margins; layout.horizontalSpacing = spacing; layout.verticalSpacing = spacing; parent.setLayout(layout); Label imageLabel = new Label(parent, SWT.NONE); imageLabel.setBackground(bgColor); Image image = getImage(); if (image != null) { image.setBackground(bgColor); imageLabel.setImage(image); imageLabel.setLayoutData( new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_BEGINNING)); } Text text = new Text(parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP); text.setBackground(bgColor); text.setForeground(fgColor); // text.setForeground(JFaceColors.getErrorText(text.getDisplay())); text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); text.setText(Messages.getString("ReportDocumentEditor.errorMessage")); // $NON-NLS-1$ detailsButton = new Button(parent, SWT.PUSH); detailsButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { showDetails(!showingDetails); } }); detailsButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); detailsButton.setVisible(e != null); updateDetailsText(); detailsArea = new Composite(parent, SWT.NONE); detailsArea.setBackground(bgColor); detailsArea.setForeground(fgColor); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 3; data.verticalSpan = 1; detailsArea.setLayoutData(data); detailsArea.setLayout(new FillLayout()); parent.layout(true); }
public String getNodeDisplayName(Object object) { return Messages.getString("VariablesNodeProvider.NodeName"); // $NON-NLS-1$ }
public class UserPropertyBuilder extends BaseDialog { public static final int USER_PROPERTY = 0; public static final int NAMED_EXPRESSION = 1; private static final String PROPERTY_TITLE = Messages.getString("UserPropertyBuilder.0"); // $NON-NLS-1$ private static final String EXPRESSION_TITLE = Messages.getString("UserPropertyBuilder.Title.NamedExpression"); // $NON-NLS-1$ private static final String ERROR_MSG_NAME_IS_REQUIRED = Messages.getString("UserPropertyBuilder.ErrorMessage.NoName"); // $NON-NLS-1$ private static final String ERROR_MSG_NAME_DUPLICATED = Messages.getString("UserPropertyBuilder.ErrorMessage.DuplicatedName"); // $NON-NLS-1$ private static final String LABEL_PROPERTY_NAME = Messages.getString("UserPropertyBuilder.Label.PropertyName"); // $NON-NLS-1$ private static final String LABEL_EXPRESSION_NAME = Messages.getString("UserPropertyBuilder.Label.ExpressionName"); // $NON-NLS-1$ private static final String LABEL_TYPE = Messages.getString("UserPropertyBuilder.Label.PropertyType"); // $NON-NLS-1$ private static final String LABEL_DEFAULT_VALUE = Messages.getString("UserPropertyBuilder.Label.DefaultValue"); // $NON-NLS-1$ private static final Image ERROR_ICON = ReportPlatformUIImages.getImage(ISharedImages.IMG_OBJS_ERROR_TSK); private static PropertyType[] PROPERTY_TYPES; private static PropertyType EXPRESSION_TYPE; static { List typeList = new ArrayList(UserPropertyDefn.getAllowedTypes()); EXPRESSION_TYPE = DEUtil.getMetaDataDictionary().getPropertyType(PropertyType.EXPRESSION_TYPE); typeList.remove(EXPRESSION_TYPE); PROPERTY_TYPES = (PropertyType[]) typeList.toArray(new PropertyType[0]); } private DesignElementHandle input; private int style; private Text nameEditor, defaultValueEditor; private Combo typeChooser; private CLabel messageLine; public UserPropertyBuilder(int style) { super(UIUtil.getDefaultShell(), ""); // $NON-NLS-1$ switch (this.style = style) { case USER_PROPERTY: setTitle(PROPERTY_TITLE); break; case NAMED_EXPRESSION: setTitle(EXPRESSION_TITLE); break; } } protected boolean initDialog() { switch (style) { case USER_PROPERTY: typeChooser.setText(new UserPropertyDefn().getType().getDisplayName()); break; case NAMED_EXPRESSION: } checkName(); return super.initDialog(); } protected Control createDialogArea(Composite parent) { switch (style) { case USER_PROPERTY: UIUtil.bindHelp(parent, IHelpContextIds.ADD_EDIT_USER_PROPERTIES_DIALOG_ID); break; case NAMED_EXPRESSION: UIUtil.bindHelp(parent, IHelpContextIds.ADD_EDIT_NAMED_EXPRESSION_DIALOG_ID); break; } Composite composite = (Composite) super.createDialogArea(parent); GridLayout layout = new GridLayout(2, false); layout.marginHeight = layout.marginWidth = 10; composite.setLayout(layout); messageLine = new CLabel(composite, SWT.NONE); GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; messageLine.setLayoutData(gd); switch (style) { case USER_PROPERTY: new Label(composite, SWT.NONE).setText(LABEL_PROPERTY_NAME); break; case NAMED_EXPRESSION: new Label(composite, SWT.NONE).setText(LABEL_EXPRESSION_NAME); break; } nameEditor = new Text(composite, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); gd.widthHint = 200; nameEditor.setLayoutData(gd); nameEditor.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { checkName(); } }); switch (style) { case USER_PROPERTY: new Label(composite, SWT.NONE).setText(LABEL_TYPE); typeChooser = new Combo(composite, SWT.BORDER | SWT.READ_ONLY); typeChooser.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); typeChooser.setVisibleItemCount(30); for (int i = 0; i < PROPERTY_TYPES.length; i++) { typeChooser.add(PROPERTY_TYPES[i].getDisplayName(), i); } break; case NAMED_EXPRESSION: new Label(composite, SWT.NONE).setText(LABEL_DEFAULT_VALUE); Composite subComposite = new Composite(composite, SWT.NONE); subComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); subComposite.setLayout(UIUtil.createGridLayoutWithoutMargin(2, false)); defaultValueEditor = new Text(subComposite, SWT.BORDER | SWT.WRAP); gd = new GridData(GridData.FILL_HORIZONTAL); gd.heightHint = defaultValueEditor.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - defaultValueEditor.getBorderWidth() * 2; defaultValueEditor.setLayoutData(gd); createComplexExpressionButton(subComposite, defaultValueEditor); } return composite; } private void createComplexExpressionButton(Composite parent, final Text text) { ExpressionButtonUtil.createExpressionButton(parent, text, new ExpressionProvider(input), input); } protected void okPressed() { UserPropertyDefn def = new UserPropertyDefn(); def.setName(nameEditor.getText().trim()); switch (style) { case USER_PROPERTY: def.setType(PROPERTY_TYPES[typeChooser.getSelectionIndex()]); break; case NAMED_EXPRESSION: def.setType(EXPRESSION_TYPE); def.setDefault(ExpressionButtonUtil.getExpression(defaultValueEditor)); break; } setResult(def); super.okPressed(); } public void setInput(DesignElementHandle handle) { input = handle; } private void checkName() { String errorMessage = null; String name = nameEditor.getText().trim(); if (name.length() == 0) { errorMessage = ERROR_MSG_NAME_IS_REQUIRED; messageLine.setImage(null); } else if (input.getPropertyHandle(name) != null) { errorMessage = ERROR_MSG_NAME_DUPLICATED; messageLine.setImage(ERROR_ICON); } if (errorMessage != null) { messageLine.setText(errorMessage); } else { messageLine.setText(""); // $NON-NLS-1$ messageLine.setImage(null); } getOkButton().setEnabled(errorMessage == null); } }
/** * Presents a list of values from dataset, allows user to select to define default value for dynamic * parameter */ public class SelectParameterDefaultValueDialog extends BaseDialog { // private static final String STANDARD_DATE_TIME_PATTERN = "MM/dd/yyyy hh:mm:ss a"; //$NON-NLS-1$ private TableViewer tableViewer = null; private Table table = null; private Object[] selectedItems = null; private int[] selectedIndices = null; private int sortDir = SWT.UP; private java.util.List<Object> columnValueList = new ArrayList<Object>(); private final String nullValueDispaly = Messages.getString("SelectValueDialog.SelectValue.NullValue"); // $NON-NLS-1$ private int expectedColumnDataType; private static DateFormatter formatter = new DateFormatter(ULocale.US); public SelectParameterDefaultValueDialog(Shell parentShell, String title) { super(parentShell, title); } public void setColumnValueList(Collection valueList, String dateType) { columnValueList.clear(); columnValueList.addAll(valueList); expectedColumnDataType = DataAdapterUtil.modelDataTypeToCoreDataType(dateType); } /* * (non-Javadoc) * * @see * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets * .Composite) */ protected Control createDialogArea(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); tableViewer = new TableViewer(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); GridData data = new GridData(GridData.FILL_BOTH); data.heightHint = 250; data.widthHint = 300; table = tableViewer.getTable(); table.setLayoutData(data); table.setHeaderVisible(true); final TableColumn column = new TableColumn(table, SWT.NONE); column.setText(Messages.getString("SelectValueDialog.selectValue")); // $NON-NLS-1$ column.setWidth(data.widthHint); TableItem item = new TableItem(table, SWT.NONE); item.setText(0, Messages.getString("SelectValueDialog.retrieving")); // $NON-NLS-1$ column.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { sortDir = sortDir == SWT.UP ? SWT.DOWN : SWT.UP; table.setSortDirection(sortDir); tableViewer.setSorter(new TableSorter(sortDir)); } }); table.addMouseListener( new MouseAdapter() { public void mouseDoubleClick(MouseEvent e) { if (table.getSelectionCount() > 0) { okPressed(); } } }); PlatformUI.getWorkbench() .getDisplay() .asyncExec( new Runnable() { public void run() { populateList(); } }); UIUtil.bindHelp(parent, IHelpContextIds.SELECT_PARAMETER_DEFAULT_VALUE_DIALOG_ID); return composite; } /* * (non-Javadoc) * * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { selectedIndices = table.getSelectionIndices(); if (columnValueList.get(selectedIndices[0]) == null) { setResult(null); } else { selectedItems = new Object[table.getSelectionCount()]; for (int i = 0; i < table.getSelectionCount(); i++) { selectedItems[i] = table.getSelection()[i].getData(); } setResult(table.getSelection()); } super.okPressed(); } /** populate all available value in selectValueList */ private void populateList() { try { if (this.getShell() == null || this.getShell().isDisposed()) return; if (this.getOkButton() != null && !this.getOkButton().isDisposed()) getOkButton().setEnabled(false); table.removeAll(); table.deselectAll(); tableViewer.setContentProvider(new ContentProvider()); tableViewer.setLabelProvider(new TableLabelProvider()); if (columnValueList != null) { tableViewer.setInput(columnValueList); } else { ExceptionHandler.openErrorMessageBox( Messages.getString("SelectValueDialog.errorRetrievinglist"), Messages.getString("SelectValueDialog.noExpressionSet")); // $NON-NLS-1$ //$NON-NLS-2$ } if (table.getItemCount() > 0) { table.select(0); getOkButton().setEnabled(true); } for (int i = 0; i < table.getItemCount(); i++) { table.getItem(i).setData(columnValueList.get(i)); } table.setSortColumn(table.getColumn(0)); table.setSortDirection(sortDir); tableViewer.setSorter(new TableSorter(sortDir)); table.setSelection(0); } catch (Exception e) { ExceptionHandler.handle(e); } } public String[] getSelectedValue() { String[] exprValues = null; if (selectedIndices != null && selectedIndices.length > 0) { exprValues = new String[selectedIndices.length]; for (int i = 0; i < selectedIndices.length; i++) { if (selectedItems[i] == null) { exprValues[i] = "null"; // $NON-NLS-1$ } else { exprValues[i] = getDataText(selectedItems[i]); } } } return exprValues; } public class TableSorter extends ViewerSorter { private int sortDir; private TableSorter(int sortDir) { this.sortDir = sortDir; } public int compare(Viewer viewer, Object e1, Object e2) { if (sortDir == SWT.UP) { if (e1 instanceof Integer) { return ((Integer) e1).compareTo((Integer) e2); } else if (e1 instanceof Double) { return ((Double) e1).compareTo((Double) e2); } else if (e1 instanceof BigDecimal) { return ((BigDecimal) e1).compareTo((BigDecimal) e2); } else if (getDataText(e1) != null) { return getDataText(e1).compareTo(getDataText(e2)); } } else if (sortDir == SWT.DOWN) { if (e2 instanceof Integer) { return ((Integer) e2).compareTo((Integer) e1); } else if (e2 instanceof Double) { return ((Double) e2).compareTo((Double) e1); } else if (e2 instanceof BigDecimal) { return ((BigDecimal) e2).compareTo((BigDecimal) e1); } else if (getDataText(e2) != null) { return getDataText(e2).compareTo(getDataText(e1)); } } return 0; } } public static class ContentProvider implements IStructuredContentProvider { public Object[] getElements(Object inputElement) { if (inputElement instanceof List) { return ((List) inputElement).toArray(); } return new Object[0]; } public void dispose() {} public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} } public class TableLabelProvider extends LabelProvider implements ITableLabelProvider { public String getColumnText(Object element, int columnIndex) { if (columnIndex == 0) { if (element != null) return getDataText(element); else return nullValueDispaly; } return null; } public Image getColumnImage(Object element, int columnIndex) { return null; } } private String getDataText(Object element) { if (element != null) { if (expectedColumnDataType == DataType.SQL_DATE_TYPE && element instanceof Date) { formatter.applyPattern("yyyy-MM-dd"); // $NON-NLS-1$ return formatter.format((Date) element); } else if (expectedColumnDataType == DataType.SQL_TIME_TYPE && element instanceof Date) { formatter.applyPattern("HH:mm:ss.SSS"); // $NON-NLS-1$ return formatter.format((Date) element); } else if (expectedColumnDataType == DataType.DATE_TYPE && element instanceof Date) { formatter.applyPattern("yyyy-MM-dd HH:mm:ss.SSS"); // $NON-NLS-1$ return formatter.format((Date) element); } // Because of fixed Timestamp format problem(T60058),add DataTypeUtil.toString(element ); // But this will make nunmber format has "," ,such as 10000 to be 10,000 // In SelectValueDialog ,it call DataTypeUtil.toLocaleNeutralString( element ) // So add follow code to call DataTypeUtil.toLocaleNeutralString( element ) else if (element instanceof Number) { try { return DataTypeUtil.toLocaleNeutralString(element); } catch (BirtException e) { return String.valueOf(element); } } else { try { return DataTypeUtil.toString(element); } catch (BirtException e) { return String.valueOf(element); } } } return null; } }
/** * Constructs an action for renaming resource. * * @param page the resource explorer page */ public RenameResourceAction(LibraryExplorerTreeViewPage page) { super(Messages.getString("RenameLibraryAction.Text"), page); // $NON-NLS-1$ setId(ActionFactory.RENAME.getId()); }
protected Control createContents(Composite parent) { UIUtil.bindHelp(parent, IHelpContextIds.PREFERENCE_BIRT_PREVIEW_DATA_ID); Composite cmpTop = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(1, false); cmpTop.setLayout(layout); GridData gd = new GridData(GridData.FILL_HORIZONTAL); cmpTop.setLayoutData(gd); createDispalyRowLimitGroup(cmpTop); txtMaxRowLevelMember = new IntegerFieldEditor( PREVIEW_MAX_ROW_LEVEL_MEMBER, Messages.getString( "designer.preview.preference.resultset.maxrowlevelmember.description"), cmpTop); //$NON-NLS-1$ txtMaxRowLevelMember.setPage(this); txtMaxRowLevelMember.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE); txtMaxRowLevelMember.setEmptyStringAllowed(false); txtMaxRowLevelMember.setPropertyChangeListener( new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(FieldEditor.IS_VALID)) setValid(txtMaxRowLevelMember.isValid()); } }); txtMaxColumnLevelMember = new IntegerFieldEditor( PREVIEW_MAX_COLUMN_LEVEL_MEMBER, Messages.getString( "designer.preview.preference.resultset.maxcolumnlevelmember.description"), cmpTop); //$NON-NLS-1$ txtMaxColumnLevelMember.setPage(this); txtMaxColumnLevelMember.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE); txtMaxColumnLevelMember.setEmptyStringAllowed(false); txtMaxColumnLevelMember.setPropertyChangeListener( new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(FieldEditor.IS_VALID)) setValid(txtMaxColumnLevelMember.isValid()); } }); txtMaxInMemoryCubeSize = new IntegerFieldEditor( PREVIEW_MAX_IN_MEMORY_CUBE_SIZE, Messages.getString( "designer.preview.preference.resultset.maxinmemorycubesize.description"), cmpTop); //$NON-NLS-1$ txtMaxInMemoryCubeSize.setPage(this); txtMaxInMemoryCubeSize.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE); txtMaxInMemoryCubeSize.setEmptyStringAllowed(false); txtMaxInMemoryCubeSize.setPropertyChangeListener( new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(FieldEditor.IS_VALID)) setValid(txtMaxInMemoryCubeSize.isValid()); } }); initControlValues(); return cmpTop; }
/* * (non-Javadoc) * * @see * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets * .Composite) */ protected Control createDialogArea(Composite parent) { UIUtil.bindHelp(parent, IHelpContextIds.RESOURCE_EDIT_DIALOG_ID); loadMessage(); final Composite innerParent = (Composite) super.createDialogArea(parent); final Table table = new Table(innerParent, SWT.BORDER | SWT.FULL_SELECTION); GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = 450; data.heightHint = 200; table.setLayoutData(data); table.setHeaderVisible(true); table.setLinesVisible(true); TableLayout tableLayout = new TableLayout(); table.setLayout(tableLayout); final TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText(Messages.getString("ResourceEditDialog.text.Key.TableColumn")); // $NON-NLS-1$ column1.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { table.setSortColumn(column1); viewer.setSorter(new ResourceSorter(table.getSortDirection() == SWT.UP, false)); table.setSortDirection(table.getSortDirection() == SWT.UP ? SWT.DOWN : SWT.UP); } }); final TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText(Messages.getString("ResourceEditDialog.text.Value.TableColumn")); // $NON-NLS-1$ column2.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { table.setSortColumn(column2); viewer.setSorter(new ResourceSorter(table.getSortDirection() == SWT.UP, true)); table.setSortDirection(table.getSortDirection() == SWT.UP ? SWT.DOWN : SWT.UP); } }); viewer = new TableViewer(table); viewer.setContentProvider( new IStructuredContentProvider() { public Object[] getElements(Object inputElement) { if (inputElement instanceof List) { List list = (List) inputElement; List availableList = new ArrayList(); for (int i = 0; i < list.size(); i++) { GlobalProperty property = (GlobalProperty) list.get(i); if (!property.isDeleted) availableList.add(property); } return availableList.toArray(); } return new Object[0]; } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} public void dispose() {} }); viewer.setLabelProvider(new PropertyLabelProvider()); viewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateSelection(); } }); TableLayout layout = new AutoResizeTableLayout(viewer.getTable()); layout.addColumnData(new ColumnWeightData(50, true)); layout.addColumnData(new ColumnWeightData(50, true)); viewer.getTable().setLayout(layout); // table.setSortColumn( column1 ); // table.setSortDirection( SWT.UP ); // viewer.setSorter( new ResourceSorter( false, false ) ); Group gp = new Group(innerParent, SWT.NONE); gp.setText(Messages.getString("ResourceEditDialog.text.QuickAdd")); // $NON-NLS-1$ gp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); gp.setLayout(new GridLayout(6, false)); Label lb = new Label(gp, 0); lb.setText(Messages.getString("ResourceEditDialog.text.Key")); // $NON-NLS-1$ keyText = new Text(gp, SWT.BORDER | SWT.SINGLE); keyText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); lb = new Label(gp, 0); lb.setText(Messages.getString("ResourceEditDialog.text.Value")); // $NON-NLS-1$ // lb = new Label( gp, 0 ); // lb = new Label( gp, 0 ); valueText = new Text(gp, SWT.BORDER | SWT.SINGLE); valueText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); btnAdd = new Button(gp, SWT.PUSH); btnAdd.setText(Messages.getString("ResourceEditDialog.text.Add")); // $NON-NLS-1$ btnAdd.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { addSelection(); } }); btnAdd.setEnabled(isFileSystemFile()); btnDelete = new Button(gp, SWT.PUSH); btnDelete.setText(Messages.getString("ResourceEditDialog.text.Delete")); // $NON-NLS-1$ btnDelete.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { deleteSelection(); } }); lb = new Label(innerParent, 0); lb.setText(Messages.getString("ResourceEditDialog.message.AddNote")); // $NON-NLS-1$ lb.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); viewer.setInput(globalLinkedProperties); return innerParent; }
/** * Creates the top level control for this dialog page under the given parent composite. * * <p>Implementors are responsible for ensuring that the created control can be accessed via * <code>getControl</code> * * @param parent the parent composite */ public void createControl(Composite parent) { helper = new DataSetBasePageHelper(); // initialize the dialog layout Composite composite = new Composite(parent, SWT.NULL); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout layout = new GridLayout(); composite.setLayout(layout); final Group group = new Group(composite, SWT.NONE); group.setLayout(new GridLayout()); group.setText(Messages.getString("DataSetBasePage.Group.DataSourceSelection")); // $NON-NLS-1$ group.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, true, 1, 8)); // GridData.FILL_BOTH)); wizardFilter = new WizardFilter(); dataSourceFilteredTree = new FilteredTree( group, SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL, this.wizardFilter, true); GridData treeData = new GridData(GridData.FILL_BOTH); treeData.grabExcessHorizontalSpace = true; treeData.grabExcessVerticalSpace = true; treeData.heightHint = 300; treeData.widthHint = 600; dataSourceFilteredTree.setLayoutData(treeData); SelectionListener listener = new SelectionListener() { TreeItem parent = null; public void widgetDefaultSelected(SelectionEvent arg0) {} public void widgetSelected(SelectionEvent event) { if (event.item.getData() instanceof DataSourceHandle) { dataSetTypeChooser.getCombo().setEnabled(true); if (parent == null || parent != ((TreeItem) event.item).getParentItem()) { parent = ((TreeItem) event.item).getParentItem(); doDataSourceSelectionChanged(parent.getData()); } setPageComplete(!hasWizard() && (getMessageType() != ERROR)); } else { dataSetTypeChooser.getCombo().clearSelection(); dataSetTypeChooser.getCombo().setEnabled(false); setPageComplete(false); } dataSourceFilteredTree.getViewer().getTree().setFocus(); } }; dataSourceFilteredTree.getViewer().getTree().addSelectionListener(listener); createDataSetTypeViewer(composite); setDataSourceTreeViewer(); setPageStatus(); // initialize name editor new Label(composite, SWT.RIGHT) .setText(Messages.getString("dataset.wizard.label.datasetName")); // $NON-NLS-1$ nameEditor = new Text(composite, SWT.BORDER); String name = ReportPlugin.getDefault().getCustomName(ReportDesignConstants.DATA_SET_ELEMENT); if (name != null) { nameEditor.setText(Utility.getUniqueDataSetName(name)); } else // can't get defaut name { nameEditor.setText( Utility.getUniqueDataSetName( Messages.getString("dataset.new.defaultName"))); // $NON-NLS-1$ } nameEditor.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); nameEditor.setToolTipText(Messages.getString("DataSetBasePage.tooltip")); // $NON-NLS-1$ nameEditor.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { if (StringUtil.isBlank(nameEditor.getText().trim())) { setMessage(EMPTY_NAME, ERROR); } else if (isDuplicateName()) { // name is duplicated setMessage(DUPLICATE_NAME, ERROR); } else if (containInvalidCharactor( nameEditor.getText())) { // name contains invalid ".", "/", "\", "!", ";", "," // character String msg = Messages.getFormattedString( "error.invalidName", //$NON-NLS-1$ new Object[] {nameEditor.getText()}); setMessage(msg, ERROR); } else { // everything is OK setMessage(CREATE_PROMPT); } setPageComplete( !hasWizard() && (getMessageType() != ERROR) && getSelectedDataSource() != null); nameEditor.setFocus(); } }); setControl(composite); Utility.setSystemHelp(getControl(), IHelpConstants.CONEXT_ID_DATASET_NEW); }
/** * Constructs a action for adding resource. * * @param viewer the resource explorer page */ public AddResourceAction(LibraryExplorerTreeViewPage viewer) { super(Messages.getString("AddResourceAction.Text"), viewer); // $NON-NLS-1$ }