Search in sources :

Example 6 with TableEntity

use of com.microsoft.tooling.msservices.model.storage.TableEntity in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method getTableEntity.

@NotNull
private static TableEntity getTableEntity(@NotNull String tableName, @NotNull DynamicTableEntity dte) {
    String partitionKey = Strings.nullToEmpty(dte.getPartitionKey());
    String rowKey = Strings.nullToEmpty(dte.getRowKey());
    String eTag = Strings.nullToEmpty(dte.getEtag());
    Calendar timestamp = new GregorianCalendar();
    if (dte.getTimestamp() != null) {
        timestamp.setTime(dte.getTimestamp());
    }
    Map<String, Property> properties = new HashMap<String, Property>();
    if (dte.getProperties() != null) {
        for (Entry<String, EntityProperty> entry : dte.getProperties().entrySet()) {
            if (entry.getKey() != null && entry.getValue() != null) {
                String key = entry.getKey();
                Property property;
                switch(entry.getValue().getEdmType()) {
                    case BOOLEAN:
                        property = new Property(entry.getValue().getValueAsBooleanObject());
                        break;
                    case DATE_TIME:
                        Calendar value = new GregorianCalendar();
                        value.setTime(entry.getValue().getValueAsDate());
                        property = new Property(value);
                        break;
                    case DOUBLE:
                        property = new Property(entry.getValue().getValueAsDoubleObject());
                        break;
                    case GUID:
                        property = new Property(entry.getValue().getValueAsUUID());
                        break;
                    case INT32:
                        property = new Property(entry.getValue().getValueAsIntegerObject());
                        break;
                    case INT64:
                        property = new Property(entry.getValue().getValueAsLongObject());
                        break;
                    case STRING:
                        property = new Property(entry.getValue().getValueAsString());
                        break;
                    default:
                        property = new Property(entry.getValue().getValueAsString());
                        break;
                }
                properties.put(key, property);
            }
        }
    }
    return new TableEntity(partitionKey, rowKey, tableName, eTag, timestamp, properties);
}
Also used : TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity) Property(com.microsoft.tooling.msservices.model.storage.TableEntity.Property) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 7 with TableEntity

use of com.microsoft.tooling.msservices.model.storage.TableEntity in project azure-tools-for-java by Microsoft.

the class TableFileEditor method editEntity.

private void editEntity() {
    TableEntity[] selectedEntities = getSelectedEntities();
    if (selectedEntities != null && selectedEntities.length > 0) {
        final TableEntity selectedEntity = selectedEntities[0];
        final TableEntityForm form = new TableEntityForm(project);
        form.setTableName(table.getName());
        form.setStorageAccount(storageAccount);
        form.setTableEntity(selectedEntity);
        form.setTitle("Edit Entity");
        form.setOnFinish(new Runnable() {

            @Override
            public void run() {
                tableEntities.set(entitiesTable.getSelectedRow(), form.getTableEntity());
                refreshGrid();
            }
        });
        form.show();
    }
}
Also used : TableEntityForm(com.microsoft.intellij.forms.TableEntityForm) TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity)

Example 8 with TableEntity

use of com.microsoft.tooling.msservices.model.storage.TableEntity in project azure-tools-for-java by Microsoft.

the class TableFileEditor method getSelectedEntities.

private TableEntity[] getSelectedEntities() {
    if (tableEntities == null) {
        return null;
    }
    int partitionIdIndex = -1;
    int rowIdIndex = -1;
    for (int i = 0; i < entitiesTable.getColumnCount(); i++) {
        String columnName = entitiesTable.getColumnName(i);
        if (columnName.equals(PARTITION_KEY)) {
            partitionIdIndex = i;
        }
        if (columnName.equals(ROW_KEY)) {
            rowIdIndex = i;
        }
    }
    ArrayList<TableEntity> selectedEntities = new ArrayList<TableEntity>();
    for (int i : entitiesTable.getSelectedRows()) {
        for (TableEntity tableEntity : tableEntities) {
            String partitionValue = entitiesTable.getValueAt(i, partitionIdIndex).toString();
            String rowIdValue = entitiesTable.getValueAt(i, rowIdIndex).toString();
            if (tableEntity.getPartitionKey().equals(partitionValue) && tableEntity.getRowKey().equals(rowIdValue)) {
                selectedEntities.add(tableEntity);
            }
        }
    }
    return selectedEntities.toArray(new TableEntity[selectedEntities.size()]);
}
Also used : ArrayList(java.util.ArrayList) TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity)

Aggregations

TableEntity (com.microsoft.tooling.msservices.model.storage.TableEntity)8 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)2 DefaultTableModel (javax.swing.table.DefaultTableModel)2 TableModel (javax.swing.table.TableModel)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)1 TableEntityForm (com.microsoft.azuretools.azureexplorer.forms.TableEntityForm)1 TableEntityForm (com.microsoft.intellij.forms.TableEntityForm)1 Property (com.microsoft.tooling.msservices.model.storage.TableEntity.Property)1 ArrayList (java.util.ArrayList)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 Nullable (org.jetbrains.annotations.Nullable)1