Exemplo n.º 1
0
  @Override
  protected String[] resolveAll(final TemplateContext context) {
    final DBCExecutionContext executionContext =
        ((DBPContextProvider) context).getExecutionContext();
    if (executionContext == null) {
      return super.resolveAll(context);
    }

    TemplateVariable tableVariable = ((SQLContext) context).getTemplateVariable("table");
    final String tableName = tableVariable == null ? null : tableVariable.getDefaultValue();
    if (!CommonUtils.isEmpty(tableName)) {
      final List<DBSEntityAttribute> attributes = new ArrayList<>();
      DBRRunnableWithProgress runnable =
          new DBRRunnableWithProgress() {
            @Override
            public void run(DBRProgressMonitor monitor)
                throws InvocationTargetException, InterruptedException {
              try {
                List<DBSEntity> entities = new ArrayList<>();
                SQLEntityResolver.resolveTables(monitor, executionContext, context, entities);
                if (!CommonUtils.isEmpty(entities)) {
                  DBSEntity table = DBUtils.findObject(entities, tableName);
                  if (table != null) {
                    attributes.addAll(CommonUtils.safeCollection(table.getAttributes(monitor)));
                  }
                }
              } catch (DBException e) {
                throw new InvocationTargetException(e);
              }
            }
          };
      RuntimeUtils.runTask(runnable, "Resolve attributes", 1000);
      if (!CommonUtils.isEmpty(attributes)) {
        String[] result = new String[attributes.size()];
        for (int i = 0; i < attributes.size(); i++) {
          DBSEntityAttribute entity = attributes.get(i);
          result[i] = entity.getName();
        }
        return result;
      }
    }
    return super.resolveAll(context);
  }
Exemplo n.º 2
0
  @Override
  protected Control createPageContents(Composite parent) {
    Composite propsGroup = new Composite(parent, SWT.NONE);
    propsGroup.setLayout(new GridLayout(2, false));
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    propsGroup.setLayoutData(gd);

    final Text nameText =
        UIUtils.createLabelText(propsGroup, "Name", attribute.getName()); // $NON-NLS-2$
    nameText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            if (attribute instanceof DBPNamedObject2) {
              ((DBPNamedObject2) attribute).setName(nameText.getText());
            }
          }
        });

    UIUtils.createControlLabel(propsGroup, "Properties")
        .setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    PropertyTreeViewer propertyViewer = new PropertyTreeViewer(propsGroup, SWT.BORDER);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    propertyViewer.getControl().setLayoutData(gd);
    propertyViewer.addFilter(
        new ViewerFilter() {
          @Override
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            return true;
          }
        });

    PropertySourceAbstract pc = new PropertySourceEditable(commandContext, attribute, attribute);
    pc.collectProperties();
    for (DBPPropertyDescriptor prop : pc.getProperties()) {
      if (prop instanceof ObjectPropertyDescriptor) {
        if (((ObjectPropertyDescriptor) prop).isEditPossible()
            && !prop.getId().equals(DBConstants.PROP_ID_NAME)) {
          continue;
        }
      }
      pc.removeProperty(prop);
    }
    propertyViewer.loadProperties(pc);

    return propsGroup;
  }