/// <summary> /// Displays the given Graph /// </summary> /// <param name="g">Graph to display</param> public GraphViewerForm(IGraph g) { InitializeComponent(); if (Constants.WindowIcon != null) { this.Icon = Constants.WindowIcon; } //Load Formatters List <INodeFormatter> formatters = new List <INodeFormatter>(); Type targetType = typeof(INodeFormatter); foreach (Type t in Assembly.GetAssembly(targetType).GetTypes()) { if (t.Namespace == null) { continue; } if (t.Namespace.Equals("VDS.RDF.Writing.Formatting")) { if (t.GetInterfaces().Contains(targetType)) { try { INodeFormatter formatter = (INodeFormatter)Activator.CreateInstance(t); formatters.Add(formatter); if (formatter.GetType().Equals(this._formatter.GetType())) { this._formatter = formatter; } } catch { //Ignore this Formatter } } } } formatters.Sort(new ToStringComparer <INodeFormatter>()); this.cboFormat.DataSource = formatters; this.cboFormat.SelectedItem = this._formatter; this.cboFormat.SelectedIndexChanged += new System.EventHandler(this.cboFormat_SelectedIndexChanged); this.dgvTriples.CellFormatting += new DataGridViewCellFormattingEventHandler(dgvTriples_CellFormatting); this.dgvTriples.CellContentClick += new DataGridViewCellEventHandler(dgvTriples_CellClick); if (g.BaseUri != null) { this.lnkBaseURI.Text = g.BaseUri.ToString(); } this._g = g; this.Text = String.Format("Graph Viewer - {0} Triple(s)", g.Triples.Count); }
private void cboFormat_SelectedIndexChanged(object sender, EventArgs e) { if (this.cboFormat.SelectedItem != null) { INodeFormatter formatter = this.cboFormat.SelectedItem as INodeFormatter; if (formatter != null) { INodeFormatter currFormatter = this._formatter; Type t = formatter.GetType(); if (this._nsmap != null) { Type nsmapType = typeof(INamespaceMapper); if (t.GetConstructors().Any(c => c.IsPublic && c.GetParameters().Any() && c.GetParameters().All(p => p.ParameterType.Equals(nsmapType)))) { try { this._formatter = (INodeFormatter)Activator.CreateInstance(t, new object[] { this._nsmap }); } catch { this._formatter = formatter; } } else { this._formatter = formatter; } } else { this._formatter = formatter; } if (!ReferenceEquals(currFormatter, this._formatter) || !currFormatter.GetType().Equals(this._formatter.GetType())) { DataTable tbl = (DataTable)this.dgvResults.DataSource; this.dgvResults.DataSource = null; this.dgvResults.Refresh(); this.dgvResults.DataSource = tbl; } } } }
/// <summary> /// Creates a new formatter control /// </summary> public FormatterControl() { InitializeComponent(); //Load Formatters Type targetType = typeof(INodeFormatter); foreach (Type t in Assembly.GetAssembly(targetType).GetTypes()) { if (t.Namespace == null) { continue; } if (!t.Namespace.Equals("VDS.RDF.Writing.Formatting")) { continue; } if (!t.GetInterfaces().Contains(targetType)) { continue; } try { INodeFormatter formatter = (INodeFormatter)Activator.CreateInstance(t); this._formatters.Add(new Formatter(formatter.GetType(), formatter.ToString())); } catch { //Ignore this Formatter } } this._formatters.Sort(); this.cboFormat.DataSource = this._formatters; this.cboFormat.SelectedItem = this._defaultFormatter ?? this._formatters.First(); this.cboFormat.SelectedIndexChanged += cboFormat_SelectedIndexChanged; this.RaiseFormatterChanged(); }