/** * Sets values for a property in a certain ODocument * * @param propertyName the property name * @param values the values for the property * @param document the document which should contain the data */ protected void setPropertyInternal(ODocument document, QName propertyName, Object... values) { String pName = encodeProperty(propertyName); if (values == null || values.length == 0) { document.removeField(pName); return; } boolean collection = isCollectionProperty(propertyName); if (!collection) { if (values.length > 1) { // TODO log type and property log.warn( "Attempt to set multiple values on a property that supports only one, using only the first value"); } document.field(pName, convertInstance(values[0])); } else { List<Object> valueList = new ArrayList<Object>(); for (Object value : values) { valueList.add(convertInstance(value)); } document.field(pName, valueList, getCollectionType(propertyName)); } }
@SuppressWarnings("unchecked") @Override protected DefinedAnnotation create(String id, IConfigurationElement conf) { try { return new DefinedAnnotation( id, (Class<AnnotationDescriptor<?>>) ExtensionUtil.loadClass(conf, "descriptor")); } catch (Exception e) { log.error("Could not load annotation descriptor for type identifier " + id, e); return null; } }
/** Set the actions icon as {@link ImageDescriptor} if possible */ private void loadImage() { Object icon = action.getValue(javax.swing.Action.SMALL_ICON); if (icon instanceof ImageIcon) { try { setImageDescriptor( ImageDescriptor.createFromImageData(SwingRcpUtilities.convertToSWT((ImageIcon) icon))); } catch (Exception e) { _log.warn("Error converting action icon", e); // $NON-NLS-1$ } } }
@Override public ActionUIAdvisor<?> getUIAdvisor() { if (!advisorInitialized) { try { if (conf.getAttribute("ui-advisor") != null) { Class<?> advisorClass = ExtensionUtil.loadClass(conf, "ui-advisor"); actionAdvisor = (ActionUIAdvisor<?>) advisorClass.newInstance(); } } catch (Exception e) { log.error("Failed to created action UI advisor instance", e); } advisorInitialized = true; } return actionAdvisor; }
/** @see ActionUI#getEnabledWhen() */ @Override public Expression getEnabledWhen() { IConfigurationElement[] children = conf.getChildren("enabledWhen"); if (children != null && children.length > 0) { // get child of enabled when children = children[0].getChildren(); if (children != null && children.length > 0) { try { return ElementHandler.getDefault() .create(ExpressionConverter.getDefault(), children[0]); } catch (CoreException e) { log.error("Could not evaluate expression for action enablement.", e); } } } return null; }
@Override public void addBaseAlignment( String prefix, URI alignment, Iterable<BaseAlignmentCell> cells, Iterable<CustomPropertyFunction> baseFunctions) { if (baseAlignments.containsValue(alignment)) throw new IllegalArgumentException("base alignment " + alignment + " already included"); if (baseAlignments.containsKey(prefix)) throw new IllegalArgumentException("prefix " + prefix + " already in use."); baseAlignments.put(prefix, alignment); for (BaseAlignmentCell cell : cells) { internalAdd(cell); } for (CustomPropertyFunction function : baseFunctions) { if (idToBaseFunction.put(function.getDescriptor().getId(), function) != null) { log.error( MessageFormat.format( "Function with identifier {0} defined multiple times in base alignments", function.getDescriptor().getId())); } } }
@Override protected void addControls() { StringValue idParam = getPageParameters().get(0); if (!idParam.isNull() && !idParam.isEmpty()) { String templateId = idParam.toString(); OrientGraph graph = DatabaseHelper.getGraph(); try { Template template = null; try { template = Template.getByTemplateId(graph, templateId); } catch (NonUniqueResultException e) { log.error("Duplicate template representation: " + templateId, e); } if (template != null) { // get associated user Vertex v = template.getV(); Iterator<Vertex> owners = v.getVertices(Direction.OUT, "owner").iterator(); if (UserUtil.isAdmin() // user is admin // or user is owner || (owners.hasNext() && UserUtil.getLogin().equals(new User(owners.next(), graph).getLogin()))) { add(new TemplateForm("edit-form", false, templateId)); } else { throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_FORBIDDEN); } } else { throw new AbortWithHttpErrorCodeException( HttpServletResponse.SC_NOT_FOUND, "Template not found."); } } finally { graph.shutdown(); } } else throw new AbortWithHttpErrorCodeException( HttpServletResponse.SC_BAD_REQUEST, "Template identifier must be specified."); }
/** * @see Wizard#performFinish() * @return <code>true</code> if executing the I/O provider was successful */ @Override public boolean performFinish() { if (getProvider() == null) { return false; } if (!applyConfiguration()) { return false; } // create default report IOReporter defReport = provider.createReporter(); // validate and execute provider try { // validate configuration provider.validate(); ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class); URI projectLoc = ps.getLoadLocation() == null ? null : ps.getLoadLocation(); boolean isProjectResource = false; if (actionId != null) { // XXX instead move project resource to action? ActionUI factory = ActionUIExtension.getInstance().findActionUI(actionId); isProjectResource = factory.isProjectResource(); } // prevent loading of duplicate resources if (isProjectResource && provider instanceof ImportProvider) { String currentResource = ((ImportProvider) provider).getSource().getLocation().toString(); URI currentAbsolute = URI.create(currentResource); if (projectLoc != null && !currentAbsolute.isAbsolute()) currentAbsolute = projectLoc.resolve(currentAbsolute); for (IOConfiguration conf : ((Project) ps.getProjectInfo()).getResources()) { Value otherResourceValue = conf.getProviderConfiguration().get(ImportProvider.PARAM_SOURCE); if (otherResourceValue == null) continue; String otherResource = otherResourceValue.as(String.class); URI otherAbsolute = URI.create(otherResource); if (projectLoc != null && !otherAbsolute.isAbsolute()) otherAbsolute = projectLoc.resolve(otherAbsolute); String action = conf.getActionId(); // resource is already loaded into the project if (currentAbsolute.equals(otherAbsolute) && Objects.equal(actionId, action)) { log.userError("Resource is already loaded. Loading duplicate resources is aborted!"); return false; } } } // enable provider internal caching if (isProjectResource && provider instanceof CachingImportProvider) { ((CachingImportProvider) provider).setProvideCache(); } IOReport report = execute(provider, defReport); if (report != null) { // add report to report server ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class); repService.addReport(report); // show message to user if (report.isSuccess()) { // no message, we rely on the report being shown/processed // let advisor handle results try { getContainer() .run( true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Completing operation...", IProgressMonitor.UNKNOWN); try { advisor.handleResults(getProvider()); } finally { monitor.done(); } } }); } catch (InvocationTargetException e) { log.userError( "Error processing results:\n" + e.getCause().getLocalizedMessage(), e.getCause()); return false; } catch (Exception e) { log.userError("Error processing results:\n" + e.getLocalizedMessage(), e); return false; } // add to project service if necessary if (isProjectResource) ps.rememberIO(actionId, getProviderFactory().getIdentifier(), provider); return true; } else { // error message log.userError(report.getSummary() + "\nPlease see the report for details."); return false; } } else return true; } catch (IOProviderConfigurationException e) { // user feedback log.userError( "Validation of the provider configuration failed:\n" + e.getLocalizedMessage(), e); return false; } }