diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GenericTableRowColumnDefinition.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GenericTableRowColumnDefinition.java new file mode 100644 index 0000000000000000000000000000000000000000..ad1ea74b0bbcf9c7b348adc54d2d932e93a1b232 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GenericTableRowColumnDefinition.java @@ -0,0 +1,78 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific; + +import ch.systemsx.cisd.openbis.generic.shared.basic.GridRowModel; +import ch.systemsx.cisd.openbis.generic.shared.basic.IColumnDefinition; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableColumnHeader; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableRow; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ISerializableComparable; + +/** + * @author Franz-Josef Elmer + */ +public class GenericTableRowColumnDefinition implements IColumnDefinition<GenericTableRow> +{ + private GenericTableColumnHeader header; + + private String title; + + public GenericTableRowColumnDefinition(GenericTableColumnHeader header, String title) + { + this.header = header; + this.title = title; + } + + // GWT only + @SuppressWarnings("unused") + private GenericTableRowColumnDefinition() + { + this(null, null); + } + + public Comparable<?> getComparableValue(GridRowModel<GenericTableRow> rowModel) + { + return getCellValue(rowModel); + } + + public String getHeader() + { + return title; + } + + public String getIdentifier() + { + return header.getCode(); + } + + public String getValue(GridRowModel<GenericTableRow> rowModel) + { + ISerializableComparable value = getCellValue(rowModel); + return value == null ? "" : value.toString(); + } + + private ISerializableComparable getCellValue(GridRowModel<GenericTableRow> rowModel) + { + return rowModel.getOriginalObject().tryToGetValue(header.getIndex()); + } + + public String tryToGetProperty(String key) + { + return null; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableBrowserGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableBrowserGrid.java new file mode 100644 index 0000000000000000000000000000000000000000..305efda124b212081831b263f05aaa1e164655b3 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableBrowserGrid.java @@ -0,0 +1,160 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.IDisplayTypeIDGenerator; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.BaseEntityModel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.IColumnDefinitionUI; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.GenericTableResultSet; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.IResultSetConfig; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet; +import ch.systemsx.cisd.openbis.generic.shared.basic.GridRowModel; +import ch.systemsx.cisd.openbis.generic.shared.basic.IColumnDefinition; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableColumnHeader; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableRow; + +/** + * + * + * @author Franz-Josef Elmer + */ +public abstract class GenericTableBrowserGrid + extends AbstractBrowserGrid<GenericTableRow, BaseEntityModel<GenericTableRow>> +{ + private static final String BROWSER_ID_PATTERN = "[a-z0-9_]*"; + + private List<GenericTableColumnHeader> headers; + + protected GenericTableBrowserGrid(IViewContext<ICommonClientServiceAsync> viewContext, + String browserId, String gridId, boolean showHeader, boolean refreshAutomatically, + IDisplayTypeIDGenerator displayTypeIDGenerator) + { + super(viewContext, gridId, showHeader, refreshAutomatically, displayTypeIDGenerator); + if (browserId.matches(BROWSER_ID_PATTERN) == false) + { + throw new IllegalArgumentException("Invalid browser ID: " + browserId); + } + setId(browserId); + } + + /** + * Lists table rows. Implementations of this method usually call a server method. + */ + protected abstract void listTableRows( + IResultSetConfig<String, GenericTableRow> resultSetConfig, + AsyncCallback<GenericTableResultSet> callback); + + @Override + protected ColumnDefsAndConfigs<GenericTableRow> createColumnsDefinition() + { + return ColumnDefsAndConfigs.create(createColDefinitions()); + } + + @Override + protected BaseEntityModel<GenericTableRow> createModel(GridRowModel<GenericTableRow> entity) + { + return new BaseEntityModel<GenericTableRow>(entity, createColDefinitions()); + } + + private List<IColumnDefinitionUI<GenericTableRow>> createColDefinitions() + { + List<IColumnDefinitionUI<GenericTableRow>> list = new ArrayList<IColumnDefinitionUI<GenericTableRow>>(); + if (headers != null) + { + for (final GenericTableColumnHeader header : headers) + { + String title = header.getTitle(); + if (title == null) + { + title = viewContext.getMessage(getId() + "_" + header.getCode()); + } + list.add(new GenericTableRowColumnDefinitionUI(header, title)); + } + } + return list; + } + + @Override + protected void listEntities(DefaultResultSetConfig<String, GenericTableRow> resultSetConfig, + final AbstractAsyncCallback<ResultSet<GenericTableRow>> callback) + { + AbstractAsyncCallback<GenericTableResultSet> extendedCallback = + new AbstractAsyncCallback<GenericTableResultSet>(viewContext) + { + @Override + protected void process(GenericTableResultSet result) + { + headers = result.getHeaders(); + callback.onSuccess(result.getResultSet()); + refreshColumnsSettingsIfNecessary(); + } + + @Override + public void finishOnFailure(Throwable caught) + { + callback.finishOnFailure(caught); + } + }; + listTableRows(resultSetConfig, extendedCallback); + } + + @Override + protected boolean isRefreshEnabled() + { + return true; + } + + protected void refreshColumnsSettingsIfNecessary() + { + } + + @Override + protected void refresh() + { + refresh(false); + } + + public void update(Set<DatabaseModificationKind> observedModifications) + { + refreshGridSilently(); + } + + @Override + protected void showEntityViewer(GenericTableRow entity, boolean editMode) + { + } + + @Override + protected List<IColumnDefinition<GenericTableRow>> getInitialFilters() + { + return Collections.emptyList(); + } + +} + diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableRowColumnDefinitionUI.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableRowColumnDefinitionUI.java new file mode 100644 index 0000000000000000000000000000000000000000..31a468a4c46ddfe7390f397fab6409f99e0136b7 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableRowColumnDefinitionUI.java @@ -0,0 +1,54 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.IColumnDefinitionUI; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.GenericTableRowColumnDefinition; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableColumnHeader; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableRow; + +public class GenericTableRowColumnDefinitionUI extends GenericTableRowColumnDefinition implements + IColumnDefinitionUI<GenericTableRow> +{ + public GenericTableRowColumnDefinitionUI(GenericTableColumnHeader header, String title) + { + super(header, title); + } + + // GWT only + @SuppressWarnings("unused") + private GenericTableRowColumnDefinitionUI() + { + this(null, null); + } + + public int getWidth() + { + return 100; + } + + public boolean isHidden() + { + return false; + } + + public boolean isNumeric() + { + return false; + } + +} \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/GenericTableResultSet.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/GenericTableResultSet.java new file mode 100644 index 0000000000000000000000000000000000000000..7f0cf0680ac1b95839c4cc3b65e14da139f2e3d6 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/GenericTableResultSet.java @@ -0,0 +1,59 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.client.web.client.dto; + +import java.util.List; + +import com.google.gwt.user.client.rpc.IsSerializable; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableColumnHeader; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableRow; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class GenericTableResultSet implements IsSerializable +{ + private ResultSet<GenericTableRow> resultSet; + private List<GenericTableColumnHeader> headers; + + public GenericTableResultSet(ResultSet<GenericTableRow> resultSet, List<GenericTableColumnHeader> headers) + { + this.resultSet = resultSet; + this.headers = headers; + } + + // GWT only + @SuppressWarnings("unused") + private GenericTableResultSet() + { + } + + public ResultSet<GenericTableRow> getResultSet() + { + return resultSet; + } + + public List<GenericTableColumnHeader> getHeaders() + { + return headers; + } + + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/util/DataTypeUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/util/DataTypeUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..adf626ff6874b55951f37c1b6e0940122f0e8f2d --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/util/DataTypeUtils.java @@ -0,0 +1,130 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.client.web.server.util; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; + +import com.google.gwt.user.client.rpc.IsSerializable; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DoubleTableCell; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ISerializableComparable; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IntegerTableCell; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.StringTableCell; + +/** + * Utility functions around data types. + * + * @author Franz-Josef Elmer + */ +public class DataTypeUtils +{ + private static final Map<DataTypeCode, Converter> map = new HashMap<DataTypeCode, Converter>(); + + private enum Converter implements IsSerializable + { + + INTEGER(DataTypeCode.INTEGER){ + @Override + public ISerializableComparable doConvertion(String value) + { + long number; + try + { + number = Long.parseLong(value); + } catch (NumberFormatException ex) + { + throw new IllegalArgumentException("Is not an integer number: " + value); + } + return new IntegerTableCell(number); + } + }, + DOUBLE(DataTypeCode.REAL){ + @Override + public ISerializableComparable doConvertion(String value) + { + double number; + try + { + number = Double.parseDouble(value); + } catch (NumberFormatException ex) + { + throw new IllegalArgumentException("Is not a floating point number: " + value); + } + return new DoubleTableCell(number); + } + }, + DATE(DataTypeCode.TIMESTAMP){ + @Override + public ISerializableComparable doConvertion(String value) + { + return new StringTableCell(value); + } + }, + STRING(DataTypeCode.VARCHAR, DataTypeCode.MULTILINE_VARCHAR, DataTypeCode.BOOLEAN, + DataTypeCode.CONTROLLEDVOCABULARY, DataTypeCode.MATERIAL, DataTypeCode.HYPERLINK) + { + @Override + public ISerializableComparable doConvertion(String value) + { + return new StringTableCell(value); + } + }, + ; + + private static final StringTableCell EMPTY_CELL = new StringTableCell(""); + + private Converter(DataTypeCode... codes) + { + for (DataTypeCode dataTypeCode : codes) + { + map.put(dataTypeCode, this); + } + } + + public static Converter resolve(DataTypeCode dataTypeCode) + { + return map.get(dataTypeCode); + } + + public ISerializableComparable convert(String value) + { + if (StringUtils.isBlank(value)) + { + return EMPTY_CELL ; + } + return doConvertion(value); + } + public abstract ISerializableComparable doConvertion(String value); + } + + /** + * Converts the specified string value into a data value in accordance with specified + * data type. + */ + public static ISerializableComparable convertTo(DataTypeCode dataTypeCode, String value) + { + return Converter.resolve(dataTypeCode).convert(value); + } + + private DataTypeUtils() + { + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServerLogger.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServerLogger.java index b8ff35b341d00c2630cc0aa7f4dbc892d21cd8af..61f4fca6217aa15aae66b70577d55be640be79ac 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServerLogger.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/AbstractServerLogger.java @@ -69,6 +69,10 @@ public abstract class AbstractServerLogger implements IServer protected final void logAccess(final String sessionToken, final String commandName) { + long freeMemory = Runtime.getRuntime().freeMemory(); + long totalMemory = Runtime.getRuntime().totalMemory(); + System.out.println("MEMORY: " + (totalMemory - freeMemory) / 1024 / 1024 + " of " + totalMemory + / 1024 / 1024 + " used " + commandName); logAccess(sessionToken, commandName, ""); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableColumnHeader.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableColumnHeader.java new file mode 100644 index 0000000000000000000000000000000000000000..b3007c1bac821655f953a6ab4263e981cfc0bd9c --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableColumnHeader.java @@ -0,0 +1,90 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.shared.basic.dto; + +import java.io.Serializable; + +import com.google.gwt.user.client.rpc.IsSerializable; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class GenericTableColumnHeader implements Serializable, IsSerializable +{ + private static final long serialVersionUID = ServiceVersionHolder.VERSION; + + public static GenericTableColumnHeader untitledStringHeader(int identifier, String code) + { + GenericTableColumnHeader header = new GenericTableColumnHeader(); + header.setIndex(identifier); + header.setCode(code); + header.setType(DataTypeCode.VARCHAR); + return header; + } + + private String title; + + private int index; + + private String code; + + private DataTypeCode type; + + public String getTitle() + { + return title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public int getIndex() + { + return index; + } + + public void setIndex(int index) + { + this.index = index; + } + + public void setCode(String code) + { + this.code = code; + } + + public String getCode() + { + return code; + } + + public DataTypeCode getType() + { + return type; + } + + public void setType(DataTypeCode type) + { + this.type = type; + } + + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableRow.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableRow.java new file mode 100644 index 0000000000000000000000000000000000000000..16c4699e6ebfd74f7df45c4489426cbc96b46027 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableRow.java @@ -0,0 +1,50 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.shared.basic.dto; + +import java.io.Serializable; + +import com.google.gwt.user.client.rpc.IsSerializable; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class GenericTableRow implements Serializable, IsSerializable +{ + private static final long serialVersionUID = ServiceVersionHolder.VERSION; + + private ISerializableComparable[] cells; + + public GenericTableRow(ISerializableComparable... cells) + { + this.cells = cells; + } + + public ISerializableComparable tryToGetValue(int columnID) + { + return cells[columnID]; + } + + // GWT only + @SuppressWarnings("unused") + private GenericTableRow() + { + } + +}