How to set column title for JTable? - netbeans

We can easily drag and drop JTable in netbeans but I can't see any options in the properties to change the column title in netbeans.

Try the documentation:
https://docs.oracle.com/javase/tutorial/uiswing/components/table.html
This is one of the suggested ways:
// The table in SimpleTableDemo.java declares the column names in a String array:
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
// Its data is initialized and stored in a two-dimensional Object array:
Object[][] data = {
{"Kathy", "Smith",
"Snowboarding", new Integer(5), new Boolean(false)},
{"John", "Doe",
"Rowing", new Integer(3), new Boolean(true)},
{"Sue", "Black",
"Knitting", new Integer(2), new Boolean(false)},
{"Jane", "White",
"Speed reading", new Integer(20), new Boolean(true)},
{"Joe", "Brown",
"Pool", new Integer(10), new Boolean(false)}
};
// Then the Table is constructed using these data and columnNames:
JTable table = new JTable(data, columnNames);

Related

Unexpected array elements skipping while populating collection in mongoose

There are two collections - Users and Images. Each user object has the list of images, that are accessible to this user - that goes as a field user.userOpenedToImages, with the references to the respective image objects id. During the population process I apply some options
const { userOpenedToImages } = await User.findOne({ _id: req.userId })
.select("userOpenedToImages")
.populate({
path: "userOpenedToImages",
select: "-imageHostingId -smallImageHostingId -imageInfo.openedTo -imageInfo.sharedByLink",
options: { skip: offset, limit: imagesPerPage },
});
Basically, I find the user I need, select one field of this user object, populate it. During the population I exclude fields I don't need (select:) - and implement pagination through options:. Pretty plain for now.
The problem is following:
This scheme is used in several places in the code - and it works great. Except for one place. The resulting array that I get in the userOpenedToImages variable has some of it elements shifted to the end. this is what it looks like :
the complete array of userOpenedToImages in database
userOpenedToImagesTotal : [
new ObjectId("62337a8ea5a6253e5e2094ac"),
new ObjectId("62337a92a5a6253e5e2094ae"),
new ObjectId("62337a95a5a6253e5e2094b0"),
new ObjectId("62337a9aa5a6253e5e2094b2"),
new ObjectId("62337a9ea5a6253e5e2094b4"),
new ObjectId("62337abda5a6253e5e2094bb"),
new ObjectId("62337ac1a5a6253e5e2094bd"),
new ObjectId("62337ac6a5a6253e5e2094bf"),
new ObjectId("62337acba5a6253e5e2094c1"),
new ObjectId("62337ad0a5a6253e5e2094c3"),
new ObjectId("62337b05a5a6253e5e2094ca"),
new ObjectId("62337b09a5a6253e5e2094cc"),
new ObjectId("62337b0da5a6253e5e2094ce"),
new ObjectId("62337b10a5a6253e5e2094d0"),
new ObjectId("62337b13a5a6253e5e2094d2"),
new ObjectId("623378eba5a6253e5e2093af"),
new ObjectId("623378efa5a6253e5e2093b1"),
new ObjectId("623378f2a5a6253e5e2093b3"),
new ObjectId("623378f5a5a6253e5e2093b5"),
new ObjectId("623378f8a5a6253e5e2093b7"),
new ObjectId("6233791fa5a6253e5e2093be"),
new ObjectId("62337923a5a6253e5e2093c0"),
new ObjectId("62337926a5a6253e5e2093c2"),
new ObjectId("6233792aa5a6253e5e2093c4"),
new ObjectId("6233792da5a6253e5e2093c6")
]
the array I get when passing the following options to populate() - options: { skip: 0, limit: 10},
userOpenedToImages : [
new ObjectId("623378eba5a6253e5e2093af"),
new ObjectId("623378efa5a6253e5e2093b1"),
new ObjectId("623378f2a5a6253e5e2093b3"),
new ObjectId("623378f5a5a6253e5e2093b5"),
new ObjectId("623378f8a5a6253e5e2093b7"),
new ObjectId("6233791fa5a6253e5e2093be"),
new ObjectId("62337923a5a6253e5e2093c0"),
new ObjectId("62337926a5a6253e5e2093c2"),
new ObjectId("6233792aa5a6253e5e2093c4"),
new ObjectId("6233792da5a6253e5e2093c6")
]
options: { skip: 10, limit: 10},
userOpenedToImages : [
new ObjectId("62337a8ea5a6253e5e2094ac"),
new ObjectId("62337a92a5a6253e5e2094ae"),
new ObjectId("62337a95a5a6253e5e2094b0"),
new ObjectId("62337a9aa5a6253e5e2094b2"),
new ObjectId("62337a9ea5a6253e5e2094b4"),
new ObjectId("62337abda5a6253e5e2094bb"),
new ObjectId("62337ac1a5a6253e5e2094bd"),
new ObjectId("62337ac6a5a6253e5e2094bf"),
new ObjectId("62337acba5a6253e5e2094c1"),
new ObjectId("62337ad0a5a6253e5e2094c3")
]
As you see - the resulting arrays have other order of elements than they should, as if there were divided on groups and those groups are switching places... What might be the problem here?
In several other places with the same request scheme everything works just the way it should.

how to customize return table snapshot by hibernate en verse query

i am try with hibernate enverse below example code.
List personsAtAddress = getAuditReader().createQuery()
.forRevisionsOfEntity(MyEntity.class, false, true)
getting the out put as jsen format as below
[ {"id"=1,
"name" ="ssss"
},{
"revid" =1,
"username" ="kkk"
},
MOD
]
but my expected output is
["my entity" {"id"=1,
"name" ="ssss"
},
"custom Revision Tale"{
"revid" =1,
"username" ="kkk"
},
"modflag"="MOD"
]
how to get this result by a audit query in hibernate enverse
You basically need to marshal the returned Object[] array from the Envers API to a Map using the keys your output expects to get the results.
final List<Map<String,Object> output = new ArrayList<>();
final List<Object[]> results = // this is the list of object arrays from Envers
for ( Object[] row : results ) {
final Map<String, Object> map = new HashMap<>();
map.put( "my entity", row[0] );
map.put( "custom Revision Tale", row[1] );
map.put( "modflag", row[2] );
output.add( map );
}

Populating Combobox in a Table Column

I have tied an ODataModel with a table. In the table one of the columns is dropdown list. The list has some 3 values. It's slightly confusing for me but how to go with such scenario? Do I have to tie another model consisting of the values I want in the dropdown and then have it's property bound to the response coming from the ODataModel which is tied to the table?
Is the following thing correct? but it may not be good if I have more values to be there in the dropdown and morever.... how to proceed if I want to bind this "key" mentioned below with "Status" in the ODataModel? Here I have tied the "value" property of combobox to the "StatusText" coming from ODataModel.
But I want to tie the "key" property of ListItem with "Status" from ODataModel(which is tied with the table) response
oTable.addColumn(
new sap.ui.commons.ComboBox({
items: [
new sap.ui.core.ListItem({text: "New",key:"1"}).bindProperty("text","StatusText").bindProperty("key","Status"),
new sap.ui.core.ListItem({text: "In Process",key:"2"}),
new sap.ui.core.ListItem({text: "Completed",key:"3"})
]
}).bindProperty("value","StatusText")
);
Any Help would be appreciated.
Thanks
This works in the table, but I think your Combobox still has some error with the bindings.
var oCombobox = new sap.ui.commons.ComboBox({
items: [
new sap.ui.core.ListItem({text: "New",key:"1"}).bindProperty("text","StatusText").bindProperty("key","Status"),
new sap.ui.core.ListItem({text: "In Process",key:"2"}),
new sap.ui.core.ListItem({text: "Completed",key:"3"})
]
}).bindProperty("value","StatusText");
oTable.addColumn(new sap.ui.table.Column({
template : oCombobox,
visible : true,
}));
Lets say you have a oData field called {Firstname}, defined in your result type (table) e.g. for this table, then you bind it in the table as:
oTable.addColumn(new sap.ui.table.Column({
template : new sap.ui.commons.TextView({
text : "{Firstname}",
textAlign : sap.ui.core.TextAlign.Center
}),
visible : true,
}));
As far as I understand, you want to get the possible values out of your oData Service, but I think this is not possible in case of an dropdown / combobox because you get a table from your backend, each line has a value in one field -> how would your bind 3 values in one single table field?
I realised dropdowns in an own service, calling the dropdown values from the backend separately:
getDropdown : function() {
// Create JSON data model
var oModel = new sap.ui.model.json.JSONModel();
oModel.loadData("/sap/opu/odata/sap/YOUR_SERVICE/YourEntitySet");
sap.ui.getCore().setModel(oModel);
// Create a DropdownBox
var oDropdown = new sap.ui.commons.DropdownBox("DropdownBox", {
text: "{Firstname}",
});
oDropdown.setModel(oModel);
var oItemTemplate1 = new sap.ui.core.ListItem({
text : "{Firstname}",
});
oDropdown.bindItems("/d/results", oItemTemplate1);
// "/d/results" may vary depending on your path
// return the box
return oDropdown;
},
you can use the returning result in your table.
e.g. in view:
var dropdown = oController.getDropdown();
dropdown.placeAt("content");

How to make the time stamp difference for inserting and updating record in mongo?

I need to create a time stamp in my mongodb collection. Am using C# in front end .My code is :
internal static void CreateStudent(string Id, string Name,string strUserId)
{
MongoServer server = MongoServer.Create(ConnectionString);
MongoDatabase mydb = server.GetDatabase("Database");
MongoCollection<BsonDocument> Student = mydb.GetCollection<BsonDocument>("Student");
BsonDocument colectionGenre = new BsonDocument {
{ "Code", Id }, //Id is Auto Generated in sql. Fetch from there using Output parameter and save it in one variable and pass that here
{ "Name", Name },
{ "Status","Y"},
{"stamps" , new BsonDocument {
{"Ins_date", DateTime.Now},
{"up_date",""},
{"createUsr", strUserId},
{"updUsr", ""},
{"Ins_Ip", GetIP()},
{"Upd_IP",""}}}
};
Student.Insert(colectionGenre);
}
internal static void UpdateStudent(string Id, string Name,string strUserId)
{
MongoServer server = MongoServer.Create(ConnectionString);
MongoDatabase mydb = server.GetDatabase("Database");
MongoCollection<BsonDocument>Student = mydb.GetCollection<BsonDocument>("Student"); ;
// Query for fetch the ID which is edited by the User...(user can only able to edit the NAME field alone)
var query = new QueryDocument {
{ "Code", Id }};
// After Fetch the correspondent ID it updates the name with the Edited one
var update = new UpdateDocument {
{ "$set", new BsonDocument("Name", Name) }
};
// Updated Query.(Id is same as previous. Name is updated with new one)
{"stamps" , new BsonDocument {
{"up_date",DateTime.Now},
{"updUsr", strUserId},
{"Upd_IP",GetIp()}}}
}}
};
Student.Update(query,update,UpdateFlags.Upsert, SafeMode.True);
}
It works fine for INSERT method with time(Stamp) once the record is created. But the problem is with update method. When user update something the insert time also changed with the updated time..
After User Updates the Name, i want my will collection looks like this
{
"_id" : ObjectId("5178aea4e6d8e401e8e51dc0"),
"Code": 12,
"Name": Sname,
"Stamps:"{
"Ins_date":03:34:00,
"up_date": 04:35:12
}
}
But my problem is both the time will same after update. That is because it takes the current date and time function..How can i achieve the above output.It needs any driver.Suggest something for me...
You're passing in a value for the Ins_date field when you're updating the document. Just remove that from the update document and it won't change it.
var update = new UpdateDocument {
{"$set", new BsonDocument {
{"State_strName", name},
{"stamps" , new BsonDocument {
{"up_date",DateTime.Now},
{"createUsr", ""},
{"updUsr", ""},
{"Ins_Ip", GetIP()},
{"Upd_IP",GetIP()}}}
};
tblmytbl.Update(query, update);
How you are updating the value in the existing document by using unique id or other unique value.Check whether the unique id or value is already exist in your database documents.If it is exist means change the update time only don't do anything..
While updating the data in mongoDB,you are passing the same values for Ins_date and up_date i.e. DateTime.Now(current system date and time).So the same values are updating in your monoDB document.
For this you can do one thing :-
Before updating your mongoDB document you take Ins_date values from your database by using sql query in C#.net and then use this value for Ins_date and for up_date use DateTime.Now then your both values will be different.
var update = new UpdateDocument {
{"$set", new BsonDocument {
{"State_strName", name},
{"stamps" , new BsonDocument {
{"Ins_date", **Ins_date values_from your database**} ,
{"up_date",DateTime.Now},
{"createUsr", ""},
{"updUsr", ""},
{"Ins_Ip", GetIP()},
{"Upd_IP",GetIP()}}}
};
tblmytbl.Update(query, update);
Sounds like what you need is the new $setOnInsert operator which was added in 2.4 for exactly this use case.
When the update with upsert flag results in an insert, you want to $set insert_date to Date.now but when it's a regular update, you don't want to set it at all. So now with your update you should use $set for regular fields you want to set whether it's an update or an insert, but use $setOnInsert for fields that should only be set during insert.
Finally I got answer...In INSERT method Simply pass the below things
{"Insert-stamps" , new BsonDocument {
{"Ins_date", DateTime.Now},
{"createUsr", strUserId},
{"Ins_Ip", GetIP()}}},
{"Update-stamps" , new BsonDocument {
{"up_date",""},
{"updUsr", ""},
{"Upd_IP",""}}}
And In UPDATE method
{"Update-stamps" , new BsonDocument {
{"up_date", DateTime.Now},
{"updUsr", StrUserId},
{"Upd_IP",GetIP()}}}
It works Fine for my standard....

inserting a new document in the arrray of documents

I want to add a new document to the following document having an outer key "User"
{
name:himani,
User:[
{
_id:e25ffgf627627,
Name:User1
},
{
_id:fri2i2jhjh9098,
Name:User2
}
]
};
Below is my code in which I am trying to add a new document to already existing document.
My code is:
var server = MongoServer.Create("mongodb://username:password#localhost:27017/?safe=true");
SafeMode mode = new SafeMode(true);
SafeModeResult result = new SafeModeResult();
var db = server.GetDatabase("himani");
var coll = db.GetCollection("test");
BsonDocument document = new BsonDocument();
document.Add("name", "himani");
result = coll.Insert(document, mode);
BsonDocument nested = new BsonDocument();
nested.Add("1", "heena").Add("2", "divya");
BsonArray a = new BsonArray();
a.Add(2);
a.Add(5);
nested.Add("values", a);
document["3"] = new BsonArray().Add(BsonValue.Create(nested));
coll.Save(document);
var query = Query.And(
Query.EQ("name", "himani"),
Query.EQ("3.1", "heena")
);
var match = coll.FindOne(query);
var update = Update.AddToSet("3", new BsonDocument {{ "count", "2" }});
coll.Update(query, update);
I want to add a new document to the User array. I am doing this by above code but its not working.Please tell me the right way of doing it.
I don't understand your document structure at all... and the only "user" array I could find in here was a field called "3". Your code does in fact work and appends a document into the "3" array. The below is the result after running your code. Perhaps you could be more clear as to what you want your document to look like after you have "appended" a user.
{
"_id":ObjectId("4fa7d965ce48f3216c52c6c7"),
"name":"himani",
"3":[
{
"1":"heena",
"2":"divya",
"values":[ 2, 5 ]
},
{
"count":"2"
}
]
}