public AuthenticatorWindow() { SESecurityManager.addPasswordListener(this); // System.out.println( "AuthenticatorWindow"); Map cache = COConfigurationManager.getMapParameter(CONFIG_PARAM, new HashMap()); try { Iterator it = cache.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); String key = (String) entry.getKey(); Map value = (Map) entry.getValue(); String user = new String((byte[]) value.get("user"), "UTF-8"); char[] pw = new String((byte[]) value.get("pw"), "UTF-8").toCharArray(); auth_cache.put(key, new authCache(key, new PasswordAuthentication(user, pw), true)); } } catch (Throwable e) { COConfigurationManager.setParameter(CONFIG_PARAM, new HashMap()); Debug.printStackTrace(e); } }
void createCommand(String commandId, Map parameters) { if (commandId == null) { WorkbenchPlugin.log( "Unable to create menu item \"" + getId() //$NON-NLS-1$ + "\", no command id"); //$NON-NLS-1$ return; } Command cmd = commandService.getCommand(commandId); if (!cmd.isDefined()) { WorkbenchPlugin.log( "Unable to create menu item \"" + getId() //$NON-NLS-1$ + "\", command \"" + commandId + "\" not defined"); //$NON-NLS-1$ //$NON-NLS-2$ return; } if (parameters == null || parameters.size() == 0) { command = new ParameterizedCommand(cmd, null); return; } try { ArrayList parmList = new ArrayList(); Iterator i = parameters.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); String parmName = (String) entry.getKey(); IParameter parm; parm = cmd.getParameter(parmName); if (parm == null) { WorkbenchPlugin.log( "Unable to create menu item \"" + getId() //$NON-NLS-1$ + "\", parameter \"" + parmName + "\" for command \"" //$NON-NLS-1$ //$NON-NLS-2$ + commandId + "\" is not defined"); //$NON-NLS-1$ return; } parmList.add(new Parameterization(parm, (String) entry.getValue())); } command = new ParameterizedCommand( cmd, (Parameterization[]) parmList.toArray(new Parameterization[parmList.size()])); } catch (NotDefinedException e) { // this shouldn't happen as we checked for !defined, but we // won't take the chance WorkbenchPlugin.log( "Failed to create menu item " //$NON-NLS-1$ + getId(), e); } }
/** Create internal GUI. */ private void createComponents(Map<String, Object> currentValues) { /* * Sort alphabetically by label. */ final Locale locale = Locale.getDefault(); final Map<String, String> labels = Maps.newHashMap(); for (Map.Entry<String, AttributeDescriptor> entry : attributeDescriptors.entrySet()) { labels.put(entry.getKey(), getLabel(entry.getValue()).toLowerCase(locale)); } final Collator collator = Collator.getInstance(locale); final List<String> sortedKeys = Lists.newArrayList(labels.keySet()); Collections.sort( sortedKeys, new Comparator<String>() { public int compare(String a, String b) { return collator.compare(labels.get(a), labels.get(b)); } }); /* * Create editors and inquire about their layout needs. */ editors = Maps.newHashMap(); final Map<String, AttributeEditorInfo> editorInfos = Maps.newHashMap(); int maxColumns = 1; for (String key : sortedKeys) { final AttributeDescriptor descriptor = attributeDescriptors.get(key); IAttributeEditor editor = null; try { editor = EditorFactory.getEditorFor(this.componentClazz, descriptor); final AttributeEditorInfo info = editor.init(bindable, descriptor, globalEventsProvider, currentValues); editorInfos.put(key, info); maxColumns = Math.max(maxColumns, info.columns); } catch (EditorNotFoundException ex) { Utils.logError( "No editor for attribute: " + descriptor.key + " (class: " + descriptor.type + ")", false); /* * Skip editor. */ editor = null; } editors.put(key, editor); } /* * Prepare the layout for this editor. */ final GridLayout layout = GUIFactory.zeroMarginGridLayout(); layout.makeColumnsEqualWidth = false; layout.numColumns = maxColumns; this.setLayout(layout); /* * Create visual components for editors. */ final GridDataFactory labelFactory = GridDataFactory.fillDefaults().span(maxColumns, 1); boolean firstEditor = true; for (String key : sortedKeys) { final AttributeDescriptor descriptor = attributeDescriptors.get(key); final IAttributeEditor editor = editors.get(key); final AttributeEditorInfo editorInfo = editorInfos.get(key); if (editor == null) { // Skip attributes without the editor. continue; } final Object defaultValue; if (currentValues != null && currentValues.get(key) != null) { defaultValue = currentValues.get(key); } else { defaultValue = attributeDescriptors.get(key).defaultValue; } // Add label to editors that do not have it. if (!editorInfo.displaysOwnLabel) { final Label label = new Label(this, SWT.LEAD); final GridData gd = labelFactory.create(); if (!firstEditor) { gd.verticalIndent = SPACE_BEFORE_LABEL; } label.setLayoutData(gd); label.setText(getLabel(descriptor) + (descriptor.requiredAttribute ? " (required)" : "")); /* * Add validation overlay. */ addValidationOverlay(descriptor, editor, defaultValue, label); AttributeInfoTooltip.attach(label, descriptor); } // Add the editor, if available. editor.createEditor(this, maxColumns); // Set the default value for the editor. editor.setValue(defaultValue); editors.put(editor.getAttributeKey(), editor); /* * Forward events from this editor to all our listeners. */ editor.addAttributeListener(forwardListener); firstEditor = false; } }